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.
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.
- name: Check code style
run: vendor/bin/phpcs --warning-severity=0
phpcs.xml, and enable phpcs.executablePath.lint-staged to run only on staged files (avoids full-project slowness):
{
"lint-staged": {
"*.php": "vendor/bin/phpcs --standard=Lcobucci"
}
}
!--file> or <exclude-pattern> in phpcs.xml, then progressively remove exclusions as you refactor.App\ without leading backslash):
<rule ref="PSR12.Files.FileHeader.IncorrectOrder">
<exclude-pattern>app/Models/*.php</exclude-pattern>
</rule>
php -v before running phpcs.#[ReadOnly] or custom attributes, ensure you’re on ≥v10 (which uses Doctrine CS v11+). Older versions incorrectly flag attribute syntax.phpcs caches results aggressively. After changing phpcs.xml or upgrading the package, run with --no-cache.symplify/easy-coding-standard, this package does not ship auto-fix rules—run phpcbf manually:
vendor/bin/phpcbf --standard=Lcobucci
-s to identify the underlying sniff (e.g., Lcobucci.Arrays.ArrayDeclaration.SpaceBeforeDoubleArrow) and cross-reference with Doctrine CS docs.squizlabs/php_codesniffer globally—use only the project-local PHPCS installed by this package.How can I help you explore Laravel packages today?