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 Custom Fixers Laravel Package

erickskrauch/php-cs-fixer-custom-fixers

Custom PHP-CS-Fixer fixers by Erick Skrauch. Adds opinionated formatting rules like aligning multiline parameters, inserting blank lines around class bodies and before returns, spacing after control statements, fixing multiline if braces, ordering overrides, and Yii2 ::className() replacement.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer:
    composer require --dev erickskrauch/php-cs-fixer-custom-fixers
  2. Require PHP CS Fixer (v3+) as a dev dependency if not already present:
    composer require --dev friendsofphp/php-cs-fixer
  3. Register the custom fixers in your .php-cs-fixer.php config file:
    $finder = PhpCsFixer\Finder::create()
        ->in(__DIR__);
    
    return (new PhpCsFixer\Config())
        ->setRules([
            // your existing rules...
        ])
        ->setFinder($finder)
        ->setCustomFixers([new \ErickSkrauch\PhpCsFixer\CustomFixers\Fixer\ClassOrderFixer()]);
    
    Note: You must explicitly instantiate and register each fixer you want to use—no auto-discovery.

Implementation Patterns

  • Minimal configuration: Start with 1–2 fixers relevant to your team’s pain points (e.g., NoDuplicateProperty.php, ClassOrderFixer, ExplicitPublicMethodFixer) and gradually add more as conventions evolve.
  • CI integration: Include a formatting check in your pipeline (e.g., ./vendor/bin/php-cs-fixer fix --dry-run) to fail builds if custom rules are violated.
  • Pre-commit hooks: Use husky + lint-staged (in JS stacks) or pre-commit (in Python/Go toolchains) to run php-cs-fixer fix on staged PHP files only.
  • Team consistency: Share your .php-cs-fixer.php config in the repo, and document added fixers in CONTRIBUTING.md to avoid confusion.

Gotchas and Tips

  • Fixer instantiation is manual: Unlike some plugins, this package doesn’t expose a factory or config-based discovery—each fixer must be manually new’d and added to setCustomFixers().
  • Rule conflicts: Custom fixers may clash with built-in or third-party rules (e.g., two fixers reordering properties or methods). Use --dry-run and --diff during initial rollout to audit changes.
  • Order matters: Fixers run in the order registered. If multiple fixers affect the same token(s), stack order can cause unpredictable results—group logically related fixers together.
  • Debugging: Set XDEBUG_MODE=off before running to avoid performance penalties; custom fixers can be slow if they use heavy regex or AST traversal.
  • Extensibility: The package is small (≈3k SLOC), well-structured, and open for extension—copy and tweak a fixer to build project-specific rules. Look in src/Fixer/ for baseline examples.
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