-
Notifications
You must be signed in to change notification settings - Fork 103
Add dynamic return type extensions for getRepository() methods #8
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
Conversation
Neat. IMO this can be merged. Ping @ondrejmirtes |
Hi, my current stance is that this does not work very well because of two things:
Please discuss whether I'm right or wrong and why should I merge this despite these points. Thank you. |
@ondrejmirtes my usecase would be fixing |
@bendavies Yep, I understand, but your solution does not always work because of point 1. At least for now I added support for correct return type from |
@ondrejmirtes you're completely right about 1. My use case is like the one from @bendavies : I have custom methods in repositories, but they do not necessarily start with |
@afurculita I understand but that's much harder to solve. It'd mean that PHPStan would have to know about part of dependency graph of your application in order to initialize RepositoryFactory, class metadata etc. I recommend you to access your repositories not through /** @var ArticleRepository */
private $articleRepository; It will lead to a better code not only for PHPStan, but for your tests as well, you won't have to mock as much. |
Hello, |
Looks wrong to me: the return type of I know we added a repository factory and customization to doctrine internals, but that was our mistake that we should fix. |
Besides the point #1 from my comment here, if you're in need of this extension, you shouldn't call BTW: I'm not a fan of extending EntityRepository at all. It encourages huge god objects with many methods because of 1:1 mapping between repositories and entities. I like much more specific repositories for specific use-cases of an entity. For example one repository for getting translations, another repository for tree manipulation etc. So I reserve my right to be opinionated and close this PR. |
Can this PR be reconsidered as an option of the plugin? I fully understand that we should not have lot of custom repositories and the fact that At least for old codebase following old conventions, having this PR possible with an option would be a real plus IMHO. 👍 |
@soullivaneuh If someone finished #18, I'd merge it. The advantage of the more recent PR is that it uses class metadata and is not hardcoded to read annotations. |
This is completely unrelated and also this code wasn’t merged.
On Sat, 19 May 2018 at 11:41, Niels Keurentjes ***@***.***> wrote:
@tsufeki <https://github.com/tsufeki> any idea why this doesn't also
catch #27 <#27>?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGZuNRW2HgM_1cenRwUjUpJpL9KxOyUks5tz-jDgaJpZM4PQOqE>
.
--
Ondřej Mirtes
|
Extract repository class from
@Entity
annotation and use it as return type ofgetRepository()
methods onEntityManager
andManagerRegistry
.