- How do I install this package for Laravel projects?
- Run `composer require --dev kubawerlos/php-cs-fixer-custom-fixers` in your Laravel project. The package integrates seamlessly with Laravel’s existing PHP CS Fixer setup, requiring only a configuration update in `php-cs-fixer.php` or `.php-cs-fixer.dist.php`.
- Which Laravel-specific fixers should I enable first?
- Start with low-risk fixers like `NoLeadingSlashInGlobalNamespaceFixer` or `NoDoctrineMigrationsGeneratedCommentFixer` to clean up Laravel/Doctrine-specific patterns. These address common pain points without disrupting logic. Test in a staging environment before full adoption.
- Will this break existing PHPUnit or Pest tests?
- Most fixers are safe, but some like `PhpUnitDedicatedAssertFixer` or `PhpUnitAssertArgumentsOrderFixer` may alter test syntax. Run tests in a CI pipeline after enabling new rules to catch regressions. Use `--dry-run` to preview changes first.
- How do I handle conflicts with Laravel’s default PHP CS Fixer rules?
- Conflicts often arise between custom fixers (e.g., `NoSuperfluousConcatenationFixer`) and built-in rules like `array_syntax`. Disable conflicting rules explicitly in your config or use `!rule_name` to override. Always test with a subset of fixers first.
- Can I use this in a CI/CD pipeline for Laravel GitHub Actions?
- Yes, integrate it into your workflow by running `php-cs-fixer fix --rules=@PSR2 --rules=CustomFixer::name`. For GitHub PRs, use `php-cs-fixer/diff` to show changes. Benchmark performance—some fixers may slow down builds, so consider parallel execution or gating to specific branches.
- Are there any deprecated fixers I should avoid?
- Yes, fixers like `DataProviderNameFixer` or `InternalClassCasingFixer` are deprecated in favor of PHP CS Fixer’s built-in rules. Audit your config for redundancy before enabling new custom fixers. Check the [README](https://github.com/kubawerlos/php-cs-fixer-custom-fixers) for updated recommendations.
- How do I whitelist files for risky fixers like `IssetToArrayKeyExistsFixer`?
- Use the `paths` or `paths_mode` config options to exclude specific files or directories. For example, add `'paths': ['src/', '!tests/'],` to your PHP CS Fixer config. This allows gradual adoption while protecting legacy code.
- Does this package support Laravel Valet or Sail environments?
- The package works in any PHP environment, including Valet or Sail. Ensure your `php-cs-fixer` version is compatible (v3.0+) and that the `bootstrap.php` is loaded if using the `php-cs-fixer/shim` package. Test locally before deploying to production.
- What’s the best way to test custom fixers before enforcing them?
- Run `php-cs-fixer fix --dry-run --rules=CustomFixer::name` to preview changes. Use `php-cs-fixer fix --diff` to see Git diffs, or integrate with `pestphp/pest` for automated testing. Start with a small subset of files to validate behavior.
- Are there alternatives to this package for Laravel-specific coding standards?
- For Laravel, consider `laravel-pint` (a Laravel-focused fork of PHP CS Fixer) or `spatie/laravel-phpstan` for static analysis. However, this package offers targeted fixers like `NoDoctrineRepositoryCommentFixer` that aren’t covered by alternatives. Combine tools based on your needs.