From 399b69a309f98769724f3a395bb72fc39f2aa5b0 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sat, 11 Sep 2021 13:53:20 +0200 Subject: [PATCH] Fix return type at `EntityManagerInterface::get(Partial)Reference()` (#8922) --- lib/Doctrine/ORM/EntityManagerInterface.php | 9 +++++++-- phpstan-baseline.neon | 14 ++++++++++++-- psalm-baseline.xml | 8 ++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index fafa33abaf3..1358f435745 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -23,6 +23,7 @@ use BadMethodCallException; use DateTimeInterface; use Doctrine\Common\EventManager; +use Doctrine\Common\Proxy\Proxy; use Doctrine\DBAL\Connection; use Doctrine\ORM\Internal\Hydration\AbstractHydrator; use Doctrine\ORM\Proxy\ProxyFactory; @@ -169,7 +170,7 @@ public function createQueryBuilder(); * @psalm-param class-string $entityName * * @return object|null The entity reference. - * @psalm-return ?T + * @psalm-return (T&Proxy)|null * * @throws ORMException * @@ -194,8 +195,12 @@ public function getReference($entityName, $id); * * @param string $entityName The name of the entity type. * @param mixed $identifier The entity identifier. + * @psalm-param class-string $entityName + * + * @return object|null The (partial) entity reference + * @psalm-return (T&Proxy)|null * - * @return object|null The (partial) entity reference. + * @template T */ public function getPartialReference($entityName, $identifier); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 05c22cfdcbc..f54e5aba1ff 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -161,12 +161,22 @@ parameters: path: lib/Doctrine/ORM/EntityManager.php - - message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getPartialReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\.$#" count: 1 path: lib/Doctrine/ORM/EntityManager.php - - message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns object\\|null\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getPartialReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\|null\\.$#" + count: 1 + path: lib/Doctrine/ORM/EntityManager.php + + - + message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#" + count: 1 + path: lib/Doctrine/ORM/EntityManager.php + + - + message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\|null\\.$#" count: 1 path: lib/Doctrine/ORM/EntityManager.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 3a0372a450b..6354a33983b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -487,18 +487,22 @@ is_object($entity) is_object($entity) - + $entity $entity $entity + $entity + $entity instanceof $class->name ? $entity : null $entity instanceof $class->name ? $entity : null $persister->load($sortedId, null, null, [], $lockMode) $persister->loadById($sortedId) + $this->find($entityName, $sortedId) $this->metadataFactory->getMetadataFor($className) - + ?T getClassMetadata + getPartialReference getReference