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

LessSpecificImplementedReturnType false-positive #71

Closed
fluffycondor opened this issue Sep 24, 2020 · 4 comments
Closed

LessSpecificImplementedReturnType false-positive #71

fluffycondor opened this issue Sep 24, 2020 · 4 comments

Comments

@fluffycondor
Copy link
Contributor

fluffycondor commented Sep 24, 2020

LessSpecificImplementedReturnType - src/Repository/SomethingRepository.php:9:12 - The inherited return type 'list<App\Entity\Something>' for Doctrine\ORM\EntityRepository::findAll is more specific than the implemented return type for Doctrine\ORM\EntityRepository::findall 'array<array-key, App\Entity\Something>'

Code in my SomethingRepository:

/**
 * @method Something[]    findAll() (this PHPDoc was auto-generated by Symfony)
 * @extends ServiceEntityRepository<Something>
 */
class SomethingRepository extends ServiceEntityRepository
{
 */

This is a snippet from Doctrine\ORM\EntityRepository

/**
 * Finds all entities in the repository.
 *
 * @return array The entities.
 */
public function findAll()
{
    return $this->findBy([]);
}

Just an array.

This is from Doctrine\Persistence\ObjectRepository that implemented by Doctrine\ORM\EntityRepository:

/**
 * Contract for a Doctrine persistence layer ObjectRepository class to implement.
 *
 * @template T
 */
interface ObjectRepository
{
.....

    /**
     * Finds all objects in the repository.
     *
     * @return array<int, object> The objects.
     *
     * @psalm-return T[]
     */
    public function findAll();
....
}

So it returns just T[], Something[] in my case.

Looks like there is a problem in the plugin's stub files.

@weirdan
Copy link
Member

weirdan commented Sep 25, 2020

As far as I can see (based on comments in this doctrine/persistence PR), there's indeed a problem with ObjectRepository stub where findAll() should return T[], but there's no issue with descendant return types. ORM repository actually returns list<T>.

@fluffycondor
Copy link
Contributor Author

Is there any info when there will be a new release with all of the bugfixes? :)

@weirdan
Copy link
Member

weirdan commented Sep 28, 2020

I want to fix remaining deprecation errors first, so it would be some time next week.

@weirdan weirdan closed this as completed Jan 3, 2021
@nsetyo
Copy link

nsetyo commented Jan 31, 2022

@weirdan I'm still getting this error
image

Based what I see ServiceEntityRepository extends EntityRepository and in EntityRepository findAll still return list<T>
How should I fix this?

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

3 participants