-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[11.x] Fix incorrect PHPDoc for Builder relation #52754
[11.x] Fix incorrect PHPDoc for Builder relation #52754
Conversation
2808290
to
f460a7f
Compare
f460a7f
to
c3d9e0f
Compare
/cc @calebdw |
Also, I'm pretty sure it doesn't work with nested eager loading as the value in the array can be another array. |
This will not work---I believe call-site variance only works for generics (e.g., Perhaps this is something @ondrejmirtes might consider supporting? In the meantime you can simply change your closure to specify the - $query->with(['foo' => fn (HasOne $q) => $q]);
+ $query->with(['foo' => fn (Relation $q) => $q]); |
Recursive array types are a bit painful, I'll add |
PHPStan playground is not support, but PHPStan program is supported. |
Sorry, you're mistaken here---the playground is the phpstan program. The only reason why you're not seeing errors is that the framework phpstan level is too low,, This results in a phpstan parse error and it now knows nothing about the parameter type |
@calebdw |
@calebdw I think Regarding using
There's a slight issue with it if you need to perform other operations on the inner query like |
@Plytas, the Relation forwards those method to the mixed in Builder |
It does on runtime, but I wan't able to get PHPstan happy with it. |
Then there's a bug somewhere, but it does work: https://phpstan.org/r/a17bc6f0-ca28-4dd5-9c66-fbebf28db054 |
Thanks for going extra length to confirm it. I'll try to debug why it's not working on my end. |
Might be an issue with Larastan |
@calebdw just an FYI. I believe you're right about it being Larastan issue. It's missing the https://github.com/larastan/larastan/blob/2.x/stubs/common/Relation.stub |
Larastan has ClassReflectionExtensions that handle the mixin magic---please raise an issue over there and I'll look into it |
In PHPStan, the parameters in a Closure are non-covariant by default. So, when you define a Closure with a parameter type-hinted as a subclass of Relation, PHPStan will throw the following error:
This issue may be caused by #52729