Weave Code
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 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.

View on GitHub
Deep Wiki
Context7

Companion to PHP-Parser that rebuilds PHP code from AST.

Frequently asked questions about Php Styler
Can PHP-Styler safely format Laravel Blade templates (.blade.php) without breaking syntax?
PHP-Styler does not natively handle Blade syntax like `@foreach`, `@php`, or `{{ }}` directives, which can cause parsing errors or broken templates. You must exclude Blade files from formatting or preprocess them to strip Blade tags before running PHP-Styler. Test thoroughly on critical Blade files first.
How do I install PHP-Styler in a Laravel project?
Run `composer require --dev pmjones/php-styler` to install it as a dev dependency. Then integrate it into your workflow via a custom Artisan command or Git hooks. Ensure your Laravel project uses PHP 8.1+ for compatibility.
Does PHP-Styler support incremental formatting like PHP-CS-Fixer?
No, PHP-Styler reformats files completely and does not support incremental fixes. This means every run reprocesses the entire file, which can slow down CI pipelines for large Laravel codebases. Consider using it in pre-commit hooks or CI checks rather than interactive editing.
Will PHP-Styler break dynamic PHP code in Laravel, like `eval()`, `create_function()`, or `app()->make()` calls?
There’s a risk of functional regressions in dynamic code, as PHP-Styler aggressively reformats syntax. Test thoroughly on files using `eval()`, dynamic class names, or magic methods (`__call()`, `__invoke()`). Start with non-critical directories to mitigate risks.
How can I customize PHP-Styler’s formatting for Laravel-specific needs, like facades (e.g., `App::make()`) or custom syntax?
Extend PHP-Styler’s `DeclarationFormat` or `PlainFormat` classes to handle Laravel-specific cases. For example, override token rules to preserve facade syntax or adjust spacing around Laravel constructs. Check the [GitHub repo](https://github.com/pmjones/php-styler) for extensibility examples.
Is PHP-Styler compatible with older Laravel versions (e.g., 8.x or 9.x) that use PHP 7.4–8.0?
No, PHP-Styler requires PHP 8.1+, so Laravel 10+ projects are the only supported versions. If you’re on an older Laravel version, upgrade or use an alternative like PHP-CS-Fixer, which supports broader PHP versions.
How does PHP-Styler handle line numbers in tests or debug logs after reformatting?
Reformatting alters line numbers, which can break test assertions or debug logs referencing specific lines. Update snapshots or test expectations after running PHP-Styler. For CI pipelines, consider running tests *before* formatting to catch issues early.
Can I integrate PHP-Styler into GitHub Actions for automated formatting checks?
Yes, add a step to your GitHub Actions workflow using `php-styler check` or a custom script. Example: `php vendor/bin/php-styler check app/ --dry-run`. Combine it with `php-cs-fixer` for a two-stage validation (style checks + reformatting).
What are the performance implications of running PHP-Styler on a large Laravel codebase?
PHP-Styler can be resource-intensive for large projects due to its full-file reprocessing. Use the `--workers` flag for parallel processing or run it in CI only on changed files. Test on a staging environment first to gauge runtime.
Are there alternatives to PHP-Styler for Laravel that handle Blade templates or incremental fixes?
Yes, consider **PHP-CS-Fixer** (supports Blade templates and incremental fixes) or **Prettier** (via plugins like `prettier-plugin-php`). PHP-CS-Fixer is more widely adopted in Laravel projects and offers safer, targeted formatting. PHP-Styler is better for aggressive, full-file 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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle