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