PHPStan Level 8 + Nova + Package, "Call to an undefined method" error
When using PHPStan, most of the time we can add docblock comments to code that lets phpstan know what methods or properties are available on a class, but in this case, I am using Nova, and I have a third party package that adds additional methods to the Nova fields (specifically, I am using the codenco-dev/nova-grid-system package that allows you to set the width of fields to implement a grid-like organization of fields on Nova resources)
We are working on getting our PHPstan level up to 8 with no errors / issues, but this package + Nova combination in particular seems to be causing issues. The error is that the size() method on a field is undefined:
------ ----------------------------------------------------------------------------
Line app/Resources/Users/Nova/User.php
------ ----------------------------------------------------------------------------
78 Call to an undefined method Laravel\Nova\Fields\Text::size().
where the code in question is:
Text::make('Name')
->sortable()
->rules('required', 'max:255')
->size('w-1/4'),
The code works perfectly well, but PHPstan can't figure out where the size() method is coming from. I have tried adding the following docblock to the App\Nova\Resource abstract class:
/**
* @method \Laravel\Nova\Fields\Text size(string $size)
*/
but that did not solve the issue. I also tried making it generic:
/**
* @method \Laravel\Nova\Fields\Field size(string $size)
*/
and that also did not work. I tried adding both of these doc block comments to the User resource as well, to no avail. Aside from ignoring the error for all of the instances of size() I'm not sure how else to resolve this, since the method is a macro method on Nova's fields. Any ideas?
Please or to participate in this conversation.