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 Codesniffer Sniffs Laravel Package

moxio/php-codesniffer-sniffs

Custom PHP_CodeSniffer 3.x sniffs from Moxio to catch subtle PHP bugs and unexpected behavior. Provides a standalone ruleset or individual sniffs for other standards, enforcing safer comparisons, strict base64_decode, switch continue rules, and more.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require --dev moxio/php-codesniffer-sniffs
    

    Add the custom sniffs to your phpcs.xml or phpcs.xml.dist:

    <config name="installed_paths" value="./vendor/moxio/php-codesniffer-sniffs"/>
    
  2. First Use Case Run PHP_CodeSniffer on a Laravel project:

    ./vendor/bin/phpcs -p --standard=PSR12,CustomSniffs app/
    

    Verify the custom rules are applied by checking for violations in the output.

    Note for slevomat/coding-standard users: If using slevomat/coding-standard (v8.26.0 or lower), ensure compatibility by installing both packages:

    composer require --dev slevomat/coding-standard:^8.0 moxio/php-codesniffer-sniffs
    

Implementation Patterns

Workflow Integration

  • Pre-Commit Hooks Use with tools like php-cs-fixer or Git hooks to enforce sniffs before merging:

    composer require --dev dealerdirect/phpcodesniffer-composer-installer
    

    Configure in composer.json:

    "scripts": {
      "cs-check": "phpcs -p --standard=PSR12,CustomSniffs app/"
    }
    
  • CI/CD Pipeline Add to Laravel CI (e.g., GitHub Actions):

    - name: Run PHP_CodeSniffer
      run: ./vendor/bin/phpcs -p --standard=PSR12,CustomSniffs app/ --warning-severity=0
    
  • Custom Rule Targeting Focus sniffs on Laravel-specific files (e.g., app/Providers/*, app/Http/Controllers/*):

    ./vendor/bin/phpcs -p --standard=CustomSniffs app/Providers/
    

slevomat/coding-standard Integration

  • Hybrid Setup Combine with slevomat/coding-standard (v8.26.0 or lower) for advanced static analysis:

    ./vendor/bin/phpcs --standard=PSR12,CustomSniffs,SlevomatCodingStandard app/
    

    Configure in phpcs.xml:

    <config name="standard" value="PSR12"/>
    <config name="installed_paths" value="./vendor/moxio/php-codesniffer-sniffs,./vendor/slevomat/coding-standard/Sniffs"/>
    
  • Rule Prioritization Override or merge rules between the two standards:

    <rule ref="CustomSniffs.LaravelSniff" severity="error"/>
    <rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint" severity="warning"/>
    

Gotchas and Tips

Pitfalls

  • Rule Conflicts Some sniffs may conflict with PSR12, slevomat/coding-standard, or other standards. Test incrementally:

    ./vendor/bin/phpcs --sniffs=CustomSniffs.SpecificSniff app/
    
  • Performance Large codebases may slow down. Exclude tests or generated files:

    ./vendor/bin/phpcs -p --ignore=tests/,storage/ app/
    
  • False Positives Laravel’s dynamic methods (e.g., route('name')) may trigger false alarms. Whitelist or adjust severity:

    <exclude-pattern>*/routes/web.php</exclude-pattern>
    
  • slevomat Compatibility Ensure slevomat/coding-standard is v8.26.0 or lower to avoid breaking changes. Check for updates:

    composer show slevomat/coding-standard
    

Debugging

  • Verbose Output Use -v to debug sniff application:

    ./vendor/bin/phpcs -p -v --standard=CustomSniffs,SlevomatCodingStandard app/
    
  • Sniff Isolation Test individual sniffs or standards separately:

    ./vendor/bin/phpcs --sniffs=CustomSniffs.LaravelSniff app/
    ./vendor/bin/phpcs --standard=SlevomatCodingStandard app/
    

Extension Points

  • Custom Sniffs Extend the package by adding new sniffs to ./vendor/moxio/php-codesniffer-sniffs/Sniffs/.

  • Severity Tuning Adjust severity per file type (e.g., stricter for app/):

    <file>app/</file>
    <rule ref="CustomSniffs.SniffName" severity="error" />
    
  • Integration with IDE Configure PHPStorm to use the same rules via Settings > PHP > Code Sniffer.

  • slevomat Extensions Leverage slevomat/coding-standard extensions (e.g., slevomat/coding-standard:TypeHints) alongside custom sniffs for enhanced analysis.

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