Generics in repository pattern problem #10824
-
Hello, Here is a simplified example: https://phpstan.org/r/cc252630-26ed-4fda-ae33-53237020433e I'd expect that by using If I use it with AbstractRepository then it's missing all the methods from the final repository: https://phpstan.org/r/51c111fd-cf02-44cf-a2ca-eb8659267b3e What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
PHPStan cannot understand that You can use a dynamic return type extension in order to infer that: https://phpstan.org/developing-extensions/dynamic-return-type-extensions phpstan-doctrine does something similar because it faces the same challenge. |
Beta Was this translation helpful? Give feedback.
PHPStan cannot understand that
$repositoryManager->getRepositoryByEntity(Product::class)
will returnProductRepository
. This information isn't encoded anywhere.You can use a dynamic return type extension in order to infer that: https://phpstan.org/developing-extensions/dynamic-return-type-extensions
phpstan-doctrine does something similar because it faces the same challenge.