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

Public properties are reported to be maybe undefined #70

Open szepeviktor opened 1 year ago

szepeviktor commented 1 year ago
class Option extends Component
{
    /**
     * The option name.
     */
    public string $name;

    public function __construct(string $name)
    {
        $this->name = $name;
    }

    public function render(): View
    {
        return $this->view('components.cookie.option', [
            'acceptText' => __(':name engedélyezése', ['name' => $this->label]),
            'declineText' => __(':name elutasítása', ['name' => $this->label]),
        ]);
    }
}

AFAIK public Model properties are available in blade templates. Bladestan reports {{ $name }} as

Variable $name might not be defined.

Please advise.

AJenbo commented 1 year ago

Workaround:

        return $this->view('components.cookie.option', [
            'acceptText' => __(':name engedélyezése', ['name' => $this->label]),
            'declineText' => __(':name elutasítása', ['name' => $this->label]),
            'name' => $this->name,
        ]);

The issue here is that bladestan does not import them in to the context automatically, but if you do so explicitly it will be able to see them correctly.

spawnia commented 9 months ago

I added a failing test case for this with https://github.com/TomasVotruba/bladestan/pull/82.