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

lcobucci/coding-standard

lcobucci/coding-standard provides a PHP_CodeSniffer ruleset based on Doctrine’s coding standard, with a few tweaks. Use it to enforce consistent code style and best practices across PHP projects via phpcs in CI and local development.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package into require-dev:

composer require --dev lcobucci/coding-standard

Then create a phpcs.xml in your project root to inherit its ruleset:

<?xml version="1.0"?>
<ruleset name="MyLaravelAppCS">
    <file>app</file>
    <file>src</file>
    <file>tests</file>
    <rule ref="Lcobucci"/>
</ruleset>

Run initial checks with:

vendor/bin/phpcs

The first day-to-day use case is verifying PSR-12 compliance plus Laravel/Doctrine-specific rules (e.g., strict array syntax, consistent attribute formatting) without reinventing PHPCS setup.

Implementation Patterns

  • CI Integration: Add a fast lint step to GitHub Actions/GitLab CI before tests:
    - name: Check code style
      run: vendor/bin/phpcs --warning-severity=0
    
  • VS Code Live Feedback: Install the PHP CS Fixer or PHPCS extension, point it to phpcs.xml, and enable phpcs.executablePath.
  • Pre-commit Linting: Use lint-staged to run only on staged files (avoids full-project slowness):
    {
      "lint-staged": {
        "*.php": "vendor/bin/phpcs --standard=Lcobucci"
      }
    }
    
  • Gradual Migration: Exclude legacy code with !--file> or <exclude-pattern> in phpcs.xml, then progressively remove exclusions as you refactor.
  • Laravel-Specific Overrides: Extend the standard for framework conventions (e.g., permit App\ without leading backslash):
    <rule ref="PSR12.Files.FileHeader.IncorrectOrder">
        <exclude-pattern>app/Models/*.php</exclude-pattern>
    </rule>
    

Gotchas and Tips

  • PHP Version Lock: v11.x requires ≥PHP 8.1; v10.x ≥8.2. Mismatched PHP CLI versions cause silent errors—always check php -v before running phpcs.
  • False Positives with PHP 8.2+ Attributes: If using #[ReadOnly] or custom attributes, ensure you’re on ≥v10 (which uses Doctrine CS v11+). Older versions incorrectly flag attribute syntax.
  • Cache Confusion: phpcs caches results aggressively. After changing phpcs.xml or upgrading the package, run with --no-cache.
  • Auto-fix Gap: Unlike symplify/easy-coding-standard, this package does not ship auto-fix rules—run phpcbf manually:
    vendor/bin/phpcbf --standard=Lcobucci
    
  • Debugging Violations: Use -s to identify the underlying sniff (e.g., Lcobucci.Arrays.ArrayDeclaration.SpaceBeforeDoubleArrow) and cross-reference with Doctrine CS docs.
  • Minimize Dependency Noise: Avoid installing alongside squizlabs/php_codesniffer globally—use only the project-local PHPCS installed by this package.
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