Replies: 1 comment
-
Yeah, I think there's an open issue about it. But level 6 tells you to specify this type (https://phpstan.org/r/5bebb5c7-01f0-4a1d-8acb-6e4b661eeffa) so it's inevitable you'll find out about it. To me it doesn't make sense to use an advanced feature like generics, and then stay on a pretty low level like 5. You should use level 8 to get the most out of it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I found some issues with nested generics and I think return type is not resolved correctly if class types are not specified.
Specific example:
It can be also found here: https://phpstan.org/r/7a08ad60-4d25-4d13-abb6-7d45fd238d07
Problem is in GenericService::action() method:
Parameter #1 $entity of method GenericService::test() expects AbstractSpecificEntity, EntityInterface given
I think it's not correct, because
SpecificRepository
has templateT of AbstractSpecificEntity.
Even it's type is not specified, but it can be only instance ofAbstractSpecificEntity
, so I think by default it should be used as return type and not fallback to parent class template.I know that it's easy fix just to simply specify
SpecificRepository
type, however in GenericService I expect only abstraction, nothing specific. It's possible that it's not clear which specific implementation will be passed, so even specified type will look like this:/** @var SpecificRepository<AbstractSpecificEntity> */
Is any way to avoid specifying types in cases like in this example?
Beta Was this translation helpful? Give feedback.
All reactions