nunomaduro/larastan
Larastan is a PHPStan extension for Laravel that adds static typing and catches bugs before you write tests. It understands Laravel's magic and boots your app container to resolve runtime types, supporting Laravel 9 through 11+.
Architecture fit. Larastan is a development-only Composer dependency (composer require --dev) that extends PHPStan with Laravel-aware type resolution: it adds extensions, stubs, and Laravel-specific rules for facades, the service container, Eloquent models/relations, config, translations, and Blade views. Architecturally it is a static quality gate that lives in CI and the IDE, not a runtime component — it ships nothing to production, adds no request-path latency, and has zero production blast radius. That makes it a low-ceremony fit for a standard Laravel service or monolith.
The important nuance for a TPM: the README is explicit that this is not pure static analysis. Larastan boots the application container so it can resolve types that only exist at runtime. The tool therefore inherits your app's bootstrap preconditions (env vars, APP_KEY, DB/Redis reachability for some rules and model-schema inference from migrations). That single design choice drives most of the operational risk below.
Integration feasibility. Very high on a modern stack. Three steps: install as dev dependency, add a phpstan.neon/phpstan.neon.dist including vendor/larastan/larastan/extension.neon (plus the Carbon extension), point paths at app/, run ./vendor/bin/phpstan analyse. Effort is measured in hours to first run, days to a stable baseline, and 1–2 sprints to a level ratchet with team-wide conventions.
Hard gates to clear up front:
orchestra/testbench to analyse correctly.Technical risk (ranked).
UPGRADE.md review.ignoreErrors regexes silently rot into a suppression layer that hides real defects.Allowed memory size exhausted is a first-class documented failure mode requiring --memory-limit=2G. Large codebases mean real CI minutes and wall-clock cost.Note on the metadata: Dependents: 0 is a measurement artifact — dev dependencies are largely invisible to dependent-counting, and download badges in the README indicate very wide real adoption. 6,547 stars and a frequent 3.9.x patch cadence signal an actively maintained, de facto standard tool. The opportunity: 57.26 score reads as "valuable but not urgent": this is a hygiene and defect-prevention investment, not a differentiating capability.
Key questions for the team.
phpstan.neon, the baseline file, and the level ratchet? Without a named owner this decays in a quarter.Stack fit. Ideal: Laravel 11.16+/12/13 on PHP 8.2+ (3.9.3 explicitly added Laravel 13 support), Composer-based CI, and any existing PR gate (GitHub Actions, GitLab CI, Bitbucket Pipelines). Works alongside Pint, PHPCS, and Rector; the only real friction point is Composer constraint overlap between Larastan's required PHPStan major and whatever Rector/PHPStan plugins are already installed.
Migration path — three tracks depending on where we start:
| Current state | Path |
|---|---|
| Greenfield / new service | Install Larastan 3.x, start at level 5, no baseline, gate from first PR. |
| Laravel 11.16+ legacy codebase | Install 3.x, generate baseline (--generate-baseline), gate new code above baseline, ratchet quarterly. |
| Laravel ≤10 | Pin Larastan 2.x (PHPStan 1.x). Do not adopt a baseline you cannot carry forward; time the 3.x migration with the Laravel 11+ upgrade. |
Compatibility considerations.
composer.json/composer.lock and bump deliberately — the 3.9.x line shipped six patches in a short window, several of them behavioral.phpstan.neon.dist), with phpstan.neon local overrides gitignored — same convention as phpunit.xml.dist.Sequencing.
ignoreErrors entries or code fixes.@phpstan-ignore-next-line for one-offs, config ignores only with a linked issue and expiry).Maintenance. Two artifacts become code-owned infrastructure: phpstan.neon and phpstan-baseline.neon. Both need an owner and a review policy. The maintenance burden is dominated by upgrade events, not steady state: Larastan's coupling to PHPStan majors and Laravel majors means roughly one to two coordinated upgrades per year plus monthly patch bumps. Pin, schedule, and read UPGRADE.md on every major — 3.0 in particular removed config options and enabled rules by default, which silently changes results.
Support. MIT, community-maintained, three named maintainers, no commercial SLA or vendor escalation path. Responsiveness looks healthy (small, frequent, well-described PRs; new contributors landing regularly), but this is a dependency we must be able to live without. Mitigation: an internal champion who can read the errors-to-ignore and custom-config-parameters docs and, if needed, disable the gate without disabling delivery. Do not make the release pipeline depend on it being fixed upstream on our schedule.
Scaling. Analysis cost grows faster than linearly with codebase size and level. Practical levers: PHPStan's result cache in CI, parallel workers, scoped paths, and splitting monorepos into per-package runs (each with testbench where relevant). Budget for --memory-limit at 2G and above, and size CI runners accordingly. The trade-off is real but favourable: CI minutes and slower PR checks are exchanged for defect discovery before tests are written and before review.
Failure modes to plan for.
APP_KEY, env, DB, or a PHP extension). Manifests as hangs or opaque internal errors; the Redis-extension infinite loop fixed in 3.9.5 is the canonical example. Mitigation: dedicated CI job with an explicit, committed env fixture; timeout on the step.ignoreErrors list grown without review, converts the gate into theatre. Enforce: baseline only shrinks except at sanctioned regeneration points; every config ignore carries a ticket reference.Ramp-up. Low for installation, moderate for value realisation. Developers need three habits, not deep training: how to read a PHPStan error, when to fix vs. @phpstan-ignore, and how to use Larastan's custom PHPDoc types to express intent on Eloquent models and relations (the 3.0 removal of automatic generic relation return types makes this an explicit team responsibility). Expect roughly 1–2 sprints from pilot to a self-sustaining gate, with one engineer carrying the tooling ownership at low ongoing cost.
Success measures to instrument from day one: error count above baseline (should trend to zero), baseline line count (should trend down), level (should trend up), PR check duration, and the count of code-quality defects found in CI rather than in review or production. If those last two don't move within two quarters, revisit the investment.
How can I help you explore Laravel packages today?