Skip to content

Resolve entity metadata without objectManagerLoader #253

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

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

ondrejmirtes
Copy link
Member

No description provided.

@VincentLanglet
Copy link
Contributor

Does the https://github.com/phpstan/phpstan-doctrine#configuration doc should be updated then ?

For instance to list features which still require the objectManagerLoader.

@ondrejmirtes ondrejmirtes merged commit 6fc5407 into master Jan 21, 2022
@ondrejmirtes
Copy link
Member Author

670e28d ;)

@VincentLanglet
Copy link
Contributor

670e28d ;)

Thanks.

I tried the master branch on my project and I have some issues that I don't have with my customObjectManager (cf #218).

$queryBuilder = $this->getDocumentManager()->getRepository(LogDocument::class)->createQueryBuilder();

Method Doctrine\ORM\EntityRepository<App\Document\LogDocument>::createQueryBuilder() invoked with 0 parameters, 1-2 required.

Here the Repository should be considered as a Doctrine\ODM\MongoDB\Repository. I have the same error for multiple Document.

$expeditions = $this->getEntityManager()->getRepository(Expedition::class)->getListOrders($context, $date);

Call to an undefined method Doctrine\ORM\EntityRepository<App\Entity\Expedition>::getListOrders(). Weird thing, I only have the issue with the repository of the Expedition class...

What can I do to help to debug this ?

@ondrejmirtes
Copy link
Member Author

What's gonna help me here is:

\PHPStan\dumpType($this->getDocumentManager());
\PHPStan\dumpType($this->getDocumentManager()->getRepository(LogDocument::class));

What's the actual output and what's the expected output?

@ondrejmirtes
Copy link
Member Author

And about Expedition - where is the getListOrders method defined, and does the Expedition entity have a repositoryClass setting in @ORM\Entity?

@VincentLanglet
Copy link
Contributor

What's gonna help me here is:

\PHPStan\dumpType($this->getDocumentManager());
\PHPStan\dumpType($this->getDocumentManager()->getRepository(LogDocument::class));

What's the actual output and what's the expected output?

145 Dumped type: Doctrine\ODM\MongoDB\DocumentManager
146 Dumped type: Doctrine\ORM\EntityRepository<App\Document\LogDocument>

Expected type would be 'Doctrine\ODM\MongoDB\Repository\DocumentRepository'

IMHO, it's the same issue that I was trying to solve in https://github.com/phpstan/phpstan-doctrine/pull/218/files#diff-2ffdfff3ded45d084e0d7d312fe16939835dba7dcad8fabc12a2c3ece495b46aR113-R124

Since I use both ORM and ODM, I shouldn't fallback on $this->getResolvedRepositoryClass(); because I have a fallback for ORM and a fallback for ODM ; but phpstan only save the first one met (EntityRepository) in the getResolvedRepositoryClass method.

@ondrejmirtes
Copy link
Member Author

Yeah, this is definitely doable, I'm gonna fix it.

@VincentLanglet
Copy link
Contributor

        $listProductAsset = $this->getEntityManager()->getRepository(Asset::class)->findAllByProductId(1);
        $expeditions = $this->getEntityManager()->getRepository(Expedition::class)->getListOrders($context, $date);

        \PHPStan\dumpType($this->getEntityManager());
        \PHPStan\dumpType($this->getEntityManager()->getRepository(Asset::class));
        \PHPStan\dumpType($this->getEntityManager()->getRepository(Expedition::class));

is giving me

  43     Call to an undefined method Doctrine\ORM\EntityRepository<App\Entity\Expedition>::getListOrders().  
  45     Dumped type: App\Core\Doctrine\ORM\EntityManager                                                    
  46     Dumped type: App\Repository\AssetRepository<App\Entity\Asset>                                       
  47     Dumped type: Doctrine\ORM\EntityRepository<App\Entity\Expedition> 

Expedition has the phpdoc

/**
 * @ORM\Table(name="tbl_expedition")
 * @ORM\Entity(repositoryClass="App\Repository\ExpeditionRepository")
 */
class Expedition extends BaseEntity implements EntityInterface

But I found that the issue is related to Embeddable. I have a field

/**
 * @ORM\Embedded(class="App\Entity\Embeddable\Slot")
 */
private ?Slot $slot = null;

Removing it fix my issue. Should I open an issue ?

@ondrejmirtes
Copy link
Member Author

Yeah, definitely open an issue.

@ondrejmirtes
Copy link
Member Author

This should be fine: f66919f

Please note the new different ormRepositoryClass / odmRepositoryClass config parameters for setting base repository classes if you have one.

@VincentLanglet
Copy link
Contributor

This should be fine: f66919f

Please note the new different ormRepositoryClass / odmRepositoryClass config parameters for setting base repository classes if you have one.

Thanks, it does work for me.

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

Successfully merging this pull request may close these issues.

2 participants