pmjones/php-styler
PHP-Styler is a PHP 8.1+ code formatter that fully reformats your code for consistent spacing, indentation, and line lengths. It preserves logic and comments, is diff-friendly by default, and is customizable via styles, rules, and parses.
Strengths:
SymfonyFormat, DoctrineFormat), aligning with Laravel’s ecosystem. Custom DeclarationFormat is well-suited for Laravel’s class-heavy architecture.app/ directory with ~100+ files).Weaknesses:
--rules).@param tags in Laravel’s annotations).Laravel Stack Compatibility:
composer require --dev).check/apply commands..gitignore for generated files (e.g., vendor/).Key Dependencies:
php artisan make:controller).High:
php-styler.php may diverge from Laravel’s evolving style (e.g., new PHPDoc rules).--workers) may overload CI/CD for monorepos (e.g., Laravel + Forge).Blade templates or eval() may break parsing.use function) may fail.Mitigation:
preview command to review changes before apply..git-blame-ignore-revs to avoid false positives.check in CI, then enforce via apply in a feature branch.SymfonyFormat, DoctrineFormat, or custom) should we adopt?apply run in CI (risky) or only locally (enforced via pre-commit hooks)?vendor/, node_modules/, generated config files)?--workers) impact CI/CD runtime for large repos (e.g., Laravel + Forge)?php-styler.php config and update it as Laravel’s style evolves?Laravel Ecosystem:
app/, config/, database/, and routes/ files.src/, tests/).php-styler in a custom Artisan command (e.g., php artisan style:apply).Toolchain Placement:
composer require --dev pmjones/php-styler.composer.json scripts:
"scripts": {
"style:check": "php vendor/bin/php-styler check",
"style:apply": "php vendor/bin/php-styler apply",
"style:preview": "php vendor/bin/php-styler preview"
}
husky or pre-commit).Assessment Phase:
composer require --dev pmjones/php-styler in a test environment../vendor/bin/php-styler init
preview against a sample file (e.g., app/Http/Controllers/Controller.php).Pilot Phase:
app/Console/Commands/).php artisan migrate, php artisan tinker).Full Rollout:
php-styler.php to match Laravel’s style (e.g., DeclarationFormat with lineLen: 120).- name: Check PHP Style
run: composer style:check
Post-Rollout:
Laravel-Specific Considerations:
.blade.php files (use a custom Files implementation or .php-styler.php exclusions)..env (use Files::exclude()).bootstrap/cache/ and storage/framework/views/ (add to .gitignore).@php-styler-expansive for complex docblocks (e.g., @param array<int, string> $data).Format Selection:
DeclarationFormat (recommended for Laravel’s class-heavy code).SymfonyFormat (closer to Laravel’s style but may need overrides).DoctrineFormat (strict but opinionated).Initial Setup:
preview on critical files (e.g., app/Http/Kernel.php).Incremental Adoption:
check in CI (fail builds if files are unstyled).apply in PR templates or branch rules.Long-Term:
Config Management:
php-styler.php.0.x@dev) to avoid breaking changes.Dependency Updates:
Styler::fromConfig() in 0.22.0).How can I help you explore Laravel packages today?