laravel-elasticsearch
laravel-elasticsearch copied to clipboard
Static analysis fails on some methods
Package version
v4.0.3
Describe the bug
When running static analysis over the code using larastan which uses phpstan under the hood this error is generated:
Static call to instance method PDPhilip\Elasticsearch\Eloquent\Model::firstOrCreateWithoutRefresh().
from code like this:
Model::firstOrCreateWithoutRefresh([
'attribute' => 'value',
], [
'data' => [],
]);
To Reproduce
Steps to reproduce the behavior:
create standard project with larastan as a dev dependency and try using phpstan analysis on level 1
Expected behavior
I expect the documentation to have the static calls listed as at least static in the doc block in line with the online documentation.
additionally
there are a few methods that follow this pattern, so it isn't just this single case, this just happens to be the case I was made aware of.
Workaround
Looks like one can add this to their phpstan.neon file to avoid the phpstan error:
parameters:
ignoreErrors:
- '#Static call to instance method PDPhilip\\.*#'
intelephense will also complain, adding the following above the code should mute the error:
/** @disregard P1036 */
Model::firstOrCreateWithoutRefresh([
...
@sporchia , just so I understand. You've found no issue with the package itself, just an incomplete/erroneous doc block?
The tests for this method are here: https://github.com/pdphilip/laravel-elasticsearch-tests/blob/main/tests/EloquentTests/EloquentQueriesTest.php#L778-L803 - which is passing.
correct, it would be nice to have the doc block correct though
From help from the community, the package has been refactored with PHPstan integration - which applies to your query here. V4.1.0 will have these changes.