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 Config Laravel Package

eliashaeussler/php-cs-fixer-config

Reusable PHP-CS-Fixer config package by Elias Häussler. Provides a ready-to-use ruleset and sensible defaults to keep PHP code style consistent across projects, with easy installation and quick integration into existing fixer setups.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Require the package in your project via Composer:
    composer require --dev eliashaeussler/php-cs-fixer-config
    
  2. Create or update .php-cs-fixer.php in your project root to import the config:
    <?php
    
    use Eliashaeussler\PhpCsFixerConfig\Config;
    
    return (new Config())
        ->setRiskyAllowed(true)
        ->setFinder(
            PhpCsFixer\Finder::create()
                ->in(__DIR__)
                ->name('*.php')
                ->ignoreDotFiles(true)
                ->ignoreVCS(true)
        );
    
  3. Run the fixer:
    ./vendor/bin/php-cs-fixer fix
    
  4. (Optional) Integrate with CI to fail builds on style violations using --dry-run and --diff.

💡 First use case: Enforce consistent formatting across a new Laravel app without manually configuring rules — just install and run.

Implementation Patterns

  • Centralized Standard: Add this as a dev dependency in a shared internal Composer repository or monorepo root (e.g., via composer require --dev your-org/standard-config). All child projects inherit the same style rules.

  • Project-Level Customization: Extend or override rules in your .php-cs-fixer.php:

    $config = new Config();
    $config->setRules([
        'class_attributes_separation' => true,
        'multiline_whitespace_before_semicolons' => false, // disable risky rule
        'native_function_invocation' => ['include' => ['@all']],
    ]);
    return $config;
    
  • CI Integration: Use in GitHub Actions/GitLab CI:

    - name: Run PHP-CS-Fixer
      run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
    
  • Pre-commit Hook: Combine with husky or git hooks to auto-fix on commit:

    vendor/bin/php-cs-fixer fix --allow-risky=yes
    

Gotchas and Tips

  • setRiskyAllowed(true) is required for many modern rules (e.g., native_function_invocation) — don’t forget this if fixes don’t apply.

  • Rule conflicts: If you override rules, check for overlaps (e.g., php_unit_strict may conflict with strict in general). Use ./vendor/bin/php-cs-fixer describe <rule> to inspect behavior.

  • Version locking: Pin the package version ("eliashaeussler/php-cs-fixer-config": "^1.2") to avoid unexpected style changes from updates — use patch versions for safety.

  • Performance tip: Use Finder with notPath() to exclude vendor, cache, and generated dirs:

    ->notPath('bootstrap/cache')
    ->notPath('storage')
    
  • Debugging fix issues: Run with --using-cache=no and --stop-on-violation to pinpoint which file(s) break the build.

  • Extensibility: You can subclass Config and override methods like getRules() if you need complex, dynamic rule composition across contexts (e.g., Laravel vs. API-only).

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