friendsofphp/php-cs-fixer
PHP CS Fixer automatically fixes PHP code to match coding standards. Use built-in rule sets like @PER-CS, @Symfony, or @PhpCsFixer, or define your own config. Helps modernize code for newer PHP and PHPUnit. Supports PHP 7.4–8.5.
Code Quality & Maintainability:
Developer Experience (DX) & Velocity:
Technical Debt Reduction:
@autoPHPMigration rules (e.g., array_map → array_map(fn(...))).@autoPHPUnitMigration:risky for PHPUnit 13 assertions).@risky rule sets (e.g., @Symfony:risky) for experimental but high-value changes.Build vs. Buy:
php-cbf)..php-cs-fixer.dist.php.Use Cases:
->method() → method()).@FullyQualifiedStrictTypesFixer) to catch type-related bugs early.@PER-CS for PHP-FIG compliance).->method() vs. method()).phpmd + php-cbf).foreach → array_map).*"PHP-CS-Fixer automates 90% of our code style enforcement, saving 10–20 dev-hours/week in manual reviews. By standardizing our codebase, we:
- Reduce onboarding time by 30% (new hires spend less time fixing style issues).
- Cut CI costs by 40% with parallel execution (faster feedback loops).
- Future-proof our tech stack with built-in PHP 8.x migration support.
- Align with industry standards (Symfony/PHP-FIG), improving partner/acquirer confidence.
Investment: ~$0 (MIT-licensed, open-source). ROI: 5–10x in developer productivity. Let’s pilot it in the next sprint."*
*"PHP-CS-Fixer is the Swiss Army knife for PHP code quality:
- Pre-commit hooks: Auto-fix files before
git push(viapre-commitorhusky).- CI integration: Block non-compliant PRs early (e.g., GitHub Actions:
- name: PHP-CS-Fixer run: ./vendor/bin/php-cs-fixer fix --dry-run --diff- Rule sets: Leverage
@Symfony,@PER-CS, or@autoPHPMigrationfor zero-config modernizations.- Performance: Parallel mode (default since v3.94.0) halves CI runtime for large repos.
- Extensible: Custom rules or
.php-cs-fixer.dist.phpto enforce team-specific standards.Key metrics to track:
- % of PRs passing CS checks on first try (target: >95%).
- Time saved in code reviews (pre/post-adoption).
- Reduction in ‘style nitpicks’ in PR feedback.
Next steps:
- Run
composer require --dev friendsofphp/php-cs-fixerin a sandbox repo.- Test with
./vendor/bin/php-cs-fixer fix --dry-runto preview changes.- Integrate into CI and pre-commit hooks."*
*"Tired of:
- ‘Indentation is wrong’ comments in PRs?
- Manually fixing
->method()vs.method()inconsistencies?- Wasting time on style debates instead of shipping features?
PHP-CS-Fixer does this for you:
- One command:
./vendor/bin/php-cs-fixer fixauto-corrects 100+ style rules.- IDE plugins: Fix issues as you type (PhpStorm/VS Code support).
- No more ‘it works on my machine’: Enforces consistent formatting across the team.
- Modernize safely: Rules like
@autoPHPMigrationupdate legacy code to PHP 8.x without breaking changes.Try it:
composer require --dev friendsofphp/php-cs-fixer ./vendor/bin/php-cs-fixer init # Auto-generate config ./vendor/bin/php-cs-fixer fix # Boom. Done. ```"
How can I help you explore Laravel packages today?