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

component support? #27

Closed AJenbo closed 1 year ago

AJenbo commented 1 year ago

canvural/phpstan-blade-rule has a not in the readme:

Blade components are not analyzed. Support for it will come soon.

Has this been reolved since it does not appear?

I noticed that the following will produce an error:

<?php

namespace App\View\Components;

use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class MyComponent extends Component
{
    public string $test;

    public function render(): View
    {
        return view('components.my-component');
    }
}

Variable $test might not be defined.

TomasVotruba commented 1 year ago

Hi, this is not supported and I'm not sure it should. The view must have defined type and passed variables:

return view('components.my-component', [
     'test' => $this->test
]);

E.g. the $test in your example would throw fatal error, as is nullable and not defined since constuctor.

AJenbo commented 1 year ago

That's fair (and also the solution i went with). Another issue I found with components is that if i change view() for $this->view() it doesn't analyze the blade at all and just says there are no issues in the component.

TomasVotruba commented 1 year ago

Test fixture pull-request would the most helpful :)

AJenbo commented 1 year ago

Once I have grouped the various issues I will start creating a mvp project that can trigger these issues and submit it :)

TomasVotruba commented 1 year ago

Thanks :+1:

Instead of project, I mean a test fixture in here, e.g. https://github.com/TomasVotruba/bladestan/blob/b1e4a45d9180b743e74b439bf6ddb6e063986f9c/tests/Rules/LaravelViewFunctionRuleTest.php#L54, so we have it covered and see the errors :)

AJenbo commented 1 year ago

Well, one step at a time :)

AJenbo commented 1 year ago

I guess my question was answered, just maybe not the one i stated in the title :)