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

Coding Standard Laravel Package

woohoolabs/coding-standard

Woohoo Labs PHP Coding Standard for PHP_CodeSniffer, based on PSR-12 and inspired by Doctrine and Slevomat rules. Install via Composer and drop in the provided phpcs.xml to start enforcing consistent code style (PHP 7.4+).

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require --dev woohoolabs/coding-standard
    

    Update composer.json under require-dev to reflect the new dependency version:

    "extra": {
        "coding-standard": {
            "ruleset": "woohoolabs"
        }
    }
    
  2. First Run Integrate with PHP-CS-Fixer (now aligned with slevomat/coding-standard v8):

    composer require --dev friendsofphp/php-cs-fixer
    vendor/bin/php-cs-fixer fix --rules=@woohoolabs --dry-run
    
  3. First Use Case Use as a pre-commit hook (via php-cs-fixer) or in CI (e.g., GitHub Actions):

    # .github/workflows/php-cs.yml
    - name: PHP Coding Standard
      run: vendor/bin/php-cs-fixer fix --rules=@woohoolabs --allow-risky=yes
    

Implementation Patterns

Workflows

  1. Local Development

    • Run interactively with --diff to preview changes:
      vendor/bin/php-cs-fixer fix --rules=@woohoolabs --diff
      
    • Use --dry-run to check without modifying files.
  2. CI/CD Integration

    • Fail builds on violations (strict mode):
      vendor/bin/php-cs-fixer fix --rules=@woohoolabs --allow-risky=yes --stop-on-violation
      
    • Cache results for faster runs (e.g., GitHub Actions cache).
  3. Customization

    • Extend the ruleset in .php-cs-fixer.dist.php (now compatible with slevomat/coding-standard v8):
      return (new PhpCsFixer\Config())
          ->setRules([
              '@woohoolabs' => true,
              'no_unused_imports' => true, // Add custom rules
          ]);
      

Laravel-Specific Tips

  • Artisan Integration Create a custom command to enforce standards:

    php artisan make:command FixCodingStandard
    
    // app/Console/Commands/FixCodingStandard.php
    public function handle() {
        $this->call('php-cs-fixer', ['--rules=@woohoolabs']);
    }
    

    Register in app/Console/Kernel.php:

    protected $commands = [
        \App\Console\Commands\FixCodingStandard::class,
    ];
    
  • IDE Support Configure your IDE (PHPStorm/VSCode) to use the updated ruleset:

    // .vscode/settings.json
    "php-cs-fixer.executablePath": "vendor/bin/php-cs-fixer",
    "php-cs-fixer.rules": "@woohoolabs"
    

Gotchas and Tips

Pitfalls

  1. Rule Conflicts

    • slevomat/coding-standard v8 may introduce stricter defaults. Override in .php-cs-fixer.dist.php:
      'array_syntax' => ['syntax' => 'short'],
      'no_unused_private_properties' => ['ignore_unused_defined_properties' => true],
      
  2. Performance

    • Large codebases may slow down php-cs-fixer. Use --parallel:
      vendor/bin/php-cs-fixer fix --rules=@woohoolabs --parallel
      
  3. Deprecated Rules

    • Some legacy rules may no longer apply. Verify compatibility with:
      vendor/bin/php-cs-fixer fix --rules=@woohoolabs --dry-run --verbose
      

Debugging

  • Verbose Output Use --verbose to diagnose rule application:

    vendor/bin/php-cs-fixer fix --rules=@woohoolabs --verbose
    
  • Rule Isolation Test individual rules:

    vendor/bin/php-cs-fixer fix --rules=@woohoolabs --only=@woohoolabs\type_declaration
    

Extension Points

  1. Custom Rules Extend the ruleset by creating a new rule file (e.g., ruleset/laravel.php):

    return [
        '@woohoolabs' => true,
        'no_unused_imports' => true,
        'native_function_invocation' => ['include' => ['@'], 'scope' => 'all'],
    ];
    

    Reference it in composer.json:

    "extra": {
        "coding-standard": {
            "ruleset": "ruleset/laravel"
        }
    }
    
  2. Git Hooks Automate enforcement via pre-commit:

    composer require --dev laravel/git-hooks
    vendor/bin/git-hooks install
    

    Configure in .git/hooks/pre-commit:

    #!/bin/sh
    vendor/bin/php-cs-fixer fix --rules=@woohoolabs --allow-risky=yes --stop-on-violation
    
  3. Documentation

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor