--level used: 5factory(UserModel::class)->make();
Error: Function factory invoked with 1 parameter, 0 required.
Are we able to inspect the @param notation of this function, or should we provide an extension here in larastan?
Hello,
It seems to be the @param tag has not valid syntax. You can see here: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/helpers.php#L490
I'm not sure if this is even valid PHPDoc syntax. So PHPstan does not recognize it. You can try to make a PR in Laravel repo to change this.
@canvural do you have a suggestion on how to do so without it being a breaking change?
I also found https://github.com/phpstan/phpstan/issues/1881#issuecomment-461728870 which might be related
@mr-feek You can just change the PHPDoc, that wouldn't be a breaking change. Also converting the function to variadic arguments (...$args) would not be a breaking change I think. Laravel also uses variadic argument style in many other places.
Maybe we can solve this with the help of stubs, instead of making a PR in Laravel waiting to be merged.
I'm gonna re-open this. Any PRs are welcome! :+1:
Looks like this will be fixed in Laravel 7.0 https://github.com/laravel/framework/pull/30867
For now you can help yourself with a stub.
I'm new to setting this up, but how exactly would I create a stub for Laravel 6.x?
I have added
stubFiles:
- stubs/helpers.stub
to my phpstan.neon which seems to be working,
and then created that file (stubs/helpers.stub) with
<?php
/**
* @param string $class
* @param int $amount
* @return \Illuminate\Database\Eloquent\FactoryBuilder
*/
function factory($class, $amount = null)
{
}
I am still getting Function factory invoked with 1 parameter, 0 required
Was anyone able to get this working? We're on 6.x also and have the same issue, stub file doesn't seem to help.
Was anyone able to get this working? We're on 6.x also and have the same issue, stub file doesn't seem to help.
If stubs are really not working for that case, it seems maybe PHPStan does not support adding stubs for functions in global namespace or there is a bug with it. Please create an issue there.
Most helpful comment
I'm new to setting this up, but how exactly would I create a stub for Laravel 6.x?
I have added
to my
phpstan.neonwhich seems to be working,and then created that file (stubs/helpers.stub) with
I am still getting
Function factory invoked with 1 parameter, 0 required