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.
final modifiers) without manual refactoring. Prioritizes maintainability over perfection.readonly classes and PHPUnit 11.PhpFileOnlyProxyFixer address Blade/PHTML templating quirks.no_superfluous_phpdoc_tags (allowing mixed) bridge static analysis tools.utf8 rule to prevent encoding-based vulnerabilities.Adopt if:
Look elsewhere if:
setRiskyAllowed(true) may break legacy code).Problem: "Inconsistent code formatting slows down development, increases bugs, and raises onboarding costs. For example, UTF-8 encoding issues in Blade templates caused [X] production incidents last quarter."
Solution: *"This package extends PHP-CS-Fixer to enforce Laravel-specific standards—like UTF-8 encoding and abstract class finality—automatically. It’s a zero-cost way to:
Ask: "Approve 1-hour setup in CI/CD to adopt this as a required status check for PRs. ROI: Faster releases, fewer bugs."
Why This Package? *"It solves three critical pain points in our Laravel codebase:
Utf8Fixer ensures all files use UTF-8 (blocks encoding bugs in Blade templates).FinalAbstractPublicFixer standardizes final modifiers for abstract methods (critical for Laravel’s service container).readonly classes and PHPUnit 11 out of the box."*Implementation Plan:
composer require --dev slam/php-cs-fixer-extensions
.php_cs:
$config->registerCustomFixers([new SlamCsFixer\Utf8Fixer()]);
$config->setRules(['Slam/utf8' => true]);
.github/workflows/php-cs-fixer.yml:
- name: PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --rules=@Slam --allow-risky=yes
Risks & Mitigations:
| Risk | Mitigation |
|---|---|
| False positives in Doctrine | Test with php-cs-fixer fix --dry-run first. |
| PHP 8.4+ requirement | Upgrade PHP in parallel (blocker: none). |
setRiskyAllowed(true) |
Review fixers individually before enabling. |
Alternatives Considered:
Next Steps:
Key Metric: "Reduce PR review time by 20% by auto-fixing 80% of formatting issues."
How can I help you explore Laravel packages today?