PHP-CS-Fixer Fails CI - Style Violations and Config/Version Drift
php-cs-fixer enforces a coding-style ruleset. In CI it usually runs with --dry-run, exiting non-zero when any file would be changed. A style violation - or a different fixer/PHP version than developers use - fails the check.
What this error means
A php-cs-fixer fix --dry-run --diff step fails listing files that need formatting, even though developers ran the fixer locally. Often the CI fixer version differs from the local one, so the two disagree on style.
$ php-cs-fixer fix --dry-run --diff
1) src/Order.php
---------- begin diff ----------
- public function total( ) {
+ public function total()
---------- end diff ----------
Found 1 file that can be fixed. (exit code 8)Common causes
Files violate the configured ruleset
Code was committed without running the fixer, so it does not match .php-cs-fixer.dist.php, and the dry-run reports the diff.
Fixer or PHP version drift
CI runs a different php-cs-fixer (or PHP) version than developers. Rulesets evolve between releases, so the same code is judged differently.
How to fix it
Apply the fixes locally and commit
Run the fixer for real, then commit the formatting changes.
vendor/bin/php-cs-fixer fix
git add -A && git commit -m "Apply php-cs-fixer"Pin the fixer version
Lock php-cs-fixer so CI and local enforce identical rules.
composer require --dev friendsofphp/php-cs-fixer:^3.58
# run via the locked binary everywhere
vendor/bin/php-cs-fixer fix --dry-run --diffRun the same command CI runs
- Use the project config:
--config=.php-cs-fixer.dist.php. - Match CI’s PHP version when running locally.
- Add a pre-commit hook so violations never reach CI.
How to prevent it
- Pin php-cs-fixer (and the PHP version) so CI and local agree.
- Run the fixer via a pre-commit hook before pushing.
- Commit
.php-cs-fixer.dist.phpand use it in every invocation.