lcobucci/coding-standard
PHP_CodeSniffer ruleset based on Doctrine’s coding standard with small tweaks. Install and use it in your projects to enforce consistent formatting and code style via phpcs in CI and local development.
phpcs commands.array{} syntax, attributes, union types).composer require with minimal configuration (e.g., adding to phpcs.xml or CI scripts).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| PHP Version Lock-in | Requires PHP 8.4+ (v12.0.0+). | Phase adoption: Start with v11.x (PHP 8.2+) for legacy projects, migrate to v12.x. |
| PHPCS Version | PHPCS 4.0+ required (v12.0.0+). | Audit CI/CD for PHPCS upgrades; use php-cs-fixer as a fallback for older setups. |
| Rule Overrides | Custom rules may conflict with existing PHPCS configs. | Test in a staging environment; use phpcs --ignore for exceptions. |
| Performance | PHPCS can slow CI pipelines if not cached. | Cache PHPCS results (e.g., GitHub Actions actions/cache). |
| False Positives | Strict rules (e.g., array syntax) may flag legacy code. | Configure .php-cs-fixer.dist.php to exclude specific files/directories. |
PHP Version Strategy:
CI/CD Impact:
php-cs-fixer be used for auto-fixes in pre-commit hooks?Customization Needs:
Tooling Stack:
squizlabs/php_codesniffer?Adoption Phasing:
php artisan lint) for developer convenience.[ParamConverter] formatting).php-cs-fixer fix).pre-commit to block violations early.| Phase | Action | Tools/Commands |
|---|---|---|
| Assessment | Audit current PHPCS/PHP-CS-Fixer configs for conflicts. | composer why-not lcobucci/coding-standard, phpcs --standard=current --sniffs |
| Pilot Project | Test in a non-critical Laravel module or Symfony bundle. | composer require lcobucci/coding-standard, update phpcs.xml. |
| CI/CD Integration | Add PHPCS to CI pipeline (e.g., GitHub Actions). | Example: phpcs --standard=lcobucci --error-severity=3 src/ |
| Developer Onboarding | Document rules and provide a fix-it script (PHP-CS-Fixer). | php-cs-fixer fix --rules=@lcobucci |
| Full Rollout | Enforce in all repositories; archive legacy PHPCS configs. | Update composer.json across monorepo or team projects. |
@foreach). Exclude resources/views in phpcs.xml.[Inject]) are supported in PHP 8.0+.[ListenerEvent]) is enforced.--ignore for deprecated files or gradual enforcement (e.g., phpcs --ignore=legacy/).phpcs.xml template with LCobucci’s rules.<config defaultStandard="lcobucci">
<arg name="encoding" value="utf-8"/>
<file>./src</file>
<exclude>./tests</exclude>
</config>
- name: Run PHPCS
run: composer require --dev lcobucci/coding-standard && vendor/bin/phpcs --standard=lcobucci --error-severity=3 src/
{
"hooks": {
"pre-commit": "phpcs --standard=lcobucci --warning-severity=0"
}
}
composer require --dev php-cs-fixer
./vendor/bin/php-cs-fixer fix --rules=@lcobucci
How can I help you explore Laravel packages today?