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 completely rewrites formatting for consistent spacing, indentation, and line wrapping. It preserves program logic and comments, aims for diff-friendly output, and supports customizable styles, rules, and parses via a token-based pipeline.

View on GitHub
Deep Wiki
Context7

PHP-Styler is a PHP 8.1+ code formatter that fully rebuilds your source formatting from tokens, producing consistent spacing, indentation, and line breaks. It parses code via PhpToken, applies configurable Styles, Rules, and Parses, then assembles and splits lines to meet a maximum length—aiming for diff-friendly output while preserving program logic.

  • Logic-preserving reformatting that keeps code behavior intact
  • Consistent horizontal/vertical spacing (indentation, blank lines)
  • Automatic line-length control with prioritized split points
  • Highly customizable formatting via styles, structural rules, and token replacements
  • Preserves comments (EOL stays in place; blocks preserved)
Frequently asked questions about Php Styler
Can PHP-Styler safely format Laravel 10+ applications without breaking functionality?
Yes, PHP-Styler preserves logic by rebuilding code from an abstract syntax tree (AST), ensuring reformatted PHP behaves identically. However, exclude config/, routes/, and Blade templates (due to string/heredoc limitations) to avoid unintended formatting conflicts. Always test in a staging environment first.
How do I install and run PHP-Styler in a Laravel project?
Install via Composer: `composer require pmjones/php-styler`. Run with `./vendor/bin/php-styler format src/`. For Laravel, add a `composer cs-fix` script aliasing this command. Use `--workers` for parallel processing on large codebases (e.g., `app/` directory).
Does PHP-Styler support Laravel’s Blade templates or should I exclude them?
PHP-Styler struggles with embedded PHP in Blade files (e.g., `@php` directives, heredocs) due to string-splitting limitations. Exclude Blade files via `--exclude=resources/views/*.blade.php` in your config. For critical Blade logic, manual review or exclusion is recommended.
What’s the difference between PHP-Styler and PHP CS Fixer for Laravel?
PHP-Styler *rewrites* code entirely (e.g., reorders imports, normalizes braces), while PHP CS Fixer applies *incremental fixes* (e.g., spacing, line breaks). Use PHP-Styler for opinionated reformatting (e.g., SymfonyFormat) and CS Fixer for fine-tuned adjustments. They can coexist if configured to target different file types.
How do I configure PHP-Styler to match Laravel’s PSR-12 coding standards?
Use the pre-built `SymfonyFormat` (PSR-12 compatible) in your `php-styler.php` config. Example: `return [new SymfonyFormat()];`. Customize further with `Styles` (e.g., line length) or `Rules` (e.g., `NormalizeImports`). Test with `php-styler preview` before full application.
Will PHP-Styler work in CI/CD pipelines for Laravel projects?
Yes, PHP-Styler is lightweight and supports parallel execution (`--workers`) to handle Laravel’s ~100K+ LoC efficiently. Cache results with `--cache` for faster CI runs, but note cache invalidation requires a full reformat. Integrate via GitHub Actions or Git hooks (e.g., `composer cs-check`).
How do I handle conflicts between PHP-Styler’s reformatting and existing manual formatting (e.g., in config/ or routes/)?
Exclude sensitive files via `--exclude` or a `Files` rule in your config. Example: `return [new Files(['config/', 'routes/'])]`. For partial adoption, script selective reformatting (e.g., `find app/ -name '*.php' | xargs php-styler format`). Always preview changes first.
Are there performance concerns for large Laravel applications?
PHP-Styler is optimized for performance with parallel processing (`--workers`) and caching. On a Laravel codebase (~100K+ LoC), expect ~1–5 minutes for a full reformat (depending on hardware). Test with `--dry-run` to estimate runtime. Cache invalidation is the main bottleneck—avoid frequent config changes.
Can PHP-Styler integrate with Laravel’s testing pipeline (e.g., Pest or PHPUnit)?
Yes, add a `composer cs-check` script to validate formatting before tests run. Example: `composer cs-check` → `./vendor/bin/php-styler check src/`. Chain with PHPStan or Pest for a full quality gate. Use `--diff` to highlight formatting issues in CI output.
What maintenance is required for PHP-Styler in a Laravel project?
Maintenance involves updating the `php-styler.php` config as Laravel evolves (e.g., new PHP features in 9+). Monitor for rule interactions (e.g., `NormalizeImports` + `ExpandGroupedImports`) and test with `php-styler preview` after config changes. Document exclusions (e.g., Blade files) in your team’s coding guidelines.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport