php-collective/code-sniffer
PHP_CodeSniffer ruleset from PhpCollective. PSR-2 compliant with many extra sniffs/fixers (incl. PSR-12) plus an optional stricter standard (PhpCollectiveStrict). Install via Composer and run phpcs/phpcbf, or wire into CI/IDE.
PhpCollective and PhpCollectiveStrict), allowing gradual adoption. This aligns well with Laravel’s incremental improvement philosophy.phpcbf), reducing manual refactoring overhead—a key advantage for Laravel’s rapid development cycles.require-dev dependency, with minimal configuration (e.g., phpcs.xml). Laravel’s existing composer.json scripts can easily incorporate cs-check/cs-fix commands.PhpCollective.ControlStructures.DisallowCloakingCheck) may conflict with Laravel’s idiomatic patterns (e.g., dynamic property access). Mitigation: Test against Laravel’s core codebase first.^8.1) or fork the package for older PHP.laravel-pint) to avoid redundancy.PhpCollective sniffs align with Laravel’s existing standards (e.g., Generic.Files.LineEndings vs. Laravel’s .editorconfig)?pint, psalm, or rector? Should it replace or complement them?app/, packages/) via phpcs.xml includes.PhpCollectiveStrict standard can be gradually adopted by excluding legacy paths initially.composer.json (require-dev).phpcs.xml to target new code only (e.g., app/Http/).--warning-severity=3).squizlabs/php_codesniffer).PhpCollectiveStrict after stabilizing the baseline.PhpCollective.Laravel.DisallowFacadeStaticCalls) may conflict with Laravel’s facade pattern. Solution: Exclude or customize these rules.vendor/bin/phpcs is in PATH or use ./vendor/bin/phpcs for consistency.| Step | Action | Tools/Files Involved |
|---|---|---|
| 1. Installation | composer require --dev php-collective/code-sniffer |
composer.json |
| 2. Configuration | Create phpcs.xml with PhpCollective ruleset. |
phpcs.xml |
| 3. CI Setup | Add vendor/bin/phpcs to CI workflows (e.g., GitHub Actions). |
.github/workflows/lint.yml |
| 4. IDE Setup | Configure PHPStorm/VSCode external tools. | IDE Settings |
| 5. Gradual Rollout | Run on new PRs first, then expand to all branches. | git |
| 6. Strict Mode | Migrate to PhpCollectiveStrict after baseline compliance. |
phpcs.xml |
composer update php-collective/code-sniffer --with-dependencies.^1.0) for stability.Sniffs/ and updating ruleset.xml. Complexity: Medium (requires PHP knowledge).README.md, docs/sniffs.md), but lacks Laravel-specific examples. Gap: Create a laravel-phpcs-config template repo.squizlabs/PHP_CodeSniffer community for broader support.--report=full for detailed violation reports and --diff to compare changes.phpcs --cache).parallel-lint + phpcs).vendor/ and node_modules/ from scans.phpcs.xml in a monorepo or template.| Scenario | Impact | Mitigation |
|---|---|---|
| CI Fails on Legacy Code | Blocks PRs for non-compliant code. | Gradually exclude paths or silence rules. |
| Rule Overrides Conflict | Custom phpcs.xml breaks builds. |
Use git diff to identify changes. |
| Performance Bottleneck | CI times out on large repos. | Cache results or split into stages. |
| IDE Integration Fails | Sniffs not triggering in editor. | Verify vendor/bin/ is in PATH. |
| False Positives | Legitimate code flagged. | Customize rules or exclude files. |
composer.json and run composer cs-check.Ctrl+Comma for sniffing).phpcs.xml for project needs.CONTRIBUTING.md snippet on CS rules.phpcbf for auto-fixing common issues.pint/psalm or works alongside them.PhpCollective.Laravel.DisallowBladeEcho).phpcbf-compatible issues on PRs (with approval).How can I help you explore Laravel packages today?