https://github.com/ergebnis/php-cs-fixer-config
📓 Provides a composer package with a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
https://github.com/ergebnis/php-cs-fixer-config
configuration php-cs-fixer
Last synced: 2 months ago
JSON representation
📓 Provides a composer package with a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
- Host: GitHub
- URL: https://github.com/ergebnis/php-cs-fixer-config
- Owner: ergebnis
- License: mit
- Created: 2019-11-25T18:38:21.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-05-12T19:45:52.000Z (about 1 year ago)
- Last Synced: 2025-05-12T20:48:10.631Z (about 1 year ago)
- Topics: configuration, php-cs-fixer
- Language: PHP
- Size: 6.2 MB
- Stars: 71
- Watchers: 2
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# php-cs-fixer-config
[](https://github.com/ergebnis/php-cs-fixer-config/actions/workflows/integrate.yaml)
[](https://github.com/ergebnis/php-cs-fixer-config/actions/workflows/merge.yaml)
[](https://github.com/ergebnis/php-cs-fixer-config/actions/workflows/release.yaml)
[](https://github.com/ergebnis/php-cs-fixer-config/actions/workflows/renew.yaml)
[](https://codecov.io/gh/ergebnis/php-cs-fixer-config)
[](https://packagist.org/packages/ergebnis/php-cs-fixer-config)
[](https://packagist.org/packages/ergebnis/php-cs-fixer-config)
[](https://packagist.org/packages/ergebnis/php-cs-fixer-config)
This project provides a [`composer`](https://getcomposer.org) package with a configuration factory and rule set factories for [`friendsofphp/php-cs-fixer`](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer).
## Installation
Run
```sh
composer require --dev ergebnis/php-cs-fixer-config
```
## Usage
### Configuration
Pick one of the rule sets:
- [`Ergebnis\PhpCsFixer\RuleSet\Php53`](src/RuleSet/Php53.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php54`](src/RuleSet/Php54.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php55`](src/RuleSet/Php55.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php56`](src/RuleSet/Php56.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php70`](src/RuleSet/Php70.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php71`](src/RuleSet/Php71.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php72`](src/RuleSet/Php72.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php73`](src/RuleSet/Php73.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php74`](src/RuleSet/Php74.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php80`](src/RuleSet/Php80.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php81`](src/RuleSet/Php81.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php82`](src/RuleSet/Php82.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php83`](src/RuleSet/Php83.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php84`](src/RuleSet/Php84.php)
- [`Ergebnis\PhpCsFixer\RuleSet\Php85`](src/RuleSet/Php85.php)
Create a configuration file `.php-cs-fixer.php` in the root of your project:
```php
in(__DIR__);
$config = Config\Factory::fromRuleSet($ruleSet);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
$config->setFinder($finder);
return $config;
```
### Git
All configuration examples use the caching feature, and if you want to use it as well, you should add the cache directory to `.gitignore`:
```diff
+ /.build/
/vendor/
```
### Configuring a rule set with header
:bulb: Optionally specify a header:
```diff
withHeader($header);
$finder = Finder::create()->in(__DIR__);
$config = Config\Factory::fromRuleSet($ruleSet);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
$config->setFinder($finder);
return $config;
```
This will enable and configure the [`HeaderCommentFixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.1.1/src/Fixer/Comment/HeaderCommentFixer.php), so that file headers will be added to PHP files, for example:
```diff
withRules(Config\Rules::fromArray([
+ 'mb_str_functions' => false,
+ 'strict_comparison' => false,
+]));
$finder = Finder::create()->in(__DIR__);
$config = Config\Factory::fromRuleSet($ruleSet);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
$config->setFinder($finder);
return $config;
```
### Configuring a rule set that registers and configures rules for custom fixers
:bulb: Optionally register and configure rules for custom fixers:
```diff
withCustomFixers(Config\Fixers::fromFixers(
+ new Fixer\BarBazFixer(),
+ new Fixer\QuzFixer(),
+ ))
+ ->withRules(Config\Rules::fromArray([
+ 'FooBar/bar_baz' => true,
+ 'FooBar/quz' => [
+ 'qux => false,
+ ],
+ ]))
+]);
$finder = Finder::create()->in(__DIR__);
$config = Config\Factory::fromRuleSet($ruleSet);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
$config->setFinder($finder);
return $config;
```
### Makefile
If you like [`Makefile`](https://www.gnu.org/software/make/manual/make.html#Introduction)s, create a `Makefile` with a `coding-standards` target:
```diff
+.PHONY: coding-standards
+coding-standards: vendor
+ mkdir -p .build/php-cs-fixer
+ vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --show-progress=dots --verbose
vendor: composer.json composer.lock
composer validate
composer install
```
Run
```sh
make coding-standards
```
to automatically fix coding standard violations.
### Composer script
If you like [`composer` scripts](https://getcomposer.org/doc/articles/scripts.md), add a `coding-standards` script to `composer.json`:
```diff
{
"name": "foo/bar",
"require": {
"php": "^8.1",
},
"require-dev": {
"ergebnis/php-cs-fixer-config": "^6.21.0"
+ },
+ "scripts": {
+ "coding-standards": [
+ "mkdir -p .build/php-cs-fixer",
+ "php-cs-fixer fix --diff --show-progress=dots --verbose"
+ ]
}
}
```
Run
```sh
composer coding-standards
```
to automatically fix coding standard violations.
### GitHub Actions
If you like [GitHub Actions](https://github.com/features/actions), add a `coding-standards` job to your workflow:
```diff
on:
pull_request: null
push:
branches:
- main
name: "Integrate"
jobs:
+ coding-standards:
+ name: "Coding Standards"
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ php-version:
+ - "8.1"
+
+ steps:
+ - name: "Checkout"
+ uses: "actions/checkout@v2"
+
+ - name: "Set up PHP"
+ uses: "shivammathur/setup-php@v2"
+ with:
+ coverage: "none"
+ php-version: "${{ matrix.php-version }}"
+
+ - name: "Cache dependencies installed with composer"
+ uses: "actions/cache@v2"
+ with:
+ path: "~/.composer/cache"
+ key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
+ restore-keys: "php-${{ matrix.php-version }}-composer-"
+
+ - name: "Install locked dependencies with composer"
+ run: "composer install --ansi --no-interaction --no-progress --no-suggest"
+
+ - name: "Create cache directory for friendsofphp/php-cs-fixer"
+ run: mkdir -p .build/php-cs-fixer
+
+ - name: "Cache cache directory for friendsofphp/php-cs-fixer"
+ uses: "actions/cache@v2"
+ with:
+ path: "~/.build/php-cs-fixer"
+ key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}"
+ restore-keys: |
+ php-${{ matrix.php-version }}-php-cs-fixer-main
+ php-${{ matrix.php-version }}-php-cs-fixer-
+
+ - name: "Run friendsofphp/php-cs-fixer"
+ run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --show-progress=dots --verbose"
```
## Changelog
The maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).
## Contributing
The maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).
## Code of Conduct
The maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).
## General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by [sponsoring @ergebnis](https://github.com/sponsors/ergebnis).
## PHP Version Support Policy
This project currently supports the following PHP versions:
- [PHP 7.4](https://www.php.net/releases/#7.4.0) (has reached its end of life on November 28, 2022)
- [PHP 8.0](https://www.php.net/releases/#8.0.0) (has reached its end of life on November 26, 2023)
- [PHP 8.1](https://www.php.net/releases/#8.1.0) (has reached its end of life on December 31, 2025)
- [PHP 8.2](https://www.php.net/releases/#8.2.0)
- [PHP 8.3](https://www.php.net/releases/#8.3.0)
- [PHP 8.4](https://www.php.net/releases/#8.4.0)
- [PHP 8.5](https://www.php.net/releases/#8.5.0)
The maintainers of this project add support for a PHP version following its initial release and _may_ drop support for a PHP version when it has reached its [end of life](https://www.php.net/supported-versions.php).
## Security Policy
This project has a [security policy](.github/SECURITY.md).
## License
This project uses the [MIT license](LICENSE.md).
## Credits
This project is inspired by and also replaces [`localheinz/php-cs-fixer-config`](https://github.com/localheinz/php-cs-fixer-config).
This project requires and enables custom fixers from the following packages:
- [`erickskrauch/php-cs-fixer-custom-fixers`](https://github.com/erickskrauch/php-cs-fixer-custom-fixers)
- [`kubawerlos/php-cs-fixer-custom-fixers`](https://github.com/kubawerlos/php-cs-fixer-custom-fixers)
## Social
Follow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.