- How do I install PHP CS Fixer in a Laravel project?
- Install it as a Composer dev dependency with composer require --dev friendsofphp/php-cs-fixer, or use php-cs-fixer/shim when dependency conflicts occur. The fabpot/php-cs-fixer identifier is the legacy Composer name for the same project. Keep it in require-dev so production installs can exclude it with composer install --no-dev. Then run vendor/bin/php-cs-fixer fix or check from your Laravel project root.
- Does PHP CS Fixer work with Laravel Pint?
- Yes, Laravel Pint is built on PHP CS Fixer, so they can coexist technically, but you should avoid two competing formatter configurations. Prefer Pint as the developer interface if it already exists and add PHP CS Fixer only for rules Pint does not expose. Document one source of truth and verify presets do not conflict.
- Which PHP and Laravel versions does PHP CS Fixer support?
- PHP CS Fixer is framework-agnostic and does not depend on a Laravel version, so it fits Laravel projects that run supported PHP versions. The README lists PHP 7.4 through PHP 8.5, though the newest PHP release may lag and require --allow-unsupported-php-version=yes at your own risk. Verify your Laravel project's PHP version and CI images before pinning a release.
- How do I configure PHP CS Fixer for Laravel coding standards?
- Create a project-level .php-cs-fixer.dist.php configuration and start from a built-in rule set such as @PER-CS, @Symfony, or @PhpCsFixer. Add only the team-specific rules and exceptions you need, and keep the config in version control. If Laravel Pint is already present, treat Pint as the interface and avoid duplicating formatter settings.
- Can I run PHP CS Fixer in Laravel CI pipelines?
- Yes. Add vendor/bin/php-cs-fixer check --diff to your CI job to fail builds on style violations, and optionally run fix locally or in a pre-commit hook. Wire the commands into Composer scripts for repeatability, and pin the dev dependency so CI results stay stable. Keep baseline formatting changes in their own PR before enabling the gate.
- Is PHP CS Fixer safe to include in a Laravel production deployment?
- PHP CS Fixer is a dev-only CLI with no runtime role in a Laravel application, so it should stay in require-dev and be excluded from production installs. It does not affect application architecture or runtime behavior. The main production-adjacent risk is change management: large initial diffs, merge conflicts, and CI failures after upgrades. Pin versions and review rule-set changes deliberately.
- What rule sets does PHP CS Fixer provide for modernizing code?
- Built-in rule sets include @PER-CS, @Symfony, and @PhpCsFixer, plus @auto and @auto:risky base sets. Migration rule sets such as @autoPHPMigration and @autoPHPMigration:risky modernize code toward newer PHP versions, while @autoPHPUnitMigration:risky targets newer PHPUnit. Adopt risky or migration sets deliberately because they can change behavior.
- How do I apply PHP CS Fixer to an existing Laravel codebase without breaking PRs?
- Inventory existing Pint or PHP CS Fixer usage first, then pick one approved preset and pin the Composer version. Run the fixer on an isolated branch or PR and keep baseline formatting separate from functional changes. After merging the baseline, add a CI check --diff gate so only new violations are blocked. This reduces large diffs and merge conflicts across the team.
- How should I manage PHP CS Fixer upgrades and rule-set changes?
- Pin PHP CS Fixer to a known-good version and upgrade deliberately rather than auto-updating the dev dependency. Review release notes and rule-set changes, especially risky or migration sets, and run the fixer in a dedicated PR. Recent releases include cache permission and path hardening, so verify CI cache behavior after upgrades. Assign an owner for the config, exceptions, and upgrade schedule.
- What are the alternatives to PHP CS Fixer for Laravel projects?
- Laravel Pint is the most common alternative and is built on PHP CS Fixer, making it a natural choice when you want a Laravel-maintained interface. Other options include PHP_CodeSniffer with PHPCBF and Easy Coding Standard. If you need direct control over PHP CS Fixer rule sets or migration rules, use PHP CS Fixer itself as the engine. Choose one formatter configuration as the team's source of truth.