larastan: Parameter $column of method orWhere() errors when Illuminate\Database\Query\Expression is given
- Larastan Version: 0.7.0
--levelused: 5- PHPStan Version: 0.12.75
Description
When on level 5, the orWhere() method on Illuminate\Database\Eloquent\Builder<Illuminate\Database\Eloquent\Model>::orWhere() fails when a Illuminate\Database\Query\Expression is given, even though it’s in the DocBlock of aforementioned method.
/**
* Add an "or where" clause to the query.
*
* @param \Closure|array|string|\Illuminate\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @return $this
*/
public function orWhere($column, $operator = null, $value = null)
Laravel code where the issue was found
$subQuery->orWhere(
DB::raw(sprintf('lower(%s)', $column)),
'like',
'%' . strtolower($searchTerm) . '%'
);
Full error:
{
"description": "Parameter #1 $column of method Illuminate\\Database\\Eloquent\\Builder<Illuminate\\Database\\Eloquent\\Model>::orWhere() expects array<int|string, mixed>|Closure|string, Illuminate\\Database\\Query\\Expression given.",
"fingerprint": "3d188e1afc222590ee964c4330945aaa601e2139aaf0454b43c2e3ad64662aef",
"location": {
"path": "app/JsonApi/AbstractAdapter.php",
"lines": {
"begin": 46
}
}
}
Note: it says it expects an array that looks like int|string or mixed, that’s another error I think?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (11 by maintainers)
@szepeviktor @canvural I’m happy to report that the error is gone when applying the changes mentioned in https://github.com/nunomaduro/larastan/issues/784#issuecomment-781229537.
On to the tests now.
That makes perfect sense. Thank you!
For now I’ve changed it to this and am currently manually testing it:
@szepeviktor @canvural What about the array type that’s included in the stub but not in the original DocBlock? Is that expected?
Hello @ttomdewit! We use stubs for special purposes. https://github.com/nunomaduro/larastan/blob/72c7bd2311594a896386b9a7789f709748e9d1cc/stubs/EloquentBuilder.stub#L143-L151 It really lacks that type. Could you send a PR?