slam/php-cs-fixer-extensions
Extensions and ready-to-use rulesets for FriendsOfPHP PHP-CS-Fixer. Adds custom fixers like final_abstract_public, final_internal_class, utf8 cleanup, inline comment spacing, function reference spacing, and PHP-only proxy fixers for consistent code style.
Strengths:
FinalAbstractPublicFixer and FinalInternalClassFixer directly address Laravel’s service container patterns and Doctrine entity handling, reducing manual code reviews.Utf8Fixer mitigates encoding-related bugs in Blade templates (*.phtml), a common pain point in Laravel projects.readonly classes, PHPUnit 11) while maintaining compatibility with Laravel’s latest versions (10+).php_only_braces and function_reference_space enforce consistency without overreach, making them suitable for teams prioritizing maintainability over strictness.Weaknesses:
setRiskyAllowed(true) could introduce unintended refactoring (e.g., modifying abstract classes). Requires explicit opt-in for risky rules.FinalInternalClassFixer) may conflict with Laravel’s conventions (e.g., repository classes). Requires pre-adoption testing.php-cs-fixer v3.x+ means breaking changes could occur.Alignment with Team Needs:
Adoption Feasibility:
Long-Term Viability:
php-cs-fixer v3.x+?Slamdunk) project becomes inactive?Trade-offs:
FinalAbstractPublicFixer) to avoid false positives?Utf8Fixer) provide sufficient value to justify adoption?Ideal Stack:
*.phtml) or mixed PHP/HTML files requiring UTF-8 enforcement.Compatibility Notes:
FinalAbstractPublicFixer) are Laravel-agnostic but may not address framework-specific needs.Assessment Phase (1–2 days):
.php_cs config and identify conflicts.Pilot Phase (3–5 days):
composer require --dev slam/php-cs-fixer-extensions
.php_cs to include custom fixers (example provided in README)../vendor/bin/php-cs-fixer fix --dry-run --diff
Full Adoption (1 week):
.php_cs changes into the main branch.php-cs-fixer CLI or Laravel Pint).FinalAbstractPublicFixer).Prerequisites:
setRiskyAllowed(true).Recommended Order:
Utf8Fixer, function_reference_space, and inline_comment_spacer.FinalAbstractPublicFixer and FinalInternalClassFixer in isolation.FinalAbstractPublicFixer) may break existing abstract classes. Use --dry-run to identify risks.Pros:
Utf8Fixer and php_only_braces reduce manual code reviews.Cons:
php-cs-fixer and this package for breaking changes.FinalAbstractPublicFixer to prevent service container leaks").final?").FinalInternalClassFixer)..php_cs.override file for exceptions.php-cs-fixer cache:clear).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| PHP-CS-Fixer breaking change | Build failures | Pin to a specific version in composer.json. |
| False positives in production code | Developer frustration | Test in staging; use --dry-run pre-merge. |
How can I help you explore Laravel packages today?