-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
Forward calls on Model when subclass is not known #565
Conversation
I think it's failing because the type hint is What is the use case for this? |
::find()
on generic models or model class-strings::find()
on generic models or model class-strings
Right, i saw that in the test case above. It should also work with the generic
I hit this in Lighthouse, where we interact with user-defined models in a generic way. See https://github.com/nuwave/lighthouse/blob/f32243e71930e515a4b8661520c67d4f1ba04416/src/Schema/Directives/DeleteDirective.php#L60 |
This extension is responsible for finding the missing methods on models. But this check prevents it running for So you can try to change that check to |
@canvural your proposed fix does indeed, work - thank you! I found that this does allow some invalid programs:
I dug around PHPStan's
The following example is ambigious:
Is there a way to specify a class-string must be a subclass of the given type? |
I guess my branch was not up to date, the mixin does seem to be causing problems. |
@canvural opened an issue with PHPStan that might help to solve this use case. phpstan/phpstan#3256 Pragmatically, i think it should be extremely rare that developers actually try to call something like
|
Hi, PHPStan 0.12.24 is released. So I updated master branch, and added So if you rebase this branch on master the tests should pass. And if you can update the changelog we can merge this 👍 |
Nicely done @canvural. It's unfortunate the types generated by |
::find()
on generic models or model class-strings
We can improve it, what needs to be done ? 😄 |
@mfn just to be clear, i was not bashing Many of the nuances of Laravel's magic can't really be expressed correctly through a nominal type system. Other parts can be expressed only through non-standard, PHPStan-specific annotations, for which proper IDE support does not exist. I was quite happy to see you pick up work on the project, there is a large backlog of issues and open PR's - lot's to do 😉 |
Changes
Avoid false-positive when calling static builder methods such as
::find()
on Model classes where the concrete subclass is not yet known.Breaking changes
No, allows more valid programs.