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

issue with findOneByX #52

Closed
dmaicher opened this issue Feb 13, 2019 · 5 comments · Fixed by #56
Closed

issue with findOneByX #52

dmaicher opened this issue Feb 13, 2019 · 5 comments · Fixed by #56

Comments

@dmaicher
Copy link

In some repositories I have some custom functions named like findOneByX

Example:

class ReviewRepository
{
    public function findOneByReviewConfigAndId(...) { }
}

Seems that is not working properly:

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   someClass.php                                                                                                                                             
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  209    Call to method X\ReviewRepository<X\Entity\Review>::findOneByReviewConfigAndId() - entity X\Entity\Review does not have a field named  
         $reviewConfigAndId.                                                                                                                                                                         
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
@ondrejmirtes
Copy link
Member

I see - real method name clashes with the magic method convention.

@luxemate
Copy link
Contributor

luxemate commented Feb 16, 2019

@ondrejmirtes Today I ran into similar problem. Having repo like

class FooRepository
{
    public function findByDoesNotMatter(): ?Foo { }
}

results in PHPStan thinking it's an array because of findBy, not findOneBy.

 ------ ------------------------------------------------------------------------------------------ 
  Line   FooRepository.php  
 ------ ------------------------------------------------------------------------------------------ 
  36     Cannot call method someMethod() on array<int, Foo>.                                         
 ------ ------------------------------------------------------------------------------------------ 

Plus, real method clashes with the magic one.

@ondrejmirtes
Copy link
Member

I agree, will fix it. BTW I think you should adhere to the same convention and rename this method to findOneByDoesNotMatter because otherwise you're causing confusion for your developers :D

@luxemate
Copy link
Contributor

luxemate commented Feb 16, 2019

Yeah, that's what I did. Luckily, that was the only method that was out of convention.

@github-actions
Copy link

github-actions bot commented May 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants