Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Static Analysis with Larastan

Premium
4 min read

Next, we will work on another Code quality tool - Larastan.


Why Larastan is Needed?

At first glance, it does the same job as our IDE - it shows errors and warnings in the code. But Larastan is more than that.

The idea behind Larastan is to catch errors that are not visible in the code but can happen during runtime (e.g., calling a method on a non-existing model attribute).

On top of that, it also checks for compatibility issues. For example, if you have a method that should return a string, but you return an integer, Larastan will catch that.


Installing Larastan

First, we create a GitHub issue to install Larastan:

Then, we create a new branch:

git checkout -b feature/larastan

Now we can install Larastan, we run the composer command:

composer require --dev "larastan/larastan:^3.0"

Then, we need to create a configuration file for...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

DO
David O'Connell ✓ Link copied!

I ran into a memory error when running phpstan. Fixed it with ./vendor/bin/phpstan analyse --memory-limit=256M

D
Daniel ✓ Link copied!

or you can add memory_limit = 512M to your php.ini file. you can find your own php.ini file using this command: php --ini | grep "Loaded Configuration File"