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

coffreo/php-cs-fixer-config

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require --dev coffreo/php-cs-fixer-config
    

    Add the config to your project’s composer.json under "extra":

    "extra": {
        "coffreo-cs-fixer": {
            "rules": "@coffreo"
        }
    }
    
  2. First Use Case Run PHP-CS-Fixer with Coffreo’s preset:

    vendor/bin/php-cs-fixer fix --rules=@coffreo
    

    Or integrate it into your php-cs-fixer.dist.php:

    return (new PhpCsFixer\Config())
        ->setRules([
            '@coffreo' => true,
        ]);
    
  3. Where to Look First

    • Check the PHP-CS-Fixer docs for rule explanations.
    • Review the preset’s rules via:
      vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@coffreo
      

Implementation Patterns

Usage Patterns

  1. Team-Wide Enforcement Commit the preset to version control (e.g., php-cs-fixer.dist.php) to ensure consistency across the team. Example:

    return (new PhpCsFixer\Config())
        ->setRules([
            '@coffreo' => true,
            'risky' => false, // Disable risky rules if needed
        ]);
    
  2. CI/CD Integration Add a GitHub Actions step (or equivalent) to auto-fix on push:

    - name: Fix CS
      run: vendor/bin/php-cs-fixer fix --rules=@coffreo --allow-risky=yes
    
  3. Customizing the Preset Override specific rules while keeping Coffreo’s base:

    return (new PhpCsFixer\Config())
        ->setRules([
            '@coffreo' => true,
            'phpdoc_align' => false, // Disable a Coffreo rule
            'array_syntax' => ['syntax' => 'short'], // Customize a rule
        ]);
    
  4. Pre-Commit Hooks Use php-cs-fixer with tools like Husky or Pre-commit:

    composer require --dev php-cs-fixer
    echo "vendor/bin/php-cs-fixer fix --rules=@coffreo --dry-run" >> .git/hooks/pre-commit
    

Workflows

  • Onboarding: Run php-cs-fixer fix once during setup to align existing code.
  • Daily Work: Use --dry-run to preview changes before committing:
    vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@coffreo
    
  • Pull Requests: Require CS compliance via CI (e.g., fail if fixes are needed).

Integration Tips

  • Laravel-Specific: Combine with laravel-pint (if using) by running both tools in CI.
  • IDE Support: Configure your IDE (PHPStorm/VSCode) to use Coffreo’s rules for real-time feedback. Example (PHPStorm):
    {
      "php": {
        "codeSnifferConfig": "vendor/bin/php-cs-fixer",
        "codeSnifferRules": "@coffreo"
      }
    }
    

Gotchas and Tips

Pitfalls

  1. Outdated Preset The package hasn’t been updated since 2020. Verify rules align with modern PHP-CS-Fixer (v3.x+).

    • Fix: Manually audit rules or fork the preset to update it.
  2. Risky Rules Coffreo’s preset may include @Risky rules (e.g., no_unused_imports). Disable them if strictness is undesired:

    ->setRules([
        '@coffreo' => true,
        'risky' => false,
    ]);
    
  3. Path Configuration If running in a monorepo or custom directory structure, specify paths explicitly:

    vendor/bin/php-cs-fixer fix --rules=@coffreo --path-mode=intersection --path="src/"
    
  4. Caching Issues Clear PHP-CS-Fixer’s cache if rules seem ignored:

    vendor/bin/php-cs-fixer cache-clear
    

Debugging

  • Rule Conflicts: Use --verbose to debug rule application:
    vendor/bin/php-cs-fixer fix --verbose --rules=@coffreo
    
  • Dry Runs: Always test with --dry-run before committing fixes:
    vendor/bin/php-cs-fixer fix --dry-run --diff
    

Config Quirks

  • Composer Extra Key: The preset relies on the extra.coffreo-cs-fixer key. If missing, define it explicitly in php-cs-fixer.dist.php:
    ->setRules([
        '@coffreo' => true,
        // Fallback if key is missing
        'array_syntax' => ['syntax' => 'short'],
    ]);
    

Extension Points

  1. Custom Preset Extend Coffreo’s rules by creating a new preset file (e.g., cs-fixer.php):

    return (new PhpCsFixer\Config())
        ->setRules([
            '@coffreo' => true,
            'no_unused_imports' => true,
            'ordered_imports' => ['sort_algorithm' => 'alpha'],
        ]);
    
  2. Dynamic Rule Loading Load rules dynamically from a config file:

    $rules = require __DIR__ . '/cs-fixer-rules.php';
    return (new PhpCsFixer\Config())->setRules($rules);
    
  3. Parallel Processing Speed up large codebases with parallel fixes:

    vendor/bin/php-cs-fixer fix --parallel --rules=@coffreo
    
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.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields
splash/sonata-admin
splash/metadata