- 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.