ebrana / php-cs-fixer-config
The eBRANA coding standard for PHP-CS-Fixer: one rule set and one fixer version for all eBRANA PHP projects.
Requires
- php: >=8.4
- friendsofphp/php-cs-fixer: ~3.95.32
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The eBRANA coding standard for PHP-CS-Fixer: one rule set and one fixer version for all eBRANA PHP projects.
The rules are the Symfony standard (@Symfony, @Symfony:risky) with a few additions; they
are listed with their reasons in src/Config.php.
Installation
composer require --dev ebrana/php-cs-fixer-config
The package requires friendsofphp/php-cs-fixer itself. Do not require the fixer in the
project as well: rules and fixer version are released together, so the same code is formatted
the same way in every project.
Usage
.php-cs-fixer.dist.php of the project declares only what to check:
<?php declare(strict_types=1); use Ebrana\CsFixerConfig\Config; use PhpCsFixer\Finder; $finder = (new Finder()) ->in([__DIR__.'/src', __DIR__.'/tests']); return Config::create($finder)->setCacheFile(__DIR__.'/.php-cs-fixer.cache');
vendor/bin/php-cs-fixer fix --dry-run --diff # check vendor/bin/php-cs-fixer fix # fix
Config::create() returns a regular PhpCsFixer\Config. A project that needs an extra rule
adds it on top of the shared set:
return Config::create($finder) ->setRules(Config::rules() + ['yoda_style' => false]);
Keep such additions rare: a rule that makes sense in one project usually belongs here.
Changing the standard
- Change
src/Config.phpin a pull request and add a line toCHANGELOG.md. - Tag a release. A changed or added rule, or a new fixer minor version, reformats code, so it is a new minor version; a fix that changes no output is a patch.
- Each project takes the release in its own dependency-update commit and commits the reformatted code together with it.