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.
@autoPHPMigration and @autoPHPUnitMigration help gradually modernize legacy Laravel codebases (e.g., PHP 7.4 → 8.1, PHPUnit 8 → 10), reducing manual refactoring effort..php-cs-fixer.dist.php, allowing TPMs to tailor standards (e.g., enforcing Laravel-specific conventions like use App\Models\* imports).--dev dependency).routes/web.php, AppServiceProvider.php).phpunit or Laravel’s artisan test for pre-test style checks.@autoPHPMigration:risky) may break functionality if misconfigured. Requires gradual adoption and manual review for critical fixes.php-cs-fixer/shim if conflicts arise.php-cs-fixer fix locally, style changes may conflict in PRs. Mitigate with:
husky + simple-php-unit).@Symfony (Laravel’s default), @PSR12, or a custom set? How will this align with Laravel’s evolving conventions?@autoPHPMigration:risky) are acceptable for automated fixes vs. requiring manual review?php-cs-fixer run in pre-commit, pre-merge, or post-merge? How will we handle blocking vs. warning failures?.php-cs-fixer.dist.php exclusions temporarily?php artisan pint) and integrates with Laravel’s task scheduler (schedule:run).@foreach spacing) alongside PHP files.php artisan cs-fix) to standardize usage.husky + simple-php-unit to run php-cs-fixer on pre-commit.php-cs-fixer before static analysis to reduce noise from style issues.app/Http/Controllers/) using --dry-run to assess impact.@Symfony or @PSR12 as a baseline.@autoPHPMigration) with manual review..php-cs-fixer.dist.php to exclude problematic files temporarily.return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'no_unused_imports' => true,
])
->setPathCache(__DIR__.'/var/php-cs-fixer.cache')
->setFinder(
PhpCsFixer\Finder::create()
->exclude(['legacy/', 'vendor/'])
);
--allow-unsupported-php-version=yes (not recommended for production).symfony/console), use php-cs-fixer/shim or Composer’s conflict-resolution.composer require --dev friendsofphp/php-cs-fixer
./vendor/bin/php-cs-fixer init
.php-cs-fixer.dist.php for Laravel-specific rules (e.g., import ordering).return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
]);
.github/workflows/ci.yml:
- name: PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --diff --dry-run
package.json (if using npm scripts):
"scripts": {
"lint:fix": "php ./vendor/bin/php-cs-fixer fix"
}
composer require laravel/pint --dev
php artisan pint
.php-cs-fixer.dist.php locally, leading to inconsistencies.How can I help you explore Laravel packages today?