Installation:
composer global require edgedesign/phpqa
Or add to project:
composer require --dev edgedesign/phpqa
First Run (analyze entire project):
phpqa
Outputs default analysis (PSR1/PSR2, PHPStan, PHPMD, etc.) with combined results.
Quick Check (focused on critical issues):
phpqa --severity=critical
~/.phpqa.php (global) or .phpqa.php (project-specific).~/.phpqa/tools/ (e.g., phpstan.neon, phpmd.xml).phpqa --help
Run a pre-commit hook to block critical issues:
phpqa --severity=critical --format=json --output=phpqa-results.json
Then integrate with Git hooks (e.g., pre-commit) to fail if phpqa-results.json contains errors.
Project-Wide Analysis
phpqa --exclude=tests,vendor --format=github
--exclude to skip non-code directories (e.g., vendor, tests).--format=github for PR-friendly output (works with GitHub Actions).Per-Directory Analysis
phpqa src/ --tools=phpstan,psalm
src/, modules/).src/).CI/CD Integration
# .github/workflows/phpqa.yml
jobs:
phpqa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: phpqa --severity=critical --format=github
--severity=critical.--format=github for native GitHub annotations.Custom Configs
Create .phpqa.php in your project:
return [
'tools' => [
'phpstan' => [
'level' => 5,
'configuration' => 'phpstan.neon',
],
'psalm' => [
'config' => 'psalm.xml',
],
],
'exclude' => ['tests', 'vendor', 'node_modules'],
];
var/ and vendor/ by default:
phpqa --exclude=var,vendor
phpqa app1/ app2/ --tools=phpstan,phpmd
parallel-lint or pct alongside PHPQA for faster feedback.phpqa --cache-results
Tool Conflicts
--tools=phpstan or --tools=psalm explicitly to avoid redundancy..phpqa.php to prioritize one tool:
'tools' => ['phpstan' => ['level' => 5], 'psalm' => ['enabled' => false]],
XSL Extension Missing
xsl extension. Install it via:
pecl install xsl
--format=text or --format=json if HTML isn’t critical.Slow Initial Runs
phpqa --cache-results
False Positives
phpqa --severity=high,critical
--ignore-errors to skip known issues temporarily.Config Overrides
.phpqa.php overrides global ~/.phpqa.php. Test changes incrementally:
phpqa --dry-run
Verbose Output:
phpqa -vvv
Reveals tool-specific logs (e.g., PHPStan’s error details).
Tool-Specific Debugging:
phpqa --tools=phpstan --debug
Shows raw PHPStan output for troubleshooting.
Check Config Validity:
phpqa --validate-config
Validates .phpqa.php syntax before running.
Custom Tools
Extend PHPQA by adding new tools. Example for custom-tool:
// ~/.phpqa/tools/custom-tool.php
return [
'command' => 'vendor/bin/custom-tool analyze {path}',
'severity_map' => ['error' => 'critical', 'warning' => 'major'],
];
Then run:
phpqa --tools=custom-tool
Post-Analysis Scripts
Use --output to generate machine-readable results, then process with a script:
phpqa --format=json --output=results.json
php process-results.php results.json
GitHub Actions Annotations
Combine with phpqa to highlight issues in PRs:
- run: |
phpqa --format=github > phpqa-annotations
cat phpqa-annotations >> $GITHUB_STEP_SUMMARY
Dynamic Excludes Use environment variables for dynamic paths:
phpqa --exclude="tests,${CI_BUILD_DIR}/temp"
How can I help you explore Laravel packages today?