phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

ODM and ORM objectManagerLoader

Open vencakrecl opened this issue 2 years ago • 4 comments

Hi, I need to define both loaders (ODM and ORM) in same Symfony project, but configuration supports only one. Can you help me?

vencakrecl avatar Apr 19 '22 04:04 vencakrecl

Most features are now supported without needing loaders at all. I'm not sure how to solve your problem or if it needs to be solved at all.

ondrejmirtes avatar Apr 19 '22 04:04 ondrejmirtes

This is my problem without loader - custom repository:

/**
 * @method Notifications|null find($id, $lockMode = null, $lockVersion = null)
 * @method Notifications|null findOneBy(array $criteria, array $orderBy = null)
 * @method Notifications[]    findAll()
 * @method Notifications[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 *
 * @extends DocumentRepository<Notifications>
 */
class NotificationsRepository extends DocumentRepository

Property App\Services\User\UserManager::$notificationsRepository (App\Document\Repository\NotificationsRepository) does not accept Doctrine\ODM\MongoDB\Repository\DocumentRepository<App\Document\Notifications\Notifications>.

/**
 * @method TrialRequest|null find($id, $lockMode = null, $lockVersion = null)
 * @method TrialRequest|null findOneBy(array $criteria, array $orderBy = null)
 * @method TrialRequest[]    findAll()
 * @method TrialRequest[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 *
 * @extends EntityRepository<TrialRequest>
 */
class TrialRequestRepository extends EntityRepository
Property App\Services\User\UserManager::$trialRequestRepository (App\Entity\Repository\TrialRequestRepository) does not accept Doctrine\ORM\EntityRepository<App\Entity\TrialRequest>. 

vencakrecl avatar Apr 19 '22 04:04 vencakrecl

@VencaKrecl i know its a long time, but did you found a workaround for this issue?

@ondrejmirtes we have the same issue with a project which also has orm AND odm. I think there are less projects who has both orm and odm, but they exist. It would be great to find a solution for this.

Maybe we can extend the configuration like this:

parameters:
    doctrine:
        entityObjectManagerLoader: tests/doctrine-orm-bootstrap.php
        documentObjectManagerLoader: tests/doctrine-odm-bootstrap.php       

BenjaminLeibinger avatar Oct 12 '23 20:10 BenjaminLeibinger

@BenjaminLeibinger The workaround is to run phpstan two times with different configurations.

    ignoreErrors:
        - '#does not accept Doctrine\\Persistence\\ObjectManager#'
        - '#does not accept Doctrine\\ODM\\MongoDB\\Repository#'
    doctrine:
        objectManagerLoader: orm-object-manager.php
    ignoreErrors:
        - '#does not accept Doctrine\\Persistence\\ObjectManager#'
        - '#does not accept Doctrine\\ORM\\EntityRepository#'
    doctrine:
        objectManagerLoader: odm-object-manager.php

vencakrecl avatar Oct 13 '23 13:10 vencakrecl