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.
Enforce Consistent Code Style at Scale
Adopting php-styler enables teams to standardize PHP code formatting across repositories, reducing cognitive load for developers and minimizing noise in code reviews. This aligns with initiatives to improve developer productivity and maintainability.
Automate Code Quality Gates
Integrate php-styler into CI/CD pipelines to enforce formatting rules as a pre-commit or pre-merge check, reducing manual effort and ensuring compliance with team standards. This supports a "shift-left" quality strategy.
Migrate to Modern PHP Standards
For projects adopting PHP 8.1+, php-styler provides a lightweight alternative to complex tools like PHP-CS-Fixer, with built-in support for modern syntax (e.g., arrow functions, named arguments, match expressions). This enables teams to modernize their codebase without heavy tooling overhead.
Customizable Formatting for Niche Use Cases
Teams with specific formatting needs (e.g., Doctrine, Symfony, or PER coding standards) can leverage pre-built vendor formats or extend the tool via Styles, Rules, and Parses. This avoids reinventing the wheel for edge cases like:
else if to elseif or array() to [].Build vs. Buy Decision
Buy: If the team lacks the bandwidth to maintain a custom formatter or requires rapid adoption of a standardized style. php-styler’s MIT license and lack of dependencies (beyond PHP 8.1) reduce adoption friction.
Build: Only if the team needs highly specialized formatting logic not covered by existing Styles/Rules (e.g., domain-specific alignment or legacy code transformations). In such cases, forking and extending php-styler may be preferable to building from scratch.
Use Cases
Adopt php-styler when:
--workers=auto).Styles/Rules.Look elsewhere when:
php-styler intentionally avoids this to reduce maintenance burden.php-styler simplifies comments aggressively.php-styler is CLI-focused, though it could be integrated with tools like PHPStorm or VSCode via custom tasks.*"php-styler is a lightweight, high-impact tool to standardize our PHP codebase, reducing technical debt and improving developer velocity. By automating formatting—similar to how Black does for Python—we can:
It’s battle-tested (used in production since 2026), has zero dependencies beyond PHP 8.1, and supports parallel processing to handle large codebases efficiently. The upfront cost is minimal—just a composer require—and the ROI comes from reduced cognitive load and fewer merge conflicts."*
*"php-styler is a modern PHP formatter that:
--workers=auto) formats entire repos in minutes, not hours.check command flags unstyled files, and diff shows exactly what’s changing. No more ‘it looks fine to me’ debates.Styles or Rules in your config.Key differentiators vs. PHP-CS-Fixer:
Next steps:
composer require --dev pmjones/php-styler in a sandbox repo../vendor/bin/php-styler preview src/ to see how it handles our code.php-styler check as a pre-merge gate.Let’s start with the DeclarationFormat (opinionated for classes/functions) and adjust as needed."*
How can I help you explore Laravel packages today?