friendsofphp/php-cs-fixer
PHP CS Fixer automatically fixes PHP code to match coding standards. Use built-in rule sets (PER-CS, Symfony, PhpCsFixer) or custom config to unify style, modernize PHP/PHPUnit code, and apply safe or risky migrations. Supports PHP 7.4–8.5.
Code Quality & Maintainability:
Developer Experience (DX):
check mode) or auto-fix issues (via fix mode), reducing friction in onboarding and code reviews.Technical Debt Reduction:
@autoPHPMigration rules) to adopt newer PHP features (e.g., typed properties, arrow functions) without breaking changes.@autoPHPUnitMigration:risky) to adopt modern testing practices (e.g., attributes over annotations).Build vs. Buy Decision:
Roadmap Alignment:
pre-commit or pre-push) to fail fast.php-cs-fixer in the project’s contributing.md.--allow-unsupported-php-version=yes).php-cbf or psalm) over automated fixes.*"PHP CS Fixer is a low-effort, high-impact tool that automates code formatting to save developer time and reduce technical debt. By standardizing our PHP codebase, we’ll:
- Accelerate onboarding (new hires spend less time fixing style issues).
- Improve code quality (consistent formatting reduces bugs from misread code).
- Modernize legacy systems (incrementally adopt PHP 8+ features without breaking changes).
- Cut CI/CD costs (fewer manual reviews, faster merges).
It’s a one-time setup (15–30 minutes) with immediate ROI—similar to Prettier for JavaScript. Used by Symfony, Drupal, and Laravel, it’s a de facto standard for PHP teams. Let’s pilot it in our largest repo to measure impact."*
*"PHP CS Fixer automates the boring stuff—fixing indentation, braces, imports, and modernizing PHP syntax—so we don’t waste time in PRs arguing about style. Key benefits:
- Integrates with your workflow:
- Run
./vendor/bin/php-cs-fixer fixto auto-fix issues.- Add to CI to block non-compliant code (
php-cs-fixer check).- Works with PhpStorm/VS Code for real-time fixes.
- Supports our stack:
- Pre-configured for Symfony/Laravel or PSR-12.
- Can migrate legacy PHP to modern features (e.g., PHPUnit attributes).
- Extensible: Need a custom rule? It’s well-documented.
How we’ll roll it out:
- Run
composer require --dev friendsofphp/php-cs-fixerin the monorepo.- Configure
.php-cs-fixer.dist.phpto match our style (or use@Symfony).- Add to CI (e.g., GitHub Actions) and Git hooks.
- Train team on
fixvs.checkmodes.Time investment: ~2 hours to set up; payback: Hours saved weekly in code reviews."*
*"This is a must-have for any PHP project serious about maintainability. It:
- Reduces contributor friction by enforcing consistent style upfront.
- Future-proofs your codebase with migration rules for PHP 8+.
- Aligns with PSR standards, making it easier to adopt by other teams.
Example pitch for contributors:
‘Before submitting a PR, run
php-cs-fixer fixto ensure your changes match the project’s style. This saves reviewers time and keeps the codebase clean.’For maintainers:
- Add to
contributing.mdas a pre-merge requirement.- Use
@Symfonyor@PSR12rule sets for broad compatibility.- Leverage
php-cs-fixer checkin CI to fail fast on style violations."*
How can I help you explore Laravel packages today?