- How do I install this package for a Laravel project?
- Run `composer require --dev ergebnis/php-cs-fixer-config` in your Laravel project’s root directory. The package includes a factory for generating PHP-CS-Fixer configurations, so no additional setup is needed beyond selecting a rule set in your `.php-cs-fixer.php` file.
- Which PHP versions does this package support, and how do I choose the right rule set for Laravel?
- The package supports PHP 5.3 through 8.3, with dedicated rule sets for each version. For Laravel 10+ (PHP 8.1+), use `Php81`, `Php82`, or `Php83`. For older Laravel versions, match the rule set to your project’s minimum PHP version (e.g., `Php74` for Laravel 9).
- Can I customize the rules for Laravel-specific patterns like Blade templates or Facade imports?
- Yes. Use the `Finder` class in your `.php-cs-fixer.php` to exclude Blade files (e.g., `resources/views`) and override rules like `no_short_open_tag` or `no_unused_imports` for Laravel’s Facade syntax. The package supports full PHP-CS-Fixer customization while providing preconfigured defaults.
- Will this package conflict with Laravel Pint or other tools like PSalm?
- Pint is a PHP-CS-Fixer wrapper with fewer rules, so conflicts are unlikely if you disable Pint or align configurations. For PSalm/PhpStan, ensure their rules don’t overlap with PHP-CS-Fixer’s formatting (e.g., avoid duplicate import checks). The package is designed to coexist with Laravel’s toolchain.
- How do I integrate this into GitHub Actions or Laravel’s CI pipeline?
- Add a step to your CI workflow (e.g., GitHub Actions) to run `composer coding-standards` or `./vendor/bin/php-cs-fixer fix`. The package includes pre-built workflows, and you can scope it to run only on push/pull requests. Exclude the cache directory (`.build/php-cs-fixer`) from Git and CI caches to avoid bloat.
- What’s the performance impact of running PHP-CS-Fixer in CI for large Laravel projects?
- For projects with 10,000+ files, PHP-CS-Fixer may add 1–3 minutes to CI time, depending on your runner’s specs. Test locally with `composer coding-standards --dry-run` to benchmark. Cache the cache directory and parallelize fixes where possible to mitigate delays.
- How do I handle legacy Laravel code that violates PHP-CS-Fixer rules (e.g., short open tags in Blade)?
- Use the `--allow-risky=yes` flag for unstable fixes during migration or exclude specific files/directories with the `Finder` class. For Blade templates, disable `no_short_open_tag` and adjust rules like `single_quote` to avoid false positives in legacy views.
- Is this package actively maintained, and how do I update the rule sets?
- The package is maintained by the [ergebnis](https://github.com/ergebnis) team, with updates aligned to PHP-CS-Fixer releases. Use `composer update ergebnis/php-cs-fixer-config` to upgrade. Assign a team member to monitor updates or automate via Dependabot for Laravel projects.
- What are the alternatives to this package, and when should I use them?
- For minimal configurations, use **Pint** (lighter, fewer rules). For highly bespoke setups, manually configure PHP-CS-Fixer. This package is ideal for Laravel teams needing version-aware, preconfigured rule sets with extensibility for Blade/Facade patterns.
- How do I migrate an existing Laravel project to this package without breaking builds?
- Start by running `php-cs-fixer check --diff` to audit violations. Pilot the package in a feature branch, configure `.php-cs-fixer.php` with your PHP version’s rule set, and test with `composer coding-standards`. Gradually enable fixes in CI before merging to `main`.