kubawerlos/php-cs-fixer-custom-fixers
Custom fixers for FriendsOfPHP PHP-CS-Fixer. Install via Composer, register the Fixers set, then enable individual rules to enforce additional style conventions (e.g., prefer class constants, remove leading global namespace slashes, tidy PHPDoc params).
php-cs-fixer is already a dev dependency in many Laravel projects).NoLeadingSlashInGlobalNamespaceFixer, PhpdocNoSuperfluousParamFixer), addressing niche Laravel-specific patterns (e.g., Doctrine migrations, PhpStorm-generated comments).composer require --dev. Works seamlessly with Laravel’s dependency management.php-cs-fixer.config.php), leveraging Laravel’s existing php-cs-fixer integration (e.g., via laravel-pint or custom scripts).pint instead of php-cs-fixer directly).php-cs-fixer fix --diff).php-cs-fixer’s --dry-run or pre-commit integration.| Risk Area | Severity | Mitigation |
|---|---|---|
| Breaking Changes | Medium | Some fixers are deprecated (e.g., DataProviderNameFixer → php_unit_data_provider_name). Audit config before adoption. |
| Performance Overhead | Low | Fixers run during development/linting, not production. Minimal runtime cost. |
| False Positives | Medium | Risky fixers (e.g., NoReferenceInFunctionDefinitionFixer) may break legacy code. Test on a branch first. |
| Dependency Conflicts | Low | MIT-licensed; no conflicts with Laravel/PHP CS Fixer core. |
| Maintenance Burden | Low | Fixers are stable (last release: 2026-05-12). Low churn expected. |
Adoption Scope:
php-cs-fixer rules or supplement them? (E.g., enable NoUselessCommentFixer but keep @PSR12 rules.)NoTrailingCommaInSinglelineFixer.)CI/CD Impact:
php-cs-fixer step in GitHub Actions.)--fix --allow-risky) or run as a warning (--dry-run)?Developer Experience:
ForeachUseValueFixer may surprise developers.)Legacy Code:
ignore rules in config.)NoDoctrineMigrationsGeneratedCommentFixer may need selective disabling.)Testing:
php-cs-fixer fix --diff on main.)foreach loops.)Laravel Ecosystem:
php-cs-fixer setup (no framework modifications needed).laravel/pint, configure it to use the custom fixers via pint.yaml:
finder:
exclude: ["vendor"]
fixer_custom_fixers: ["kubawerlos/php-cs-fixer-custom-fixers"]
php-cs-fixer command or create a custom one (e.g., php artisan cs-fix:custom).Tooling Compatibility:
.pre-commit-config.yaml:
- repo: local
hooks:
- id: php-cs-fixer-custom
name: PHP CS Fixer (Custom)
entry: vendor/bin/php-cs-fixer fix --rules=@CustomRules --allow-risky
language: system
--diff for real-time feedback.Phase 1: Audit
php-cs-fixer fix --dry-run --rules=@CustomRules on a feature branch to identify changes.NoReferenceInFunctionDefinitionFixer) initially.Phase 2: Incremental Adoption
NoTrailingCommaInSinglelineFixer, NoUselessCommentFixer).ForeachUseValueFixer) with team buy-in.NoNullableBooleanTypeFixer) unless critical.Phase 3: CI Enforcement
--fix (auto-correct) or --diff (fail on changes).- name: PHP CS Fixer (Custom)
run: vendor/bin/php-cs-fixer fix --rules=@CustomRules --allow-risky --diff
ForeachUseValueFixer) may conflict with Blade syntax. Test on .blade.php files.NoDoctrineMigrationsGeneratedCommentFixer may need exclusion for database/migrations/.| Step | Action | Dependencies |
|---|---|---|
| 1. Installation | composer require --dev kubawerlos/php-cs-fixer-custom-fixers |
Composer, PHP CS Fixer |
| 2. Configuration | Update php-cs-fixer.config.php to register fixers. |
Existing php-cs-fixer config |
| 3. Testing | Run php-cs-fixer fix --dry-run --rules=@CustomRules on a branch. |
Git, PHP CS Fixer |
| 4. CI Integration | Add to GitHub Actions/GitLab CI. | CI pipeline |
| 5. Developer Onboarding | Document new rules and provide examples. | Team communication |
| 6. Monitoring | Track false positives/negatives in PRs. | Jira/GitHub Issues |
php-cs-fixer.config.php to avoid per-developer inconsistencies.DataProviderNameFixer) and migrate to native PHP CS Fixer rules.NoLeadingSlashInGlobalNamespaceFixer matters")..blade.php).--parallel).--parallel for large codebases (e.g., --parallel=8).How can I help you explore Laravel packages today?