Installation:
composer require amoifr/phpquality-bundle
Register the bundle in config/bundles.php:
PhpQuality\PhpQualityBundle::class => ['all' => true],
First Analysis:
php bin/console phpquality:analyze --source=src/ --type=laravel
src/ with your project's source directory.--type=laravel (or another framework type) for framework-specific rules.View Reports:
var/reports/ by default.var/reports/index.html in a browser for an interactive dashboard.Add this to your .git/hooks/pre-commit (or use a tool like husky):
#!/bin/sh
php bin/console phpquality:analyze --source=src/ --type=laravel --no-html --fail-on-violation
Run Analysis:
php bin/console phpquality:analyze --source=src/ --type=laravel --report-html=reports/
--type=laravel for Laravel-specific layer rules (e.g., ServiceProvider → Wiring layer).Review Violations:
solid.dip for concrete dependencies).Fix Iteratively:
@phpquality-ignore annotations for temporary suppressions:
/**
* @phpquality-ignore solid.dip -- Legacy dependency
*/
class LegacyService {}
Baseline Management:
php bin/console phpquality:analyze --source=src/ --generate-baseline=phpquality.baseline.json
phpquality.baseline.json to track accepted violations.php bin/console phpquality:analyze --source=src/ --baseline=phpquality.baseline.json
CI Pipeline:
# GitHub Actions example
- name: Run PhpQuality
run: php bin/console phpquality:analyze --source=src/ --baseline=phpquality.baseline.json --fail-on-violation
Custom Rules:
phpquality.json to override defaults:
{
"layers": {
"rules": [
{ "match": "App\\Services\\**", "layer": "Application" }
]
},
"ignore": {
"violations": ["solid.dip:App\\Legacy\\*"]
}
}
Test Coverage:
./vendor/bin/phpunit --coverage-clover=coverage.xml
php bin/console phpquality:analyze --source=src/ --coverage=coverage.xml
Dockerized Analysis:
docker run --rm -v $(pwd):/project amoifr13/phpquality --source=/project/src --type=laravel --report-html=/project/reports
Layer-Specific Focus:
php bin/console phpquality:analyze --source=src/ --type=laravel --layers=Domain,Infrastructure
False Positives in Framework Projects:
ServiceProvider is auto-categorized as Wiring (exempt from layer violations).--type=laravel is used; adjust phpquality.json if needed.Baseline Drift:
Performance:
--git-blame) is slow on large repos.Complexity Thresholds:
--generate-baseline to calibrate thresholds to your codebase.Docker Volume Mounts:
# Missing: -v $(pwd)/reports:/reports
docker run --rm -v $(pwd):/project amoifr13/phpquality --source=/project/src
Silent Failures:
--verbose to debug:
php bin/console phpquality:analyze --source=src/ --verbose
Layer Misclassification:
phpquality.json or use --list-types to verify your framework’s preset.Coverage Mismatches:
JSON vs. HTML Reports:
--json=report.json) are useful for programmatic access but lack visualization.Custom Metrics:
PhpQuality\Analyzer\Result\MetricCollection to add project-specific metrics.Report Templates:
templates/report/ to customize the HTML layout.CLI Commands:
PhpQuality\Command\AnalyzeCommand to add custom analysis logic.Project Types:
PhpQuality\Analyzer\ProjectType\ProjectTypeInterface.Violation Handlers:
PhpQuality\Analyzer\ViolationHandlerInterface to customize violation processing (e.g., slack notifications).Pair with PHPStan/Psalm: Combine with static analyzers for a layered quality check:
./vendor/bin/phpstan analyse --level=max
php bin/console phpquality:analyze --source=src/
Track Metrics Over Time: Use the JSON output to log metrics in a database and visualize trends (e.g., MI score per sprint).
Onboarding New Devs: Point them to the "Documentation" tab in the HTML report to explain metrics like CCN and LCOM.
Exclude Tests:
Add tests to --exclude to avoid analyzing them:
php bin/console phpquality:analyze --source=src/ --exclude=tests/
Architecture Score Targets: Aim for an Architecture Score > 70 (B rating) for maintainable projects. Use the dependency graph to identify circular dependencies.
How can I help you explore Laravel packages today?