friendsofphp/php-cs-fixer
PHP CS Fixer automatically detects and fixes coding standards issues in your PHP code. Choose from built-in rule sets like @PER-CS, @Symfony, or @PhpCsFixer, or define your own style, and modernise your codebase with ease.
Architecture fit
require-dev and disappears from production images built with composer install --no-dev..env, or Laravel kernel — safe in a bare CI container.Integration feasibility
composer require --dev friendsofphp/php-cs-fixer; when Laravel's pinned Symfony components collide, the php-cs-fixer/shim variant resolves the conflict. Both paths are documented..php-cs-fixer.php file returning a Config with a Finder; excludes for vendor/, storage/, bootstrap/cache/, node_modules/, and IDE-helper generated files are the usual baseline.init, fix, check, --dry-run, --diff, --using-cache, --parallel. Editor integration exists natively for PhpStorm and via community plugins for VS Code, Vim, Sublime, NetBeans.Technical risk
@auto:risky, @autoPHPMigration:risky, and @autoPHPUnitMigration:risky can alter semantics, not just whitespace. They must be opt-in, reviewed per-PR, and never introduced in the same change as the initial style baseline.SingleClassElementPerStatementFixer and OrderedClassElementsFixer fixes in the v3.82.x line, VisibilityRequiredFixer promoted-property handling in v3.84.0). An unpinned ^3 with automated dependency bumps will eventually produce surprise diffs and red builds.--allow-unsupported-php-version=yes and is explicitly unsupported — a risk if the platform team upgrades PHP ahead of the fixer.git blame and conflicts with every open branch.Key questions
.php-cs-fixer.php and the upgrade cadence — platform, or the app team?.php-cs-fixer.cache?Finder scopes?Stack fit
@PER-CS for PHP-FIG alignment, @PhpCsFixer for the opinionated baseline, @Symfony as the closest off-the-shelf approximation of Laravel's house style. Anything Laravel-specific beyond that is a small custom config, not custom fixers.Migration path
php-cs-fixer init, select a base rule set.fix --dry-run --diff on a scratch branch and quantify the churn. This is the go/no-go number..git-blame-ignore-revs.check to a required status check; add .php-cs-fixer.cache to .gitignore and to the CI cache..idea project config.Compatibility
^3.95) rather than floating ^3, and bump deliberately. Note that recent releases explicitly add support for phpunit/phpunit:^13.2 and sebastian/diff:^9 — the package tracks the ecosystem closely, which is a positive but also a source of churn.Sequencing
| Phase | Scope | Exit criterion |
|---|---|---|
| Discovery | Pint vs. direct, rule set choice, diff size estimate | Decision memo + diff size |
| Baseline | Single formatting commit, blame ignore | Clean check on main |
| Gate | CI required check, cache wired | PRs blocked on style |
| Local DX | Hooks, editor config | New code never reaches CI dirty |
| Ratchet | Incremental rule additions | Quarterly review cadence established |
Maintenance
fix: entries — those are the ones that change output on already-clean code..php-cs-fixer.cache must be gitignored locally and keyed properly in CI, or stale caches produce false passes.Support
Scaling
--parallel and the result cache keep runs tractable; on a large Laravel monorepo expect low minutes, not seconds, for a cold full run.Finder, or exclusion lists grow unmanageable.Failure modes
composer update — mitigation: shim variant, or isolate the fixer in a separate CI image.main red without any code change — mitigation: pinned minor, scheduled bumps, and a rule-change PR template..git-blame-ignore-revs plus a merge-window announcement.Ramp-up
How can I help you explore Laravel packages today?