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.
@autoPHPMigration and @Symfony:risky help gradually modernize legacy Laravel codebases (e.g., PHP 7.4 → 8.1+ syntax updates)..php-cs-fixer.dist.php), allowing TPMs to tailor standards to team preferences (e.g., stricter Symfony rules for API layers, relaxed rules for legacy modules).--dev dependency), avoiding runtime bloat.post-css hooks) or Vite for frontend-backend consistency.--parallel) speeds up CI runs for monorepos.| Risk Area | Mitigation Strategy |
|---|---|
| Breaking Changes | Use --dry-run first; test with @Symfony or @PSR12 rule sets incrementally. |
| Rule Conflicts | Start with @auto or @auto:risky, then refine via .php-cs-fixer.dist.php. |
| Legacy Code | Leverage @autoPHPMigration for safe syntax updates (e.g., foreach → arrow functions). |
| CI Flakiness | Cache Composer dependencies; run in a separate job from tests. |
| Custom Rules | Extend via PHP-CS-Fixer’s custom rule API if built-in rules are insufficient. |
@Symfony (strict) or @PSR12 (minimal) as a baseline? How will we handle exceptions (e.g., legacy controllers)?husky + php-cs-fixer) or rely solely on CI?--parallel?@autoPHPMigration to enable PHP 8.2+ features (e.g., match expressions, readonly properties)?php artisan cs:fix) to wrap php-cs-fixer.php-cs-fixer fix --diff for visibility.valet link hooks for local consistency.composer require --dev friendsofphp/php-cs-fixer)..editorconfig to align with PHP-CS-Fixer rules (e.g., indent_size, end_of_line)../vendor/bin/php-cs-fixer fix --dry-run --diff to preview changes.@Symfony vs. @PSR12).@auto.@Symfony:risky) in separate PRs.- name: PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --diff --allow-risky=yes
husky or pre-commit:
./vendor/bin/php-cs-fixer fix --path-mode=intersection
| Component | Compatibility Notes |
|---|---|
| PHP Versions | Supports 7.4–8.5; use --allow-unsupported-php-version for bleeding-edge. |
| Laravel Versions | Works with Laravel 5.8+; test with Laravel Pint (alternative) for LTS. |
| Third-Party Packages | Exclude vendor/ via .php-cs-fixer.dist.php to avoid modifying dependencies. |
| Custom Code | Use exclude in config to skip legacy modules (e.g., app/OldLegacyModule). |
./vendor/bin/php-cs-fixer init..php-cs-fixer.dist.php to version control.@Symfony or @PSR12; refine via custom rules.CONTRIBUTING.md how to run fixes locally.php-cs-fixer fix --rules=@Symfony)..php-cs-fixer.dist.php in all branches; use php-cs-fixer update to sync.composer.json (e.g., ^3.95) and test upgrades in a staging environment.foreach to arrow functions?").exclude.--parallel or cache results.--verbose and --dry-run to diagnose issues.--parallel=8 and exclude vendor//storage//bootstrap/.git diff --name-only HEAD~1 | xargs ./vendor/bin/php-cs-fixer fix
--path-mode=intersection for pre-commit hooks.How can I help you explore Laravel packages today?