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 Cs Fixer Laravel Package

friendsofphp/php-cs-fixer

PHP CS Fixer automatically fixes PHP code to match coding standards. Use built-in rule sets (PER-CS, Symfony, PhpCsFixer) or custom config to unify style, modernize PHP/PHPUnit code, and apply safe or risky migrations. Supports PHP 7.4–8.5.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Code Quality Enforcement: PHP-CS-Fixer is a perfect fit for Laravel/PHP projects where consistent coding standards are critical. It aligns with Laravel’s reliance on PSR-12 (PHP-FIG standards) and Symfony’s coding conventions, reducing friction in team collaboration.
  • Automation-Friendly: Integrates seamlessly with CI/CD pipelines (e.g., GitHub Actions, GitLab CI) to enforce standards pre-commit or pre-merge, reducing manual review overhead.
  • Modernization Support: Built-in rule sets like @autoPHPMigration and @Symfony:risky help gradually modernize legacy Laravel codebases (e.g., PHP 7.4 → 8.1+ syntax updates).
  • Customizability: Supports project-specific rule sets (via .php-cs-fixer.dist.php), allowing TPMs to tailor standards to team preferences (e.g., stricter Symfony rules for API layers, relaxed rules for legacy modules).

Integration Feasibility

  • Laravel Ecosystem Compatibility:
    • Works natively with Composer (--dev dependency), avoiding runtime bloat.
    • Integrates with Laravel Mix (via post-css hooks) or Vite for frontend-backend consistency.
    • Compatible with Laravel Forge/Envoyer for deployment-time enforcement.
  • Toolchain Synergy:
    • Pairs well with PHPStan (static analysis) and Psalm for type safety.
    • Can be gated in CI alongside tests (e.g., fail builds if fixes are needed).
    • Supports IDE plugins (PhpStorm, VS Code) for real-time feedback.
  • Performance:
    • Memoization (v3.91.1+) reduces redundant checks in large codebases.
    • Parallel processing (via --parallel) speeds up CI runs for monorepos.

Technical Risk

Risk Area Mitigation Strategy
Breaking Changes Use --dry-run first; test with @Symfony or @PSR12 rule sets incrementally.
Rule Conflicts Start with @auto or @auto:risky, then refine via .php-cs-fixer.dist.php.
Legacy Code Leverage @autoPHPMigration for safe syntax updates (e.g., foreach → arrow functions).
CI Flakiness Cache Composer dependencies; run in a separate job from tests.
Custom Rules Extend via PHP-CS-Fixer’s custom rule API if built-in rules are insufficient.

Key Questions for TPM

  1. Rule Set Strategy:
    • Should we adopt @Symfony (strict) or @PSR12 (minimal) as a baseline? How will we handle exceptions (e.g., legacy controllers)?
  2. CI Integration:
    • Where in the pipeline should PHP-CS-Fixer run? (Pre-commit? Merge check? Post-deploy?)
    • Should failures block merges, or require manual approval for large changes?
  3. Developer Experience:
    • Will we enforce pre-commit hooks (e.g., via husky + php-cs-fixer) or rely solely on CI?
    • How will we handle false positives (e.g., third-party libraries)?
  4. Performance:
    • For monorepos (>10k files), should we exclude vendor/, cache results, or use --parallel?
  5. Modernization Roadmap:
    • Should we use @autoPHPMigration to enable PHP 8.2+ features (e.g., match expressions, readonly properties)?
  6. Customization:
    • Are there team-specific rules (e.g., line length, docblock formats) that need customization?

Integration Approach

Stack Fit

  • Laravel-Specific Synergies:
    • Artisan Integration: Add a custom Artisan command (e.g., php artisan cs:fix) to wrap php-cs-fixer.
    • Laravel Forge/Envoyer: Deploy a pre-deploy hook to run php-cs-fixer fix --diff for visibility.
    • Laravel Valet: Include in valet link hooks for local consistency.
  • Toolchain Placement:
    • Dev Dependencies: Install via Composer (composer require --dev friendsofphp/php-cs-fixer).
    • IDE Plugins: Enable PhpStorm’s built-in PHP-CS-Fixer or VS Code extension for real-time fixes.
    • EditorConfig: Use .editorconfig to align with PHP-CS-Fixer rules (e.g., indent_size, end_of_line).

Migration Path

  1. Phase 1: Assessment
    • Run ./vendor/bin/php-cs-fixer fix --dry-run --diff to preview changes.
    • Analyze rule set coverage (e.g., @Symfony vs. @PSR12).
  2. Phase 2: Incremental Adoption
    • Start with non-breaking rules (e.g., spacing, imports) via @auto.
    • Gradually introduce riskier rules (e.g., @Symfony:risky) in separate PRs.
  3. Phase 3: CI Enforcement
    • Add to CI (e.g., GitHub Actions):
      - name: PHP-CS-Fixer
        run: ./vendor/bin/php-cs-fixer fix --diff --allow-risky=yes
      
    • Fail builds if fixes are needed (or allow manual overrides for large changes).
  4. Phase 4: Pre-Commit Hooks
    • Add to husky or pre-commit:
      ./vendor/bin/php-cs-fixer fix --path-mode=intersection
      

Compatibility

Component Compatibility Notes
PHP Versions Supports 7.4–8.5; use --allow-unsupported-php-version for bleeding-edge.
Laravel Versions Works with Laravel 5.8+; test with Laravel Pint (alternative) for LTS.
Third-Party Packages Exclude vendor/ via .php-cs-fixer.dist.php to avoid modifying dependencies.
Custom Code Use exclude in config to skip legacy modules (e.g., app/OldLegacyModule).

Sequencing

  1. Initial Setup:
    • Generate config: ./vendor/bin/php-cs-fixer init.
    • Commit .php-cs-fixer.dist.php to version control.
  2. Rule Set Selection:
    • Start with @Symfony or @PSR12; refine via custom rules.
  3. CI Integration:
    • Add as a separate job before tests to avoid flaky builds.
  4. Developer Onboarding:
    • Document in CONTRIBUTING.md how to run fixes locally.
    • Provide a cheat sheet for common fixes (e.g., php-cs-fixer fix --rules=@Symfony).

Operational Impact

Maintenance

  • Configuration Drift:
    • Risk: Rule sets may diverge across branches if not version-controlled.
    • Mitigation: Enforce .php-cs-fixer.dist.php in all branches; use php-cs-fixer update to sync.
  • Rule Updates:
    • Risk: New PHP-CS-Fixer versions may introduce breaking changes.
    • Mitigation: Pin versions in composer.json (e.g., ^3.95) and test upgrades in a staging environment.
  • Custom Rules:
    • Risk: Custom rules may break with updates.
    • Mitigation: Test custom rules against new PHP-CS-Fixer versions in CI.

Support

  • Developer Onboarding:
    • Effort: Low to moderate. Most IDEs support PHP-CS-Fixer natively.
    • Training: Document common fixes (e.g., "Why does PHP-CS-Fixer change foreach to arrow functions?").
  • Troubleshooting:
    • Common Issues:
      • False positives in third-party code → Exclude via exclude.
      • Performance in large repos → Use --parallel or cache results.
    • Debugging: Use --verbose and --dry-run to diagnose issues.

Scaling

  • Large Codebases:
    • Performance: Use --parallel=8 and exclude vendor//storage//bootstrap/.
    • Incremental Fixes: Run on changed files only:
      git diff --name-only HEAD~1 | xargs ./vendor/bin/php-cs-fixer fix
      
  • Monorepos:
    • Strategy: Use --path-mode=intersection for pre-commit hooks.
    • CI:
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.
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
atriumphp/atrium