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.
Shift from reactive to proactive code quality: Integrate static analysis into the CI/CD pipeline to catch bugs before they reach testing or production. Reduces debugging time and improves developer velocity.
phpstan.neon for new features while allowing baseline exceptions for legacy code.Leverage Laravel’s ecosystem: Build a type-safe foundation for new projects or migrate legacy codebases to modern PHP practices (e.g., stricter typing, fewer runtime errors).
Developer experience (DX) investment: Reduce context-switching for engineers by automating error detection during local development (e.g., via Git hooks or IDE plugins like PHPStorm integration).
--generate-baseline for legacy projects to gradually improve code quality without blocking work.Build vs. buy: Avoid custom static analysis tools (high maintenance) by adopting Larastan’s Laravel-specific extensions (e.g., Eloquent, Blade, Facades). Saves ~6–12 months of dev effort.
Roadmap alignment:
orchestra/testbench).--memory-limit or parallel runs).*"Larastan is like a pre-flight check for our Laravel code—it catches critical bugs before they crash production or slow down developers. For example, it would’ve flagged [insert real-world bug, e.g., a missing Eloquent relationship or undefined Facade method] that cost us [X hours/downtime]. By integrating this into our CI pipeline, we can:
Ask: Can we pilot this on [Project X] for 2 sprints to measure bug reduction? Budget: ~$0 (open-source); ROI: ~$Y in saved dev time."*
*"Larastan supercharges PHPStan to understand Laravel’s magic—like Eloquent models, Blade views, and Facades—so it stops treating them as ‘undefined.’ Here’s how we’ll use it:
phpstan analyse on PRs (Level 3) and merges (Level 5).--generate-baseline to gradually tighten rules without blocking work.Why now?
MethodNotFoundException’].Next steps:
composer require --dev larastan/larastan.phpstan.neon (I’ll share a template).Example win: It’ll flag this anti-pattern in 10 seconds:
// ❌ Larastan catches this:
$user->role->permissions; // role() might return null!
// ✅ Fixed with:
$user->role?->permissions;
```"*
---
### **For Developers:**
*"Larastan is your **PHPStan sidekick for Laravel**—it understands:
- Eloquent models (e.g., `User::where('active', true)->get()`).
- Blade templates (e.g., missing translations).
- Facades (e.g., `Cache::get('key')` without null checks).
**How to start**:
1. Install:
```bash
composer require --dev larastan/larastan
phpstan.neon:
includes:
- vendor/larastan/larastan/extension.neon
level: 5
paths:
- app/
./vendor/bin/phpstan analyse
Pro tip: Use @phpstan-ignore-line for false positives, but aim to fix 80%—it’ll make your code more robust.
What to expect:
--memory-limit=2G or run on specific files.How can I help you explore Laravel packages today?