Builder scope in the same class is not yet recognized
szepeviktor opened this issue · comments
- Larastan Version: 2.6.4
--level
used: 5
Description
Call to an undefined method Illuminate\Database\Eloquent\Builder::valid().
I had to add a param tag to scopeInvalid
to work around it.
@param \Illuminate\Database\Eloquent\Builder<self> $query
Laravel code where the issue was found
/**
* Scope the query only to the valid quizzes.
*/
public function scopeValid(Builder $query, bool $valid = true): Builder
{
return $valid
? $query->whereNull($query->qualifyColumn('invalidated_at'))
: $query->whereNotNull($query->qualifyColumn('invalidated_at'));
}
/**
* Scope the query only to the invalid quizzes.
*/
public function scopeInvalid(Builder $query): Builder
{
return $query->valid(false); 👈🏻
}
Hi,
Yes, adding @param \Illuminate\Database\Eloquent\Builder<self> $query
is the only way. We cannot make assumptions because it'd be too complicated. Like, what if the method is in a trait, or what if there is some inheritance. Then what would be the model?
Thank you.