A measured approach to using Larastan

More isn't always better

Joel Clermont
Joel Clermont

If you haven't heard of it, Larastan is a set of extensions that run on top of PHPStan to make it easier to use static analysis in a Laravel project.

PHPStan has the concept of levels, which are a way to gradually increase the strictness of the analysis. The higher the level, the more strict the analysis.

But what is a good level to use in your Laravel project? This is a question that I've heard a few times. And is there an implicit assumption that a higher level is always better?

Our project standard is to run apps at level 5. This seems to be the sweet spot between finding actual bugs and not making the analysis so strict that we can no longer write code in our preferred style.

The reality is that aspects of Laravel are quite dynamic and difficult to statically analyze without a lot of extra ceremony. For us, that trade off hasn't been worth it.

Your preferences may vary, but the point is that running at level 9 isn't necessarily the goal of using a tool like PHPStan. It should be to find bugs and improve the quality of your code.

Here to help,


P.S. Have a pesky PHPStan error you can't figure out? We've seen it all.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.