DEV Community

AriaieBOY
AriaieBOY

Posted on • Originally published at ariaieboy.ir

Test Your Codebase Without Testing It Using Larastan

Larastan is a wrapper around PHPStan for Laravel, and it let you test your source codes without writing any tests.

PHPStan is a static analyzer for PHP and it's working with legacy and modern codes.

Since lots of Laravel works magically PHPStan needs some justification to understand the magic behind Laravel it's when Larastan comes into place.

So if you have any PHP code base you can PHPStan and if you use Laravel you must go with Larastan. from here on I am gonna reference these tools as static analyzers.

But how it's working

Static Analyzers scan your code base before you even run your code in development or in CI to prevent any obvious & tricky bugs to reach your production.

PHPStan has 9 levels of rule sets that you can use on your code base. for example, level 0 only checks for:

basic checks, unknown classes, unknown functions, unknown methods called on $this, wrong number of arguments passed to those methods and functions, always undefined variables.

It's good practice to start using these tools with low levels and fix bugs and errors after you fixed all errors on that level you can bump your level up and try to make your code base more strict and bug-free.

For sure Static Analyzers are not going to test all possible outcomes of your code, but they can detect lots of annoying bugs and dead codes etc. and make your code base much cleaner and bug-free.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay