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 Code Style Laravel Package

jakub-onderka/php-code-style

A PHP coding style toolkit for consistent formatting and style enforcement across projects. Helps standardize code layout and conventions, making reviews easier and reducing style-related noise in diffs for teams and CI pipelines.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require --dev jakub-onderka/php-code-style
    

    Register the service provider in config/app.php under providers:

    JakubOnderka\PHPCodeStyle\PHPCodeStyleServiceProvider::class,
    
  2. Basic Usage Run the fixer directly via Artisan:

    php artisan code-style:fix
    

    This will process files in app/ by default (check config/code-style.php for paths).

  3. First Use Case Integrate into your CI pipeline (e.g., GitHub Actions) to enforce style consistency before merges:

    - name: Run PHP Code Style Fixer
      run: php artisan code-style:fix --dry-run
    

Implementation Patterns

Workflow Integration

  1. Pre-Commit Hook Use husky or Laravel’s pre-commit to run the fixer automatically:

    php artisan code-style:fix --path=app/Http/Controllers
    

    Tip: Cache results with --cache for faster repeated runs.

  2. Custom Rules Extend the default rules (e.g., PSR-2) by publishing the config:

    php artisan vendor:publish --provider="JakubOnderka\PHPCodeStyle\PHPCodeStyleServiceProvider" --tag="config"
    

    Modify config/code-style.php to include additional rules (e.g., SquizLabs_PHP_CodeSniffer).

  3. Parallel Processing For large codebases, leverage Laravel’s queues to process files in parallel:

    // In a custom Artisan command
    $files = File::allFiles(app_path());
    foreach ($files as $file) {
        FixFiles::dispatch($file->getPathname());
    }
    
  4. IDE Integration Use php-cs-fixer (a modern fork) as a fallback if this package lacks features. Sync configs between tools:

    php artisan code-style:config:export --format=php-cs-fixer
    

Gotchas and Tips

Pitfalls

  1. Outdated Rules The package is unmaintained (last release: 2014). Prioritize:

    • Alternatives: Use php-cs-fixer (active maintenance).
    • Migration: Export configs and switch incrementally:
      php artisan code-style:config:export --format=php-cs-fixer > .php-cs-fixer.dist.php
      
  2. Performance Issues

    • Large Projects: Disable --diff and --verbose for faster runs.
    • Memory Limits: Increase PHP’s memory_limit if processing many files:
      memory_limit = 2G
      
  3. Config Overrides

    • Global vs. Local: Local .php-codestyle files override global settings. Document this in your team’s style guide.

Debugging

  1. Dry Runs Always use --dry-run first to preview changes:

    php artisan code-style:fix --dry-run --diff
    
  2. Excluded Files Use .php-codestyle-exclude to skip tests or generated files:

    /tests/
    /storage/
    
  3. Custom Rules Debugging Enable verbose output to trace rule failures:

    php artisan code-style:fix --verbose
    

Extension Points

  1. Custom Rulesets Create a Ruleset class to combine multiple standards:

    use JakubOnderka\PHPCodeStyle\Ruleset;
    
    class CustomRuleset extends Ruleset {
        protected $rules = [
            '@PSR2',
            'SquizLabs_PHP_CodeSniffer.Sniffs.WhiteSpace.SpaceAfterCastSniff',
        ];
    }
    
  2. Event Listeners Hook into the code-style.fixed event to log or notify:

    // In EventServiceProvider
    protected $listen = [
        'code-style.fixed' => [
            \App\Listeners\LogCodeStyleFix::class,
        ],
    ];
    
  3. Parallel Processing Override the FixFiles command to implement chunked processing:

    public function handle() {
        $files = File::allFiles(app_path())->chunk(100);
        foreach ($files as $chunk) {
            FixFiles::dispatch($chunk);
        }
    }
    
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