Skip to content

PHPDoc tag @var with type UserRepository is not subtype of type UserRepository<User>. #630

Open
@whataboutpereira

Description

@whataboutpereira

I'm looking at upgrading to v2.0 and just turned on bleeding edge. This has resulted in these errors being reported for Doctrine repositories.

PHPDoc tag @var with type App\Repository\UserRepository is not subtype of type App\Repository\UserRepository<App\Entity\User>

The repository is defined like this:

/**
 * @extends ServiceEntityRepository<User>
 */
class UserRepository extends ServiceEntityRepository {}

And the error is triggered by this:

/** @var UserRepository */
$userRepository = $entityManager->getRepository(User::class);

I see I can quieten the error by removing the docblock, but I need /** @var UserRepository */ to appease my IDE and for it to pick up methods from the repository.

It hasn't been giving an error without bleeding edge.

How can I work around this short of ignoring the error completely?

I'm not actually sure whether this is caused by phpstan itself or the Doctrine extension.

phpstan v1.12.11
phpstan-doctrine v1.5.6
phpstan/phpstan-symfony 1.4.12

Thanks!

Activity

InvisibleSmiley

InvisibleSmiley commented on Jan 13, 2025

@InvisibleSmiley

It is caused by this extension, namely GetRepositoryDynamicReturnTypeExtension.

It determines the repository class and then creates a generic type from that:

new GenericObjectType($repositoryClass, [$classType])

when in fact the repository class is already generic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      PHPDoc tag @var with type UserRepository is not subtype of type UserRepository<User>. · Issue #630 · phpstan/phpstan-doctrine