Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Analyzer Laravel Package

graham-campbell/analyzer

Analyzer is a PHP package by Graham Campbell that checks whether referenced classes actually exist. It helps catch missing or mistyped class references, supports PHP 8.1-8.5, and integrates with PHPUnit 10-13 for test-time analysis.

View on GitHub
Deep Wiki
Context7

Analyzer is a PHP package by Graham Campbell that checks whether referenced classes actually exist. It scans your code for class references and verifies each one can be resolved, catching typos, missing imports, and stale dependencies before they become runtime failures.

Built for modern PHP, it supports PHP 8.1–8.5 and integrates with PHPUnit 10–13, making it easy to add class-existence checks to your test suite.

  • Detects references to non-existent classes
  • Flags missing imports and typos early
  • Works seamlessly with PHPUnit-based workflows
  • Supports current PHP versions (8.1–8.5)
  • Lightweight, MIT-licensed, and actively maintained
Frequently asked questions about Analyzer
How do I install Analyzer in a Laravel project?
Run `composer require --dev graham-campbell/analyzer` to install it as a dev dependency. Ensure your project uses PHP 8.1–8.5 and PHPUnit 10–13 (default in Laravel 9+). No additional Laravel-specific setup is required.
Does Analyzer work with Laravel 8?
No, Analyzer v5.1+ requires PHP 8.1+ and PHPUnit 10–13, which aligns with Laravel 9+. For Laravel 8, use v4.x of the package, which supports PHPUnit 7–9, but check compatibility with your PHP version first.
Can I integrate Analyzer into my CI pipeline?
Yes, add it to your CI workflow by running `./vendor/bin/phpunit` with the Analyzer extension enabled in `phpunit.xml`. Failures will block builds if misconfigured classes are found, making it ideal for pre-deployment checks.
What types of class references does Analyzer validate?
Analyzer checks for valid class references in your code, including PHPDoc annotations (`@method`, `@property`, `@var`), Laravel service providers (e.g., `bind()` calls), middleware, and event handlers. It does not validate method signatures or return types.
How do I exclude specific files or classes from analysis?
Use the `getIgnored()` method in your test configuration to exclude files or classes. For example, ignore dynamic classes or legacy code by adding them to the whitelist. This helps avoid false positives in complex projects.
Will Analyzer slow down my local development?
No, Analyzer is designed for CI/CD use. Run it only in your pipeline or via custom scripts to avoid performance overhead. For local testing, use the `shouldAnalyzeFile()` method to limit checks to critical paths.
Does Analyzer support PHPDoc validation for OpenAPI/Swagger?
Yes, Analyzer validates PHPDoc annotations, which are critical for OpenAPI/Swagger documentation. It ensures `@method`, `@property`, and `@var` tags reference real classes, improving API reliability and IDE tooling (e.g., PhpStorm, VSCode).
What alternatives exist for class reference validation in Laravel?
Alternatives include PHPStan (for static analysis) and Psalm (for type checking), but they focus on broader validation. Analyzer specializes in class existence checks, making it lighter and more targeted for Laravel’s dependency patterns like service providers and facades.
How do I configure Analyzer to fail only on critical errors?
Use the `setStrictMode(false)` option to treat missing classes as warnings instead of failures. This is useful during migration phases or for non-critical paths. Combine with `getIgnored()` to fine-tune behavior.
Can Analyzer detect issues in Laravel migrations or factories?
Yes, but exclude them by default using `shouldAnalyzeFile()` to avoid false positives. Migrations and factories often reference dynamic classes (e.g., timestamps, soft deletes) that may not need runtime validation.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource