pmjones/php-styler
PHP-Styler is a PHP 8.1 code formatter that fully rewrites formatting for consistent spacing, indentation, and line splitting. It preserves code logic and comments, aims for diff-friendly output, and supports customizable styles/rules for structural transformations.
Strengths:
Styles, Rules, and Parses. This is valuable for enforcing team-specific or framework-specific conventions (e.g., Laravel’s PSR-12 adherence).git diff, reducing friction for collaborative development—a critical feature for Laravel teams working across repositories or with CI/CD pipelines.--workers) reduces formatting time for large codebases, which is essential for Laravel monorepos or projects with extensive test suites.Weaknesses:
Laravel-Specific Considerations:
.php files only. Laravel’s Blade templates (.blade.php) would require pre-processing to extract PHP logic, adding complexity.app/Console/Commands/) might break if they rely on specific formatting (e.g., for readability in handle() methods).app/Providers/AppServiceProvider.php often mix configuration and logic; aggressive reformatting could obscure intent.Dependencies:
AutoShell for CLI (no Laravel-specific dependencies). This ensures low friction for integration.CI/CD Pipeline Fit:
apply or check commands to enforce formatting before commits (e.g., using robo.phar or custom scripts).- name: Format PHP
run: vendor/bin/php-styler check || (echo "Formatting errors detected" && exit 1)
apply in a separate job to auto-fix formatting (with git-blame-ignore-revs to avoid noise).Database/Environment Impact:
| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Code Logic Breaks | Early versions had bugs (e.g., changelog 0.10.1) where inline comments caused syntax errors. Testing shows this is now fixed, but edge cases may remain. | Run preview on critical files first. Use check in CI to fail builds if formatting would break logic. |
| Team Resistance | Aggressive reformatting may frustrate developers accustomed to manual formatting or tools like PHP-CS-Fixer. | Pilot in a non-critical branch (e.g., feature/formatting). Allow opt-outs via config exclusions (e.g., Files::exclude()). |
| Blade Template Issues | Blade syntax (e.g., @foreach, {{ }}) might not parse correctly, leading to broken templates. |
Exclude Blade files from formatting or pre-process them to extract PHP logic. |
| Performance | Parallel processing helps, but large Laravel apps (e.g., with 10K+ files) may still be slow. | Start with a subset of files (e.g., app/ directory). Monitor CI runtime and adjust --workers. |
| Configuration Drift | Custom Format configurations may diverge from Laravel’s PSR-12 standards over time. |
Document the chosen Format (e.g., DeclarationFormat) in the team’s coding guidelines. Use vendor/bin/php-styler diff to audit changes. |
| Tooling Lock-In | Switching away later (e.g., to Laravel Pint) could require re-formatting the entire codebase. | Treat PHP-Styler as a temporary solution if needed, but avoid mixing it with other formatters. |
Adoption Scope:
app/, src/)?Configuration:
Format should be used? (DeclarationFormat, SymfonyFormat, or a custom one?)CI/CD Strategy:
Team Alignment:
Long-Term Maintenance:
php-styler.php config file (e.g., update it if Laravel’s conventions change)?Laravel Compatibility:
DeclarationFormat or SymfonyFormat).artisan via custom commands or service providers.Toolchain Synergy:
array_syntax, concat_space), while PHP-Styler handles broader formatting..git-blame-ignore-revs to avoid noise from initial formatting commits.IDE Support:
php-styler apply.php-styler preview on a sample of critical files (e.g., app/Http/Controllers/, app/Providers/).Format (e.g., DeclarationFormat with lineLen: 120).classBracePosition: 'next_line').resources/views/, tests/Feature/).composer require --dev pmjones/php-styler
./vendor/bin/php-styler init
How can I help you explore Laravel packages today?