Skip to content
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

Adding not-nullable search methods to ObjectRepository #23

Open
Jean85 opened this issue Feb 9, 2018 · 3 comments
Open

Adding not-nullable search methods to ObjectRepository #23

Jean85 opened this issue Feb 9, 2018 · 3 comments

Comments

@Jean85
Copy link

Jean85 commented Feb 9, 2018

I'm currently in the process of improving my codebase with static analysis (PHPStan in this case), and I've found an interesting use case to improve the ObjectRepository interface: I find it pretty annoying have to specify/check each time that I don't expect null values from my find()/findOneBy() methods etc, so it would be nice if there was some get*() twin methods for which a nullable return would not be allowed.

This is obviously a BC, so it should target 3.0, hence leveraging nullable types from PHP 7.1 it would make really sense.... What do you think?

PS: since we already have doctrine/common#826 doctrine/common#738 etc, maybe we can create a 3.0 milestone?

@Majkl578
Copy link
Contributor

Majkl578 commented Feb 9, 2018

It could be done similarly to AbstractQuery::getSingleResult()/AbstractQuery::getOneOrNullResult(), although find with null should probably be the happy path since catching exception is more costly.

maybe we can create a 3.0 milestone

Doctrine Common is to be split and obsoleted for 3.0 (see #826) so I don't think that tracking 3.0 milestone here is a way to go in long-term.

@Majkl578 Majkl578 transferred this issue from doctrine/common Oct 31, 2018
@malarzm
Copy link
Member

malarzm commented Nov 1, 2018

FWIW in ODM we ended up not introducing get method and @alcaeus had good points on why: doctrine/mongodb-odm#1613 (comment)

@drupol
Copy link
Contributor

drupol commented Dec 4, 2021

Sorry to dig up old topics but this is precisely the reason why I wrote a new package last week.

Find it here: https://github.com/loophp/repository-monadic-helper

It fixes the issue you're describing, and it's fully typed !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants