app/Providers/) while allowing custom overrides for framework-specific patterns.routes/web.php from certain checks).phpcq/phpcq wrapper further simplifies adoption.vendor/, bootstrap/cache/) via XML rulesets.pint (formatter) and Rector (refactoring) by focusing on static analysis rather than code transformation.devDependencies."scripts": {
"cs-fix": "vendor/bin/phpcs --standard=PhpCodeQuality --report=emacs src/"
}
| Risk | Severity | Mitigation |
|---|---|---|
| Rule Conflicts with PSR-12 | Medium | Audit existing PSR-12 rules vs. PhpCodeQuality; merge or override as needed. |
| Performance Overhead in CI | Low | Exclude large directories (e.g., tests/) and cache results. |
| Lack of Laravel-Specific Rules | Medium | Extend rulesets for Laravel patterns (e.g., use App\Models\ imports). |
| Tooling Version Incompatibility | Low | Pin phpcs/phpmd versions in composer.json. |
| Low Community Adoption | Medium | Fork and maintain if critical rules are missing. |
PhpCodeQuality compare?phpcs and phpmd already in the stack? If not, what’s the effort to add them?pint or rector? Avoid duplication of formatting/refactoring tools.routes/, app/Providers/).phpcs).php artisan make:controller conventions).pint: Handles formatting (leave phpcs for style rules).rector: Handles refactoring (leave phpmd for static analysis).Phase 1: Audit Existing Codebase
phpcs and phpmd with default rules to identify violations.vendor/bin/phpcs --standard=PhpCodeQuality src/ --report=full > phpcs-report.txt
Phase 2: Configure Integration
phpcs/phpmd
Add to composer.json:
"scripts": {
"cs-check": "phpcs --standard=vendor/phpcq/coding-standard/phpcs/PhpCodeQuality/ruleset.xml src/",
"pmd-check": "phpmd src/ text vendor/phpcq/coding-standard/phpmd/ruleset.xml"
}
phpcq/phpcq Wrapper
Configure build.default.properties:
phpcs.standard=${basedir}/vendor/phpcq/coding-standard/phpcs/PhpCodeQuality/ruleset.xml
phpmd.ruleset=${basedir}/vendor/phpcq/coding-standard/phpmd/ruleset.xml
Run via:
vendor/bin/phpcq check
Phase 3: Incremental Enforcement
# .github/workflows/phpcq.yml
- name: PHPCQ Check
run: composer cs-check
husky):
// package.json
"husky": {
"hooks": {
"pre-commit": "composer cs-check"
}
}
Phase 4: Customization
phpcs.ruleset.xml:
<rule ref="PhpCodeQuality">
<exclude name="App\Providers" />
<exclude name="routes" />
</rule>
use App\Models\ imports).- name: Run PHPCQ
run: composer cs-check
test:phpcq:
script: composer cs-check
php-cs-fixer).phpcq/coding-standard for new rule additions.composer.json:
"require-dev": {
"phpcq/coding-standard": "^1.0",
"squizlabs/php_codesniffer": "^3.7",
"phpmd/phpmd": "^2.11"
}
CODE_QUALITY.md with:
## Code Quality
- Run `composer cs-check` to validate changes.
- Fix issues with `composer cs-fix`.
- Exclude files via `phpcs.ruleset.xml`.
app/Providers/ may trigger false positives.#[\AllowDynamicProperties]) may need exclusions.phpcs results toHow can I help you explore Laravel packages today?