- How do I install Analyzer in a Laravel project?
- Run `composer require graham-campbell/analyzer --dev` to install it as a development dependency. It requires PHP 8.1–8.5 and PHPUnit 10–13. No additional configuration is needed for basic usage.
- Does Analyzer work with Laravel Facades (e.g., Cache::store())?
- Analyzer may flag Facades as errors by default since they dynamically resolve classes. To fix this, exclude the `app/Providers/` or `app/Facades/` directories in `getIgnored()` or extend `shouldAnalyzeFile()` to whitelist them.
- Can Analyzer catch typos in PHPDoc annotations (e.g., @method, @property) in Laravel Policies or Form Requests?
- Yes, Analyzer validates PHPDoc references just like regular class references. It’s especially useful for catching typos in Laravel’s annotation-heavy components like Policies, Form Requests, and API Resources.
- Will Analyzer slow down my CI pipeline significantly?
- Analyzer is lightweight (~1–2 seconds for medium Laravel apps) and can be parallelized. For large codebases, cache results with `composer cache:clear` or run it in parallel using tools like `php-parallel-lint`.
- How do I integrate Analyzer into GitHub Actions or GitLab CI?
- Add it to your CI script like this: `composer run analyzer`. Use `fail-on-error: true` to block PR merges. Example for GitHub Actions: `- name: Run Analyzer run: composer run analyzer`.
- Does Analyzer support Laravel’s Service Providers or API Resources?
- Yes, Analyzer is designed for Laravel’s ecosystem and will validate class references in Service Providers, API Resources, and other core components. Just ensure the paths are included in `getPaths()`.
- What if Analyzer flags a false positive (e.g., dynamic class loading with `class_alias()`)?
- Exclude problematic paths in `getIgnored()` or override `shouldAnalyzeFile()` to skip dynamic class loading. For example, ignore `vendor/` or custom directories where dynamic loading occurs.
- Can I use Analyzer alongside PHPStan or Psalm?
- Yes, Analyzer acts as a pre-filter to reduce false positives in PHPStan/Psalm by 30–50% for class-related issues. Run Analyzer first in your CI pipeline to catch obvious errors before deeper static analysis.
- What Laravel versions does Analyzer support?
- Analyzer is framework-agnostic but optimized for Laravel 9+. It works with any Laravel version that uses PHP 8.1–8.5, including Service Providers, Facades, and Eloquent models.
- How do I customize Analyzer to ignore third-party SDKs (e.g., stripe/stripe-php)?
- Use `getIgnored()` to exclude vendor paths like `vendor/stripe/`. For SDK-specific PHPDoc issues, extend `shouldAnalyzeFile()` to filter out SDK directories or override validation logic for known-safe references.