fabpot/php-cs-fixer
PHP CS Fixer is a command-line tool for automatically fixing PHP coding standards issues. It formats and modernizes code using configurable rulesets, supports custom rule configurations, and helps keep projects consistent and clean across teams and CI.
vendor:publish templates).use statement ordering)..php-cs-fixer.dist.php for project-specific rules (e.g., overriding Laravel’s array_syntax to consistent).config/app.php via environment variables (e.g., CS_FIXER_RULES).no_unused_imports) may clash with Laravel’s autoloading or facade usage.
php-cs-fixer fix --dry-run before enforcing.--cache-file and parallel processing (--parallel).ordered_imports) may break dynamic use statements in Laravel’s AppServiceProvider.exclude: [app/Providers/AppServiceProvider.php]).git hooks (Husky) vs. GitHub Actions.laravel-pint)?pint is Laravel’s official formatter; PHP-CS-Fixer is more granular.composer require --dev friendsofphp/php-cs-fixer.php artisan cs:fix) to wrap PHP-CS-Fixer.php-cs-fixer in phpunit.xml as a test listener to fail builds on violations.php-cs-fixer fix --rules=@PSR12 --dry-run on a non-critical branch.git diff; adjust rules as needed.php-cs-fixer with pint if formatting-only needs are sufficient.pint for files, php-cs-fixer for logic).--path-mode-intersection), and custom packages.blade_case_enum).- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --rules=@PSR12 --diff
php-cs-fixer as a pre-job to fail fast.PHP Intelephense + PHP-CS-Fixer.composer-hooks to run fixer automatically..php-cs-fixer.dist.php with Laravel-aware rules (e.g., preserve use Illuminate\Support\Facades\Log;).return PhpCsFixerConfig::create()
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
])
->setPathModeIntersection(true);
composer.json under require-dev.php80_migration).composer.json or update annually..php-cs-fixer.dist.php.php81_migration rules.AppServiceProvider excluded?").no_unused_imports errors").--verbose and --diff flags to diagnose issues.--cache-file and --parallel to reduce CI runtime.blade_case_enum only on .blade.php files).app/Http/Controllers/) before expanding.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Rule Overkill | Breaks legacy code unexpectedly. | Use --dry-run and whitelist directories. |
| CI Timeouts | Slow runs block deployments. | Cache results, parallelize, or use smaller batches. |
| Rule Drift | Outdated rules cause merge conflicts. | Pin versions, review rules annually. |
| IDE Plugin Issues | False positives in VSCode/PHPStorm. | Configure IDE to ignore .php-cs-fixer.cache. |
| Blade Template Conflicts | Rules misapply to Blade syntax. | Exclude Blade files or use path-mode-intersection. |
How can I help you explore Laravel packages today?