--level used: 6I tried exploring to use DynamicCallOnStaticMethodsRule from https://github.com/phpstan/phpstan-strict-rules
Check that statically declared methods are called statically
The use-case is to prevent (accidentally? intentionally for sake of consistency?) calling something defined as static function… as $this->… when self:: should be used.
When I enabled it, I was greeted with thousands of errors because of all the static calls to \Illuminate\Database\Eloquent\Builder, \Illuminate\Database\Query\Builder and some from the Illuminate\Database\Eloquent\Relations namespace.
Some specific error examples:
226 Dynamic call to static method
Illuminate\Database\Eloquent\Builder<Illuminate\Database\Eloquent\Mod
el>::orderBy().
…
299 Dynamic call to static method
Illuminate\Database\Eloquent\Builder<Illuminate\Database\Eloquent\Mod
el>::forPage().
…
73 Dynamic call to static method
Illuminate\Database\Eloquent\Relations\HasMany<Illuminate\Database\El
oquent\Model>::where().
List goes on, I've > 400 such errors 😅
So right now I've to use these ignoreErrors:
- '/Dynamic call to static method Illuminate\\Database\\Eloquent\\Builder/'
- '/Dynamic call to static method Illuminate\\Database\\Query\\Builder/'
- '/Dynamic call to static method Illuminate\\Database\\Eloquent\\Relations\\/'
Is there anything Larastan can assist doing here? 🤔
🙈 Fully closing your eyes helps in the short-term :)
This is a known issue with that rule I think. #355 and #483 are the same types of issues. I still don't know exactly how to solve this.
I was thinking the issue comes from here maybe. So this has to change dynamically somehow.
Can you maybe test with changing to false here? Just to confirm again, it solves some of the issues.
Can you maybe test with changing to false
I can confirm (I guess), hard to say because now I get > 400 "Static call to instance method" errors; but yes, it flipped the side.
Interestingly, from the ignoreErrors I pasted, only two were reported as being unused
Ignored error pattern /Dynamic call to static method
Illuminate\\Database\\Query\\Builder/ was not matched in reported errors.
Ignored error pattern /Dynamic call to static method
Illuminate\\Database\\Eloquent\\Relations\\/ was not matched in reported
errors.
The one ignoring Dynamic call to static method Illuminate\\Database\\Eloquent\\Builder is still encountered it seems.
I tried to search the issues for DynamicCallOnStaticMethodsRule. I know see the mistake I made, because although I installed the phpstan-struct-rules package, I only did this to enable this one rule, not everything.
Anyway, feel free to close this in favour of the existing ones. I don't think this issue brings news to the table…
Thank you Markus.
You may comment or open another issue Anytime!
Most helpful comment
🙈 Fully closing your eyes helps in the short-term :)