mfn/php-cs-fixer-config
Opinionated PHP-CS-Fixer ruleset for v3.11+ via a simple \Mfn\PhpCsFixer\Config::getRules() helper. Requires setRiskyAllowed(true). Minimal repo with issues disabled—PRs welcome to discuss technical changes.
Pros:
ordered_imports and nullable_type_declaration align with Laravel’s autoloader, dependency injection, and modern PHP practices (e.g., PHP 8.4+), reducing technical debt in core Laravel patterns..php-cs-fixer.php configs with a single method call, leveraging Laravel’s Composer autoloading for seamless adoption with zero architecture changes.nullable_type_declaration_for_default_null_value) ensures long-term viability without manual rule updates.Cons:
src/Config.php and verify maintainer legitimacy before adoption.setRiskyAllowed(true) introduces breaking changes (e.g., native_function_invocation, no_unused_imports), which may conflict with Laravel’s dynamic method handling (e.g., Facades like Auth::user() or magic methods in Service Providers).call_user_func_array).strict_types, declare_strict_types) may clash with legacy Laravel projects or teams requiring non-PSR-12 conventions (e.g., custom docblocks for Blade or legacy naming patterns).$rules merging (e.g., disable phpdoc_summary for Blade-specific docblocks).High Feasibility for Laravel Projects:
.php-cs-fixer.php with:
require 'vendor/autoload.php';
return (new PhpCsFixer\Config())
->setFinder(…)
->setRiskyAllowed(true)
->setRules(\Mfn\PhpCsFixer\Config::getRules());
composer.json dev dependencies:
"require-dev": {
"mfn/php-cs-fixer-config": "^2.10"
}
- run: ./vendor/bin/php-cs-fixer fix --rules=@mfn
Feasibility Blockers:
Provenance and Compliance:
laravel/php-cs-fixer-config)?Risk Mitigation:
setRiskyAllowed(true) on Laravel-specific code (e.g., Facades, dynamic method calls)?Customization Strategy:
App\CsFixerConfig) to extend the base rules?Maintenance Plan:
Tooling Alignment:
laravel-shift/php-cs-fixer) or use it as a standalone config?Ideal for:
nullable_type_declaration and ordered_imports optimize Laravel’s autoloader and modern PHP features.Poor Fit for:
ordered_imports are Laravel-specific and may not apply to generic PHP or other frameworks.strict_types or override docblock rules frequently may find the opinionated nature restrictive.Assessment Phase (1–2 Weeks):
src/Config.php and verify rules against Laravel-specific edge cases (e.g., Facades, Blade, dynamic methods).composer require --dev mfn/php-cs-fixer-config
./vendor/bin/php-cs-fixer fix --dry-run --rules=@mfn
Pilot Phase (2–4 Weeks):
no_unused_imports flagging Facade aliases).native_function_invocation breaking dynamic calls).phpdoc_summary for Blade files).Rollout Phase:
.php-cs-fixer.php in all Laravel projects with the package’s config.laravel/php-cs-fixer-config).// app/Config/CsFixerConfig.php
$rules = \Mfn\PhpCsFixer\Config::getRules();
$rules['phpdoc_summary'] = false; // Disable for Blade
return (new PhpCsFixer\Config())->setRules($rules);
Post-Rollout:
nullable_type_declaration and ordered_imports are optimized for Laravel’s autoloHow can I help you explore Laravel packages today?