TomasVotruba / bladestan

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

Component support #60

Closed AJenbo closed 1 year ago

AJenbo commented 1 year ago
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Thumb extends Component
{
    public function render()
    {
        return view('components.img.view', []);
    }
}

When the class is extending Component it can be assumed that the view will be included in a context where the following variables exists as as such we should inject them when evaluating it out of context to pass the template correctly.

$slot = new Illuminate\Support\HtmlString();
$attributes = new Illuminate\View\ComponentAttributeBag();

If detecting the context of view() is problematic we could require that Component::view() be used instead.