- How does Larastan differ from regular PHPStan for Laravel?
- Larastan extends PHPStan to boot Laravel’s container, resolving types that are only known at runtime (e.g., dynamic facades, Eloquent models). This lets it catch bugs like undefined methods or incorrect return types in Laravel-specific code that regular PHPStan would miss.
- Can I use Larastan with Laravel 9 or older versions?
- Yes, but you’ll need Larastan v1.x for Laravel <9.0 and v2.x for Laravel 9.0+. For Laravel 11.16+, use v3.0+. Check the [supported versions table](https://github.com/larastan/larastan#supported-laravel-versions) for exact mappings.
- Will Larastan break my existing code due to strict typing?
- Not necessarily. Start with `level: 1` in `phpstan.neon` to catch only critical errors, then gradually increase the level. Use `@phpstan-ignore-line` or `ignoreErrors` to suppress false positives while refactoring.
- How do I configure Larastan to analyze migrations and schema dumps?
- Enable `enableMigrationCache` in `phpstan.neon` to speed up analysis, or disable `disableSchemaScan` if you don’t need schema validation. For large projects, consider `--memory-limit=2G` to avoid crashes during migration scans.
- Does Larastan work with Laravel’s dynamic properties (e.g., `$request->input()`)?
- Yes, but you may need to configure `errors-to-ignore.md` to handle edge cases like `HigherOrderCollectionProxy` or dynamic facades. Larastan is designed to support Laravel’s “magic” while still enforcing type safety.
- Can I integrate Larastan into GitHub Actions or CI/CD pipelines?
- Absolutely. Add `./vendor/bin/phpstan analyse` to your CI workflow (e.g., GitHub Actions) with `level: 5` for strict checks. Use `fail-on-error: true` to block merges with new type violations.
- How does Larastan handle legacy code without PHPDoc types?
- Use baseline files (`--generate-baseline`) to record current errors, then fix them incrementally. For untyped legacy code, start with `level: 1` and gradually increase strictness while adding PHPDoc annotations.
- Will Larastan slow down my development workflow?
- Initial analysis may take time for large codebases, but Larastan is designed for development-time checks. Enable `enableMigrationCache` in CI to speed up repeated runs, and consider running it in parallel with other tools like Pint.
- Does Larastan replace Laravel IDE Helper or PHP-CS-Fixer?
- No. Larastan focuses on static type analysis, while Laravel IDE Helper generates PHPDoc stubs for IDEs. Use both: Larastan catches bugs, and IDE Helper improves autocompletion. PHP-CS-Fixer handles coding standards separately.
- How do I suppress false positives for specific classes or methods?
- Add `@phpstan-ignore-line` or `@phpstan-ignore-next-line` inline, or configure `ignoreErrors` in `phpstan.neon` with class/method patterns. For complex cases, maintain an `errors-to-ignore.md` file to document known exceptions.