graham-campbell/analyzer
Analyzer by Graham Campbell statically checks your PHP code to ensure referenced classes actually exist, helping catch typos and missing dependencies early. Supports PHP 8.1–8.5 and integrates with PHPUnit 10–13.
composer require graham-campbell/analyzer --dev, with no runtime dependencies (dev-only).@group analyzer).php vendor/bin/phpunit --group analyzer).php artisan analyzer:check).pint --test).| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Configurable ignore lists (getIgnored()) and file filtering (shouldAnalyzeFile()). |
| Performance | Optimized for CI speed (parallelizable, skips ignored files). Benchmarked at <5 min for 10K+ files. |
| PHP Version Lock | Strict versioning (PHP 8.1–8.5) but backward-compatible with Laravel 9–11. |
| PHPDoc Parsing | Uses phpdocumentor/reflection-docblock, reducing risk of annotation parsing errors. |
| Laravel-Specific Quirks | No native support for dynamic aliases (e.g., use App;), but PSR-4 autoloading is fully supported. |
| Maintenance Burden | MIT-licensed, actively maintained (last release: 2026-03-19). No vendor lock-in. |
Scope of Validation:
use statements or also PHPDoc annotations (e.g., @property, @method)?CI Integration Strategy:
Ignore Lists:
tests/, vendor/) + whitelist exceptions (e.g., Stripe\*).Performance Trade-offs:
--parallel flag if CI allows (PHPUnit 10+ supports this).Laravel-Specific Customization:
Facade::class) or service container bindings?Alerting:
app/, src/), warn only for tests.| Component | Compatibility |
|---|---|
| PHP | 8.1–8.5 (Laravel 10–12) |
| PHPUnit | 10–13 (required for v5.1+) |
| Composer | PSR-4 autoloading (Laravel’s default) |
| Laravel | 9–12 (PHP 8.1+), with partial support for 8.x (via v4.2) |
| CI Systems | GitHub Actions, GitLab CI, CircleCI (PHPUnit integration) |
| Static Analyzers | Complements PHPStan/Psalm (runs first to filter false positives) |
| IDE/Editor | No direct integration, but PHPDoc validation improves autocompletion |
Assessment Phase (1–2 days):
getIgnored() accordingly.CI Integration (1 day):
composer.json (dev dependency):
"require-dev": {
"graham-campbell/analyzer": "^5.1"
}
phpunit.xml):
<listeners>
<listener class="GrahamCampbell\Analyzer\AnalysisListener" />
</listeners>
- name: Run Analyzer
run: php vendor/bin/phpunit --group analyzer
Laravel-Specific Hooks (Optional, 1 day):
php artisan make:command AnalyzerCheck
// app/Console/Commands/AnalyzerCheck.php
use GrahamCampbell\Analyzer\Analyzer;
use GrahamCampbell\Analyzer\AnalysisTrait;
class AnalyzerCheck extends Command {
use AnalysisTrait;
protected function getPaths() { return [app_path(), base_path('src')]; }
protected function getIgnored() { return ['tests/*', 'vendor/*']; }
}
PHPDoc Optimization (Ongoing):
@method references).| Scenario | Compatibility Status |
|---|---|
| Laravel 10+ (PHP 8.5) | ✅ Full support (v5.1+) |
| Laravel 9 (PHP 8.1) | ✅ Full support (v5.1+) |
| Legacy Laravel (8.x, PHP 7.4) | ⚠️ Partial (use v4.2, but no PHP 8.5 features) |
| Custom Autoloading | ❌ Not supported (e.g., use App; aliases) |
| Dynamic Class Loading | ❌ Not supported (e.g., eval(), class_alias()) |
| PHPDoc-Only Projects | ✅ Supported (validates annotations without code) |
| Monorepos | ✅ Supported (configure getPaths() per repo) |
Phase 1: Core Validation (Week 1)
use statements in app/ and src/ directories.Phase 2: PHPDoc Expansion (Week 2)
Phase 3: CI Optimization (Week 3)
Phase 4: Developer Adoption (Ongoing)
How can I help you explore Laravel packages today?