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

lookyman/coding-standard

Opinionated PHP coding standard package for your projects. Install via Composer and reference the bundled ruleset.xml in PHP_CodeSniffer to enforce consistent formatting and style, with room to add your own project-specific rules.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require --dev lookyman/coding-standard
    

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

    'providers' => [
        Lookyman\CodingStandard\CodingStandardServiceProvider::class,
    ],
    
  2. Configuration Publish the config file:

    php artisan vendor:publish --provider="Lookyman\CodingStandard\CodingStandardServiceProvider"
    

    Edit config/coding-standard.php to define your ruleset (e.g., PSR-12, custom rules).

  3. First Use Case Run the coding standard checker on a single file:

    php artisan coding-standard:check app/Http/Controllers/ExampleController.php
    

    Or check an entire directory (e.g., app/):

    php artisan coding-standard:check app/
    
  4. Integrate with CI Add to your .gitlab-ci.yml or Travis.yml:

    script:
      - php artisan coding-standard:check app/
    

Implementation Patterns

Workflows

  1. Pre-Commit Hooks Use php artisan coding-standard:check in a pre-commit hook (e.g., via husky or pre-commit) to catch violations early:

    # .git/hooks/pre-commit
    #!/bin/sh
    php artisan coding-standard:check --fix
    
  2. Fixing Issues Automatically Enable auto-fixing where possible:

    php artisan coding-standard:check --fix app/
    

    (Note: Only applies to rules supporting fixes, e.g., indentation, spacing.)

  3. Custom Rulesets Extend the default ruleset by creating a custom config:

    // config/coding-standard.php
    'rules' => [
        'PSR12' => true,
        'custom' => [
            'Lookyman\CodingStandard\Rules\NoHardTabs' => true,
        ],
    ],
    
  4. Integration with PHPStan/PHPMD Combine with other tools for deeper analysis:

    php artisan coding-standard:check app/ && vendor/bin/phpstan analyse app/
    
  5. Parallel Processing For large codebases, split checks across files/directories:

    find app/ -name "*.php" | xargs -P 4 php artisan coding-standard:check
    

Integration Tips

  1. Laravel IDE Helper Run checks before generating IDE helpers:

    php artisan coding-standard:check app/ && vendor/bin/ide-helper:generate
    
  2. Custom Artisan Commands Extend the package’s commands in app/Console/Commands:

    use Lookyman\CodingStandard\Commands\CheckCommand;
    
    class CustomCheckCommand extends CheckCommand {
        protected $signature = 'custom:check {path}';
        // Override logic as needed
    }
    
  3. GitHub Actions Cache Composer dependencies for faster CI runs:

    jobs:
      coding-standard:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-php@v2
          - run: composer install
          - run: php artisan coding-standard:check app/
    
  4. Visual Studio Code Integration Use the PHP Intelephense extension to highlight violations in real-time (requires manual rule mapping).


Gotchas and Tips

Pitfalls

  1. Outdated Package

    • Last release was 2018; expect missing features (e.g., PHP 8.x support, modern PSR standards).
    • Workaround: Fork the repo and update dependencies (e.g., php-cs-fixer to v3.x).
  2. No Auto-Discovery

    • The service provider may not auto-register in newer Laravel versions.
    • Fix: Manually add to config/app.php or use a package like laravel-package-discovery.
  3. Limited Rule Support

    • Only basic PSR-1/PSR-2 rules are included. For PSR-12 or custom rules, extend via:
      // config/coding-standard.php
      'rules' => [
          'PSR12' => [
              'rules' => [
                  '@PSR12' => true,
                  'no_unused_imports' => true,
              ],
          ],
      ],
      
    • Tip: Use php-cs-fixer directly if advanced rules are needed.
  4. Performance on Large Codebases

    • Checks can be slow for monorepos. Optimize by:
      • Excluding vendor/ and node_modules/ in .gitignore.
      • Running in parallel (see Implementation Patterns).
  5. False Positives

    • Custom frameworks or legacy code may trigger unnecessary warnings.
    • Solution: Whitelist files/directories in config:
      'exclude' => [
          'app/Legacy/',
          'config/custom.php',
      ],
      

Debugging

  1. Verbose Output Enable debug mode for detailed errors:

    php artisan coding-standard:check --verbose app/
    
  2. Dry Run Test changes without fixing:

    php artisan coding-standard:check --dry-run app/
    
  3. Rule-Specific Checks Isolate rule violations:

    php artisan coding-standard:check --rule=PSR12 app/
    

Extension Points

  1. Custom Rules Create a new rule by extending Lookyman\CodingStandard\AbstractRule:

    namespace App\Rules;
    
    use Lookyman\CodingStandard\AbstractRule;
    
    class CustomRule extends AbstractRule {
        public function getName() { return 'custom_rule'; }
        public function process(\PhpParser\Node $node) { /* ... */ }
    }
    

    Register in config/coding-standard.php:

    'rules' => [
        'custom_rule' => App\Rules\CustomRule::class,
    ],
    
  2. Override Default Rules Disable/enable rules dynamically:

    // In a command or service
    $checker = app('coding-standard');
    $checker->disableRule('PSR12');
    $checker->enableRule('no_hard_tabs');
    
  3. Event Listeners Listen for check events (e.g., to log violations):

    // app/Providers/EventServiceProvider.php
    protected $listen = [
        'coding-standard.violations' => [
            \App\Listeners\LogViolations::class,
        ],
    ];
    

Config Quirks

  1. Path Handling

    • Use absolute paths in config/coding-standard.php for reliability:
      'paths' => [
          base_path('app'),
          base_path('config'),
      ],
      
  2. Case Sensitivity

    • Rule names are case-sensitive. Use the exact key from the config.
  3. Caching

    • The package doesn’t cache results by default. For CI, cache vendor/ to speed up runs:
      # .gitlab-ci.yml
      cache:
        key: ${CI_COMMIT_REF_SLUG}
        paths:
          - vendor/
      
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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