Skip to content

Repository return type errors when using multiple entity managers #655

Open
@tedyno

Description

@tedyno

php 8.3
phpstan 2

repository with reproduced issue: https://github.com/tedyno/phpstan-multiple-em-issue
phpstan ran with multiple object managers: https://github.com/tedyno/phpstan-multiple-em-issue/actions/runs/14328251812
phpstan an with single object manager: https://github.com/tedyno/phpstan-multiple-em-issue/actions/runs/14328261334

Hi, I'm having an issue to make phpstan work correctly when using multiple object managers. I followed a comment by @adrienbrault as I could not find any other way and there's a problem with recognizing correct return type.

// src/Repository/UserRepository.php

    /**
     * @return User[]
     */
    public function get() : array
    {
        $query = $this->createQueryBuilder('c')
            ->getQuery();

        return $query->getResult();
    }

this simple query throws this when running phpstan

Method App\Repository\UserRepository::get() should return array<App\Entity\Main\User> but returns mixed.

When using object-manager.php from readme, the errors shows up only for EntityRepository of an Entity which is in the other manager indicating it resolved the return type correctly in UserRepository.

Could you advise how to proceed?

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