TomasVotruba / bladestan

PHPStan analysis for Blade templates
https://tomasvotruba.com/blog/introducing-bladestan-phpstan-analysis-of-blade-templates/
MIT License
286 stars 13 forks source link

Actually recursively fetch and compile includes #52

Closed AJenbo closed 1 year ago

AJenbo commented 1 year ago

Despite the comment on line 107 includes where being processed iteratively. This mean that the context from one include would bleed in to the next sibling, resulting in errors of undefined variables that are not actually in the blade file.

The following:

@include('vehicle', ['vehicle' => 'truck')
@include('animal', ['animal' => 'frogs')

Would result in something like this:

function () { // vehicle.blade.php
    $vehicle => 'truck';
}
function () use ($vehicle) { // animal.blade.php
    $animal => 'frogs';
}

The reason why variables are being gathered are for nested includes, but this should only affected child includes:

function () { // product.blade.php
    $product => 'truck';
    function () use ($product) { // image.blade.php
    }
}

Note a decent portion of the changed lines in this PR comes from removing a level of indentation so it is best viewed with "hide whitespace"

This is the last blocker for us using Bladestan with our project at level 1, so once this is merged I can start the integration for the second project :tada:

TomasVotruba commented 1 year ago

Thank you, this looks very good 👍😊