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

phootwork/php-cs-fixer-config

Reusable PHP-CS-Fixer configuration by phootwork. Provides a shared ruleset and presets to standardize code style across projects, making it easy to apply consistent formatting in CI and local development with minimal setup.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer:
    composer require --dev phootwork/php-cs-fixer-config
    
  2. Create a .php-cs-fixer.dist.php config file in your project root that extends the provided config:
    <?php
    
    use Phootwork\CSFixer\Config;
    
    return Config::create()
        ->setRiskyAllowed(true)
        ->setFinder(Config::createFinder(__DIR__));
    
  3. Run PHP CS Fixer to verify it works:
    vendor/bin/php-cs-fixer fix --dry-run
    

💡 Start with Config::create() — it loads the shared, opinionated ruleset from the package. You don’t need to copy rules manually.

Implementation Patterns

  • Base config for monorepos/multi-project orgs: Include it as a dev dependency across repos to enforce uniform formatting. Update once in the package, pull into all projects via Composer.
  • Project-specific overrides: Extend the base config and add, remove, or tweak rules:
    return Config::create()
        ->setRules([
            '@PSR12' => true,
            'single_import_per_statement' => false, // override base rule
            'ordered_imports' => ['sort_algorithm' => 'length'],
        ]);
    
  • CI integration: Reference the config in your CI workflow to run checks consistently:
    - vendor/bin/php-cs-fixer check --config=.php-cs-fixer.dist.php
    
  • IDE sync: Configure your IDE (e.g., PhpStorm, VS Code) to use the project’s .php-cs-fixer.dist.php as the source of truth for auto-formatting.

Gotchas and Tips

  • ⚠️ Config::createFinder() only scans src/ and tests/ by default. Extend it if you have other directories:
    ->setFinder(Config::createFinder(__DIR__)->in(['src', 'tests', 'bin']));
    
  • 🔁 Risky rules are disabled by default. Call setRiskyAllowed(true) if you want rules like @PHP80Migration or yoda_style. Ignoring this may cause "no fixes applied" surprises.
  • 🧩 Overrides must be chained or merged carefully: PHP CS Fixer’s ruleset merges left-to-right, so later calls in setRules() override earlier ones. Always test overrides in dry-run mode first.
  • 🔄 Update strategy: Pin the package version (e.g., ^2.0) to avoid unexpected formatting shifts on minor updates. Review changelogs before upgrading.
  • 📁 Caching: Enable caching (->setCacheFile(__DIR__.'/.php-cs-fixer.cache)`) for faster repeated runs in local/dev environments.
  • 🌐 PHP version support: The config targets modern PHP versions (7.4+). If supporting legacy PHP (e.g., 7.2), you’ll need to selectively relax rules (e.g., no_alias_functions, strict_comparison).
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
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
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests