Skip to content

Generics in repository pattern problem #10824

Closed Answered by ondrejmirtes
PingusPepan asked this question in Support
Discussion options

You must be logged in to vote

PHPStan cannot understand that $repositoryManager->getRepositoryByEntity(Product::class) will return ProductRepository. 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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PingusPepan
Comment options

Answer selected by PingusPepan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants