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 like @PER-CS, @Symfony, or @PhpCsFixer, or define your own config. Helps modernize code for newer PHP and PHPUnit. Supports PHP 7.4–8.5.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Code Quality Enforcement: PHP-CS-Fixer is a non-negotiable tool for Laravel projects to enforce consistent coding standards (PSR-12, Symfony, or custom rules). It integrates seamlessly with Laravel’s PHP-based ecosystem (e.g., Blade templates, controllers, models) and aligns with Laravel’s opinionated best practices (e.g., PSR-12 compliance).
  • Automation-Friendly: Designed for CI/CD pipelines, it can be triggered on pre-commit hooks (via Git hooks or tools like Laravel Pint) or post-merge checks to prevent style violations from entering the codebase.
  • Modernization Support: Rule sets like @autoPHPMigration and @autoPHPUnitMigration help gradually modernize legacy Laravel codebases (e.g., PHP 7.4 → 8.1, PHPUnit 8 → 10), reducing manual refactoring effort.
  • Customizability: Supports team-specific rules via .php-cs-fixer.dist.php, allowing TPMs to tailor standards (e.g., enforcing Laravel-specific conventions like use App\Models\* imports).

Integration Feasibility

  • Laravel Ecosystem Compatibility:
    • Works natively with Composer (--dev dependency).
    • Supports Blade templates, PHPUnit tests, and Laravel-specific files (e.g., routes/web.php, AppServiceProvider.php).
    • Integrates with Laravel Pint (a Laravel-first wrapper) for simplified CLI usage.
  • Toolchain Synergy:
    • Complements PHPStan (static analysis) and Psalm by fixing issues automatically rather than just reporting them.
    • Can be chained with phpunit or Laravel’s artisan test for pre-test style checks.
  • IDE/Editor Support: Native plugins for PhpStorm (Laravel’s preferred IDE) and VS Code ensure real-time feedback, reducing context-switching for developers.

Technical Risk

  • False Positives/Negatives:
    • Some risky rules (e.g., @autoPHPMigration:risky) may break functionality if misconfigured. Requires gradual adoption and manual review for critical fixes.
    • Custom rules (e.g., Laravel-specific import paths) may need maintenance as the codebase evolves.
  • Performance Overhead:
    • Parallel runner (default since v3.94.0) mitigates this, but large monorepos (e.g., Laravel SaaS with many packages) may still experience slower CI runs if not optimized (e.g., caching, path filtering).
    • Memory usage can spike during parallel execution; monitor in CI (e.g., GitHub Actions memory limits).
  • Dependency Conflicts:
    • Rare but possible with legacy Laravel versions (e.g., PHP 7.4). Use php-cs-fixer/shim if conflicts arise.
  • Merge Conflicts:
    • If multiple developers run php-cs-fixer fix locally, style changes may conflict in PRs. Mitigate with:
      • Pre-commit hooks (e.g., husky + simple-php-unit).
      • CI enforcement (fail builds on style violations).

Key Questions for TPM

  1. Standard Selection:
    • Should we use @Symfony (Laravel’s default), @PSR12, or a custom set? How will this align with Laravel’s evolving conventions?
  2. Risk Tolerance:
    • Which risky rules (e.g., @autoPHPMigration:risky) are acceptable for automated fixes vs. requiring manual review?
  3. CI/CD Strategy:
    • Should php-cs-fixer run in pre-commit, pre-merge, or post-merge? How will we handle blocking vs. warning failures?
  4. Editor vs. CLI:
    • Will we enforce real-time fixes in IDEs (e.g., PhpStorm) or rely on CI-only enforcement?
  5. Legacy Code:
    • How will we phase in fixes for large, pre-existing codebases? Should we use .php-cs-fixer.dist.php exclusions temporarily?
  6. Maintenance:
    • Who will update rules as Laravel/PHP evolves (e.g., PHP 8.5 support)? Will this be a dedicated task or part of tech debt cycles?

Integration Approach

Stack Fit

  • Laravel-Specific:
    • Laravel Pint: A Laravel-first wrapper that simplifies CLI commands (e.g., php artisan pint) and integrates with Laravel’s task scheduler (schedule:run).
    • Blade Template Support: Can fix Blade syntax (e.g., @foreach spacing) alongside PHP files.
    • Artisan Integration: Potential for a custom Artisan command (e.g., php artisan cs-fix) to standardize usage.
  • Toolchain:
    • Git Hooks: Use husky + simple-php-unit to run php-cs-fixer on pre-commit.
    • CI/CD: Add to GitHub Actions/GitLab CI as a required step (e.g., fails builds on violations).
    • PHPStan/Psalm: Run php-cs-fixer before static analysis to reduce noise from style issues.

Migration Path

  1. Pilot Phase:
    • Start with a subset of files (e.g., app/Http/Controllers/) using --dry-run to assess impact.
    • Use @Symfony or @PSR12 as a baseline.
  2. Gradual Rollout:
    • Phase 1: Enforce in CI only (non-blocking warnings).
    • Phase 2: Add pre-commit hooks for local enforcement.
    • Phase 3: Enable risky rules (e.g., @autoPHPMigration) with manual review.
  3. Legacy Handling:
    • Use .php-cs-fixer.dist.php to exclude problematic files temporarily.
    • Example:
      return PhpCsFixer\Config::create()
          ->setRules([
              '@Symfony' => true,
              'no_unused_imports' => true,
          ])
          ->setPathCache(__DIR__.'/var/php-cs-fixer.cache')
          ->setFinder(
              PhpCsFixer\Finder::create()
                  ->exclude(['legacy/', 'vendor/'])
          );
      

Compatibility

  • PHP Versions:
    • Officially supports PHP 7.4–8.5. For unsupported versions, use --allow-unsupported-php-version=yes (not recommended for production).
  • Laravel Versions:
    • Works with Laravel 8+ (PHP 7.4+) and Laravel 9/10 (PHP 8.0+). For Laravel 5.x, use an older PHP-CS-Fixer version (e.g., v2.x).
  • Dependency Conflicts:
    • If conflicts arise (e.g., with symfony/console), use php-cs-fixer/shim or Composer’s conflict-resolution.

Sequencing

  1. Initial Setup:
    • Install via Composer:
      composer require --dev friendsofphp/php-cs-fixer
      
    • Initialize config:
      ./vendor/bin/php-cs-fixer init
      
  2. Configuration:
    • Customize .php-cs-fixer.dist.php for Laravel-specific rules (e.g., import ordering).
    • Example:
      return PhpCsFixer\Config::create()
          ->setRules([
              '@Symfony' => true,
              'ordered_imports' => ['sort_algorithm' => 'alpha'],
              'no_unused_imports' => true,
          ]);
      
  3. CI/CD Integration:
    • Add to .github/workflows/ci.yml:
      - name: PHP-CS-Fixer
        run: ./vendor/bin/php-cs-fixer fix --diff --dry-run
      
  4. Local Enforcement:
    • Add to package.json (if using npm scripts):
      "scripts": {
        "lint:fix": "php ./vendor/bin/php-cs-fixer fix"
      }
      
    • Or use Laravel Pint:
      composer require laravel/pint --dev
      php artisan pint
      

Operational Impact

Maintenance

  • Configuration Drift:
    • Risk: Developers may override .php-cs-fixer.dist.php locally, leading to inconsistencies.
    • Mitigation:
      • Enforce centralized config via CI (reject PR
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