nunomaduro/larastan
Larastan is a PHPStan extension for Laravel that adds strong type inference and “code analysis” by booting the app container. It understands Laravel’s magic, finds bugs early, and improves code quality and developer productivity.
composer require --dev larastan/larastan) and requires minimal configuration (phpstan.neon). No core Laravel modifications are needed.--memory-limit=2G flag or parallel analysis (PHPStan’s --parallel).| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Use baseline files to exclude legacy errors; configure ignoreErrors in phpstan.neon. |
| Performance Overhead | Run in CI/CD pipelines (e.g., GitHub Actions) with cached dependencies. |
| Configuration Complexity | Start with level 5 (default) and incrementally raise severity. Use docs/rules.md for Laravel-specific rules. |
| Dependency Conflicts | Pin PHPStan version in composer.json to avoid breaking changes. |
| Blade/Template Parsing | Ignore dynamic Blade content (e.g., @{{ }}) via excludePaths or PHPDoc ignores. |
@var Collection<int, User>) be documented for the team?enableMigrationCache) be enabled to speed up repeated runs?vimeo/psalm-laravel instead.artisan test.spatie/laravel-type-checker) to prevent redundancy.composer require --dev phpstan/phpstan:^2.1.28 larastan/larastan:^3.0
phpstan.neon with Larastan’s extension:
includes:
- vendor/larastan/larastan/extension.neon
./vendor/bin/phpstan analyse --generate-baseline
main/develop branches.NoPublicModelScopeAndAccessorRule) via phpstan.neon.errors-to-ignore.md) for onboarding.| Component | Compatibility Notes |
|---|---|
| Laravel Packages | Works with most packages, but highly dynamic code (e.g., spatie/laravel-activitylog) may need ignores. |
| Custom Macros | Larastan does not parse macros by default. Use @phpstan-ignore-line or configure ignoreErrors. |
| Blade Templates | Supports basic Blade syntax but may miss dynamic content (e.g., @{{ $user->name }}). |
| Database Migrations | Supports raw SQL, ENUM types, and UUID/ULID via foreignUuid. |
| Event Listeners | Resolves event classes and payload types if properly typed. |
NoMissingTranslationsRule).phpstan.neon may need updates with Laravel/PHPStan major versions. Use dependency pinning to minimize surprises.NoPublicModelScopeAndAccessorRule) every 1–2 months. Subscribe to release notes to adopt improvements.--error-format=github) for debugging.Call to undefined method) should be fixed within 1 sprint.--parallel to distribute analysis across CPU cores.phpstan.neon files.projectPaths to analyze multiple apps in one run.enableMigrationCache: true to avoid re-parsing migrations.How can I help you explore Laravel packages today?