New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method Builder::whereX() should return static(Builder<Model>) but returns Builder<Model> #1676
Comments
Hello! |
Hello, I may have made some confusion by stripping some information from the error just to fit it in the title. Here are the actual error messages:
You can check https://github.com/sanfair/larastan-playground/pull/1/checks for more context. The problem is not in a model class. When phpstan analyzes method /**
* Add a "where not in" clause to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
* @param mixed $values
* @param string $boolean
* @return $this
*/
public function whereNotIn($column, $values, $boolean = 'and')
{
return $this->whereIn($column, $values, $boolean, true);
} I recreated the exact type structure but in raw PHP https://phpstan.org/r/bf3dd532-58f3-49c4-818e-fdf99883de72 Please check the types in the |
👍🏻 |
--level
used: 5Description
When defining a new
whereX
method in custom builder with return type annotation phpstan shows errors.In PR you can find both possible definitions that correctly execute at runtime, but trigger errors on static analysis.
Real application example: https://github.com/koel/koel/blob/master/app/Builders/AlbumBuilder.php#L10-L13
Note: in this case, an error can be resolved by specifying the return type as
self
, but it is not always correct.Possible related issues from phpstan: phpstan/phpstan#5132 phpstan/phpstan#4648
Note: solution with
self
used from these issuesCode where the issue was found
I managed to find the exact place where the type is defined. I tried to replace
\PHPStan\Type\Generic\GenericObjectType
with\PHPStan\Type\StaticType
but then it fails in other places.https://github.com/nunomaduro/larastan/blob/706784ec6b1bad487692730dc20aeee0ff1b19fa/src/Methods/EloquentBuilderForwardsCallsExtension.php#L150-L154
The text was updated successfully, but these errors were encountered: