Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Styler Laravel Package

pmjones/php-styler

PHP-Styler is a PHP code formatter that tokenizes source files and rebuilds them with consistent spacing, indentation, and automatic line splitting. Configurable Styles, Rules, and Parses customize the diff-friendly output, while logic and comments are preserved. No dependencies beyond PHP 8.1.

View on GitHub
Deep Wiki
Context7

PHP Styler is a dependency-free PHP code formatter that parses source files into tokens, applies configurable styling, and reconstructs code with consistent horizontal and vertical spacing, indentation, and automatic line splitting. It uses a multi-stage pipeline of Parser, Token Rules, Assembler, Splitter, and Line Rules to preserve logic while completely reformatting code.

Formatting is customizable through Styles (token spacing, line breaks, casing), Rules (structural transformations), and Parses (token replacements).

  • Logic preservation — reformatted code runs exactly as before
  • Automatic line length control with priority-based splitting
  • Diff-friendly default output to reduce noise
  • Comment preservation — end-of-line and block comments stay in place
  • No dependencies beyond PHP 8.1 (plus AutoShell for the CLI)
Frequently asked questions about Php Styler
Can PHP-Styler enforce PSR-12 standards in a Laravel project?
Yes, PHP-Styler supports configurable styles and rules to align with PSR-12. Use the `PSR12` preset or customize spacing, line length, and brace positioning in your config. Test with `--check` first to avoid unintended changes to Laravel’s existing codebase.
How does PHP-Styler handle Blade templates (.blade.php) in Laravel?
PHP-Styler processes PHP files only, so Blade templates won’t be reformatted automatically. Pre-process Blade files to extract PHP logic (e.g., with a custom script) or exclude them via config. For now, focus on core PHP files like controllers, service providers, and commands.
Will PHP-Styler break Laravel’s Artisan commands or CLI scripts?
It *could*—PHP-Styler’s aggressive reformatting may disrupt CLI scripts if they rely on specific formatting (e.g., `handle()` methods in commands). Run a preview (`php-styler apply --dry-run`) on `app/Console/Commands/` first. Exclude problematic files in your config if needed.
How do I integrate PHP-Styler into a Laravel CI/CD pipeline?
Use the `check` command in a GitHub Actions job to fail builds on formatting issues, then run `apply` in a separate job to auto-fix. Example: Add `vendor/bin/php-styler check` to your linting step, then use `git blame-ignore-revs` to suppress noise in post-merge commits.
Does PHP-Styler support incremental formatting (e.g., fix only trailing commas)?
No, PHP-Styler rewrites *all* formatting, unlike PHP-CS-Fixer. If you need granular fixes, use PHP-CS-Fixer alongside it or exclude specific files. For Laravel, this limits adoption to full-team buy-in or pre-commit hooks with strict config.
What Laravel versions and PHP versions does PHP-Styler support?
PHP-Styler requires **PHP 8.1+** and has no Laravel-specific dependencies, so it works with Laravel 9.x, 10.x, and 11.x. Test thoroughly with your Laravel version, as aggressive reformatting might affect legacy code (e.g., pre-PSR-12 projects).
How does PHP-Styler handle inline comments or docblocks in Laravel?
Block comments (e.g., `/* ... */`) and docblocks are preserved in place, but inline comments (especially multi-line) may shift. Laravel’s docblock-heavy files (e.g., `AppServiceProvider.php`) should be tested carefully. Use `--dry-run` to preview changes before full application.
Can I customize PHP-Styler’s formatting rules for my Laravel team?
Absolutely. Define custom `Styles`, `Rules`, and `Parses` in your config to match Laravel-specific conventions (e.g., brace positioning, line length). Start with the `PSR12` preset, then tweak for team preferences. Document your rules for consistency.
What’s the performance impact of PHP-Styler on large Laravel projects?
PHP-Styler supports parallel processing (`--workers`) to speed up formatting for large codebases (e.g., Laravel monorepos). For a 10,000+ file project, expect minutes, not hours. Benchmark with your CI pipeline to set realistic timeouts.
How does PHP-Styler compare to Laravel Pint (official formatter)?
PHP-Styler is more aggressive—it rewrites *all* formatting, while Pint focuses on incremental fixes. Pint is Laravel’s recommended tool for PSR-12 compliance, but PHP-Styler offers deeper customization for structural changes (e.g., brace expansion). Use Pint for maintenance, PHP-Styler for team-wide reformatting.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums