• Reading time ~ 1 min
  • 28.03.2023

Have you ever released a Blade template to production that was accidentally missing a variable or a method that had a typo? Have you wanted to avoid finding templating bugs in production? Well, check out Bladestan, by the author of rector, which adds static analysis in PHPStan for Blade templates.

— Tomas Votruba (@VotrubaT) March 24, 2023

This package finds all view calls and looks if rendered variables have valid behavior in the provided template. For example, it will check the template file path and ensure it exists, inspect the variables, render the template, and review for any violation using your PHPStan setup.

Here's an example from the author's blog post Introducing Bladestan:

@foreach($posts as $post)
    {{ $post->getContet() }}
@endforeach

In the above example, PHPStan would return the following report:

log.blade.php:17
rendered in: app/Http/Controllers/BlogController.php:20
--------------------------------------------------------------
 - '#Call to an undefined method App\\Entity\\Post\:\:getContet\(\)#'

Bladestan takes care of everything you need to check your blade templates statically and uses your existing PHPStan setup, including Larastan.

To start with Bladestan, you can get the installation and setup instructions from the GitHub repo.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297