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

phpyh/coding-standard

Opinionated PHP coding standard for Laravel projects, built on PHP-CS-Fixer with ready-to-use rules, presets, and a simple CLI/workflow to automatically format code and keep style consistent across your team and CI.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require --dev phpyh/coding-standard
    

    Register the provider in config/app.php (if not auto-discovered):

    'providers' => [
        Phpyh\CodingStandard\CodingStandardServiceProvider::class,
    ],
    
  2. Basic Usage Run the coding standard checker via Artisan:

    php artisan coding-standard:check
    

    This scans your project for violations against predefined rules (e.g., PSR-12, custom Laravel conventions).

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

    - name: Run Coding Standard
      run: php artisan coding-standard:check --fix
    

Implementation Patterns

Workflow Integration

  1. Pre-Commit Hooks Use husky or Laravel’s pre-commit to run checks before commits:

    php artisan coding-standard:check --format=json > coding-standard.json
    

    Add a Git hook to fail if violations exist.

  2. IDE Integration Configure PHPStorm to use the coding standard:

    • Go to Settings > Editor > Code Style > PHP.
    • Import the package’s .php_cs or .php_cs.dist file (if provided).
  3. Custom Rules Extend the default rules by publishing the config:

    php artisan vendor:publish --provider="Phpyh\CodingStandard\CodingStandardServiceProvider" --tag="config"
    

    Modify config/coding-standard.php to add/override rules (e.g., line length, namespace prefixes).

  4. Automated Fixes Use the --fix flag to auto-correct fixable issues:

    php artisan coding-standard:check --fix
    
  5. Parallel Processing For large codebases, leverage parallel checks with --parallel (if supported):

    php artisan coding-standard:check --parallel=4
    

Gotchas and Tips

Pitfalls

  1. False Positives

    • Custom namespace prefixes (e.g., App\Services\) may trigger unnecessary warnings. Override in config:
      'rules' => [
          'namespaces' => [
              'prefix' => 'App\\',
              'validate_root_namespace' => false,
          ],
      ],
      
  2. Performance

    • Excluding directories (e.g., vendor/, storage/) improves speed:
      php artisan coding-standard:check --exclude="vendor,storage"
      
  3. Config Overrides

    • Ensure config is published before modifying. Unpublished changes reset on updates.
  4. PHP Version Compatibility

    • Test with your project’s PHP version (e.g., 8.1). Some rules may behave differently across versions.

Debugging

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

    php artisan coding-standard:check --verbose
    
  • JSON Output For CI integration, parse JSON output:

    php artisan coding-standard:check --format=json > report.json
    

Extension Points

  1. Custom Rulesets Create a ruleset.xml (if supported) or extend the Rule classes in app/Rules:

    namespace App\Rules;
    use Phpyh\CodingStandard\Rules\AbstractRule;
    
    class CustomRule extends AbstractRule {
        protected function getPattern() { return '...'; }
        protected function getFix() { return '...'; }
    }
    
  2. Event Listeners Hook into coding-standard.checked events to log or notify:

    CodingStandard::addListener(function ($violations) {
        Log::info('Coding standard violations:', $violations);
    });
    
  3. Integration with PHP-CS-Fixer If the package uses UnderlyingPHP/PhpCsFixer, leverage its .php-cs-fixer.dist.php for advanced configs.

Pro Tips

  • Dry Runs Use --dry-run to preview changes before applying fixes:

    php artisan coding-standard:check --fix --dry-run
    
  • Team Onboarding Include a CODING_STANDARD.md in your repo with:

    • Example violations.
    • How to run checks locally.
    • Common exceptions.
  • Partial Checks Target specific files/directories:

    php artisan coding-standard:check app/Http/Controllers
    
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