graham-campbell/analyzer
Analyzer is a PHP tool by Graham Campbell that scans your code/tests to verify referenced classes actually exist, catching typos and broken imports early. Requires PHP 8.1–8.5 and supports PHPUnit 10–13 (v5.1).
@method, @property, and @var annotations, critical for IDE tooling (PhpStorm/VSCode) and API documentation (OpenAPI/Swagger).AnalysisTrait) for easy integration into existing test suites or custom scripts.phpunit.xml as a pre-test step or triggered via CLI for ad-hoc validation.bind()/singleton() references.handle() methods.toArray() references valid models.authorize()/rules() class dependencies.| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Configure getIgnored() to exclude dynamic classes (e.g., eval(), class_alias()). |
| Performance Overhead | Run only in CI (not local dev) or limit to critical paths (provideFilesToCheck). |
| PHPDoc Inconsistencies | Use shouldAnalyzeFile() to skip generated files (e.g., migrations, factories). |
| PHPUnit Version Lock | Pin to v5.1 (PHP 8.5 + PHPUnit 13) to avoid future compatibility breaks. |
| Custom Namespace Logic | Not supported; workaround: Pre-process aliases (e.g., use App; → App\Models). |
vendor/, tests/)?App\Services\Legacy\*)?use App;)?use App; aliases) that may need pre-processing.Feature\Api\*).getIgnored() to exclude non-critical paths.phpunit.xml:
<phpunit>
<extensions>
<extension class="GrahamCampbell\Analyzer\AnalyzerExtension" />
</extensions>
</phpunit>
./vendor/bin/phpunit --testdox-html --filter AnalyzerTest
| Component | Compatibility Notes |
|---|---|
| Laravel Versions | 9+ (PHP 8.1+). Laravel 8 may require v4.x of the package. |
| PHPUnit | 10–13 (default in Laravel 9+). Avoid v7–9 due to dropped support. |
| PHP Parser | Uses PHP Parser v2+ (modern Laravel projects already include this). |
| PHPDoc | Validates @method, @property, @var, and @throws. |
| Dynamic Classes | Not supported: eval(), class_alias(), or runtime namespace aliases. |
| Custom Namespaces | No support: use App; → App\Models requires manual pre-processing. |
getIgnored() as the codebase evolves.getIgnored() and getPaths()).composer.json or config/app.php.| Issue | Solution |
|---|---|
False positives in vendor/ |
Exclude via getIgnored(['vendor/*']) in AnalysisTrait. |
| PHPDoc errors in generated files | Use shouldAnalyzeFile() to skip migrations/, factories/. |
| Slow CI runs | Limit to critical paths (provideFilesToCheck()). |
| Custom namespace aliases | Pre-process aliases before analysis (e.g., use App; → App\Models). |
@internal classes).provideFilesToCheck() to target specific directories.How can I help you explore Laravel packages today?