nunomaduro/larastan
Larastan is a PHPStan extension for Laravel that analyzes your app to catch bugs early. It boots the container to resolve dynamic types, supports Laravel’s “magic,” and improves code quality with stronger static typing.
phpstan.neon config, and CLI execution), with minimal Laravel-specific adjustments.--memory-limit adjustments (e.g., 2G).| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Use ignoreErrors in phpstan.neon or inline comments (@phpstan-ignore-line). |
| Laravel Magic Limits | Leverage errors-to-ignore.md for known edge cases (e.g., HigherOrderCollectionProxy). |
| Performance Bottlenecks | Enable enableMigrationCache and disableSchemaScan if scans are unnecessary. |
| Version Skew | Pin Larastan version to match Laravel’s supported matrix (e.g., ^3.0 for Laravel 11+). |
| IDE Conflicts | Ensure laravel-ide-helper is disabled during analysis to avoid duplicate PHPDoc generation. |
phpstan.neon be version-controlled or environment-specific?ignoreErrors) be managed?disableMigrationScan be default?enableMigrationCache be enabled in CI (faster) vs. local dev (always fresh)?laravel-ide-helper)?assert()) that may conflict with static analysis.| Phase | Action | Rollout Strategy |
|---|---|---|
| Pilot | Run Larastan on a single module or new feature with level: 1. |
Optional for contributors. |
| Gradual Enforcement | Incrementally raise level (e.g., 1 → 3 → 5) and fix errors. |
Use baseline files for legacy code. |
| CI Integration | Add ./vendor/bin/phpstan analyse to pre-commit or pre-merge checks. |
Start with warnings, then enforce failures. |
| Full Adoption | Enforce level: 5 (or higher) and disable migration scans for non-critical paths. |
Deprecate ignoreErrors where possible. |
composer require --dev larastan/larastan).phpstan.neon with minimal rules (level: 1).phpstan analyse --generate-baseline).checkModelProperties, checkConfigTypes).enableMigrationCache, disableSchemaScan).phpstan.neon with justification.phpstan.neon may diverge across environments.phpstan.neon.dist) and CI validation.NoUnnecessaryCollectionCall) and how to fix them.rules.md, errors-to-ignore.md) for troubleshooting.--parallel flag for faster runs (if PHPStan supports it).phpstan.neon by domain/module to reduce scan scope.disableMigrationScan or disableSchemaScan if irrelevant.--memory-limit based on CI vs. local dev needs.How can I help you explore Laravel packages today?