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

fabpot/php-cs-fixer

Automatically fix PHP coding standards issues and unify style across your codebase. Includes rule sets like PER-CS, Symfony, and PhpCsFixer, plus configurable rules and migrations to modern PHP and PHPUnit. Supports PHP 7.4–8.5.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Code Quality Automation: PHP-CS-Fixer is a perfect fit for Laravel/PHP projects to enforce consistent coding standards (e.g., PSR-12, Symfony, or custom rulesets). It integrates seamlessly with Laravel’s existing tooling (e.g., phpunit, pint, psalm) without requiring architectural changes.
  • Non-Invasive: Operates at the file-level (not runtime), making it ideal for CI/CD pipelines, pre-commit hooks, or developer workflows. No impact on Laravel’s core logic or performance.
  • Rule Customization: Supports predefined rule sets (@PSR12, @Symfony, @PhpCsFixer) and custom configurations, allowing alignment with Laravel’s existing standards (e.g., Taylor Otwell’s conventions).
  • Modernization: Includes auto-migration rules for PHP 8.x features (e.g., named arguments, match expressions), which aligns with Laravel’s adoption of newer PHP versions.

Integration Feasibility

  • Composer-Based: Installs as a dev dependency, avoiding production bloat. Compatible with Laravel’s composer.json workflow.
  • CLI-Driven: Can be invoked via Artisan commands (custom) or directly in CI (e.g., GitHub Actions). Example:
    ./vendor/bin/php-cs-fixer fix src tests --rules=@PSR12 --dry-run
    
  • IDE Integration: Works with PhpStorm (native) and VS Code/Vim plugins, reducing friction for developers.
  • Git Hooks: Can be paired with pre-commit hooks (via husky or laravel-git) to enforce fixes before commits.

Technical Risk

  • False Positives/Negatives: Some rules (e.g., NoUnusedImports) may over-optimize or break legacy code. Requires testing in a staging environment before enforcing in CI.
  • Performance: Large codebases (e.g., Laravel + plugins) may experience slow execution in CI. Mitigation:
    • Cache results (.php-cs-fixer.cache).
    • Parallelize with --parallel flag.
    • Exclude vendor/ and generated files (e.g., bootstrap/cache).
  • Rule Conflicts: Custom Laravel conventions (e.g., @property-read) may conflict with PHP-CS-Fixer’s defaults. Solution: Extend the config to override specific rules.
  • PHP Version Support: Laravel 10+ uses PHP 8.1+. PHP-CS-Fixer supports 7.4–8.5, but unsupported versions (e.g., 8.6) require --allow-unsupported-php-version=yes (risky).

Key Questions

  1. Rule Set Alignment:
    • Does Laravel’s team have a standardized coding style guide? If so, should PHP-CS-Fixer mirror it exactly or allow flexibility?
    • Example: Should @Symfony rules be used, or a custom Laravel-specific ruleset?
  2. CI/CD Enforcement:
    • Should fixes be auto-applied in CI (breaking builds on failures) or only checked (with manual fixes)?
    • Example: GitHub Actions workflow:
      - name: PHP-CS-Fixer
        run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@PSR12
      
  3. Developer Adoption:
    • How will the team ramp up on PHP-CS-Fixer? Should there be a training session on common fixes?
    • Example: Document top 5 fixes (e.g., array_syntax, class_attributes) in the team wiki.
  4. Legacy Code:
    • How will legacy Laravel 5/6 code (if any) be handled? Should it be grandfathered or retroactively fixed?
  5. Tooling Stack:
    • Should PHP-CS-Fixer replace or complement existing tools like pint (PHP formatter) or psalm (static analysis)?
    • Example: Use pint for formatting and PHP-CS-Fixer for semantic fixes.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Composer: Native integration via composer require --dev friendsofphp/php-cs-fixer.
    • Artisan: Can be wrapped in a custom command (e.g., php artisan cs-fix) for consistency.
    • CI/CD: Works with Laravel Forge, Envoyer, or GitHub Actions out-of-the-box.
  • Toolchain Synergy:
    • Complementary to pint: Use pint for formatting (whitespace, indentation) and PHP-CS-Fixer for semantic fixes (e.g., @var to array type hints).
    • Static Analysis: Pair with psalm or phpstan to catch logical errors while PHP-CS-Fixer handles style.
    • Testing: Integrate with phpunit via --test flag to ensure fixes don’t break tests.

Migration Path

  1. Pilot Phase:
    • Install PHP-CS-Fixer in a non-critical branch (e.g., feature/cs-fixer).
    • Run ./vendor/bin/php-cs-fixer init to generate a baseline config (php-cs-fixer.php).
    • Customize rules to match Laravel’s standards (e.g., add @property-read support if needed).
  2. Incremental Rollout:
    • Start with check mode in CI to identify violations without auto-fixing.
    • Gradually introduce auto-fixing in PRs or local dev environments.
    • Example CI workflow:
      # Step 1: Check only (no auto-fix)
      - run: ./vendor/bin/php-cs-fixer check src --rules=@PSR12 --diff
      # Step 2: After 2 weeks, enable auto-fix
      - run: ./vendor/bin/php-cs-fixer fix src --rules=@PSR12
      
  3. Full Adoption:
    • Enforce in pre-commit hooks (e.g., via husky).
    • Add a CI job that blocks merges on failures.
    • Document the new workflow in the team’s CONTRIBUTING.md.

Compatibility

  • Laravel Versions:
    • Works with Laravel 5.8+ (PHP 7.2+). For older versions, use --allow-unsupported-php-version=yes cautiously.
    • Tested with Lumen and Laravel Forge deployments.
  • Dependency Conflicts:
    • Rare, but possible with other dev tools (e.g., rector). Use composer why-not to resolve.
    • Prefer php-cs-fixer/shim if conflicts arise.
  • IDE/Editor Support:
    • PhpStorm: Native integration (settings → Tools → PHP CS Fixer).
    • VS Code: Use the PHP CS Fixer extension.
    • CLI: Works with laravel-valet, docker, and homestead.

Sequencing

Phase Action Tools/Commands
Discovery Audit current codebase for violations. php-cs-fixer check --diff --rules=@PSR12
Configuration Customize php-cs-fixer.php to match Laravel’s standards. Edit config file; test with php-cs-fixer fix --dry-run
CI Integration Add to GitHub Actions/GitLab CI. Example: .github/workflows/php-cs-fixer.yml
Local Setup Configure IDEs and pre-commit hooks. PhpStorm/VS Code plugins + husky
Enforcement Block merges on failures; auto-fix in CI. php-cs-fixer fix --allow-risky=yes (for risky rules)
Maintenance Update rulesets annually (e.g., for PHP 8.3+ features). composer update friendsofphp/php-cs-fixer

Operational Impact

Maintenance

  • Configuration Drift:
    • Risk: Team members may override .php-cs-fixer.php locally, leading to inconsistencies.
    • Mitigation:
      • Store the config in version control (not .php-cs-fixer.dist.php).
      • Use php-cs-fixer fix --config=php-cs-fixer.php to enforce central config.
  • Rule Updates:
    • PHP-CS-Fixer releases monthly. New PHP versions
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky