Skip to content

Commit 5a4a92c

Browse files
committed
Fix return type at EntityManagerInterface::get(Partial)Reference()
1 parent df50861 commit 5a4a92c

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/Doctrine/ORM/EntityManagerInterface.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use BadMethodCallException;
2424
use DateTimeInterface;
2525
use Doctrine\Common\EventManager;
26+
use Doctrine\Common\Proxy\Proxy;
2627
use Doctrine\DBAL\Connection;
2728
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
2829
use Doctrine\ORM\Proxy\ProxyFactory;
@@ -169,7 +170,7 @@ public function createQueryBuilder();
169170
* @psalm-param class-string<T> $entityName
170171
*
171172
* @return object|null The entity reference.
172-
* @psalm-return ?T
173+
* @psalm-return (T&Proxy)|null
173174
*
174175
* @throws ORMException
175176
*
@@ -194,8 +195,12 @@ public function getReference($entityName, $id);
194195
*
195196
* @param string $entityName The name of the entity type.
196197
* @param mixed $identifier The entity identifier.
198+
* @psalm-param class-string<T> $entityName
199+
*
200+
* @return object|null The (partial) entity reference
201+
* @psalm-return (T&Proxy)|null
197202
*
198-
* @return object|null The (partial) entity reference.
203+
* @template T
199204
*/
200205
public function getPartialReference($entityName, $identifier);
201206

phpstan-baseline.neon

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,22 @@ parameters:
161161
path: lib/Doctrine/ORM/EntityManager.php
162162

163163
-
164-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#"
164+
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getPartialReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\.$#"
165165
count: 1
166166
path: lib/Doctrine/ORM/EntityManager.php
167167

168168
-
169-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns object\\|null\\.$#"
169+
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getPartialReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\|null\\.$#"
170+
count: 1
171+
path: lib/Doctrine/ORM/EntityManager.php
172+
173+
-
174+
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#"
175+
count: 1
176+
path: lib/Doctrine/ORM/EntityManager.php
177+
178+
-
179+
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return \\(Doctrine\\\\Common\\\\Proxy\\\\Proxy&T\\)\\|null but returns object\\|null\\.$#"
170180
count: 1
171181
path: lib/Doctrine/ORM/EntityManager.php
172182

psalm-baseline.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,22 @@
481481
<code>is_object($entity)</code>
482482
<code>is_object($entity)</code>
483483
</DocblockTypeContradiction>
484-
<InvalidReturnStatement occurrences="7">
484+
<InvalidReturnStatement occurrences="10">
485485
<code>$entity</code>
486486
<code>$entity</code>
487487
<code>$entity</code>
488+
<code>$entity</code>
489+
<code>$entity instanceof $class-&gt;name ? $entity : null</code>
488490
<code>$entity instanceof $class-&gt;name ? $entity : null</code>
489491
<code>$persister-&gt;load($sortedId, null, null, [], $lockMode)</code>
490492
<code>$persister-&gt;loadById($sortedId)</code>
493+
<code>$this-&gt;find($entityName, $sortedId)</code>
491494
<code>$this-&gt;metadataFactory-&gt;getMetadataFor($className)</code>
492495
</InvalidReturnStatement>
493-
<InvalidReturnType occurrences="3">
496+
<InvalidReturnType occurrences="4">
494497
<code>?T</code>
495498
<code>getClassMetadata</code>
499+
<code>getPartialReference</code>
496500
<code>getReference</code>
497501
</InvalidReturnType>
498502
<InvalidScalarArgument occurrences="2">

0 commit comments

Comments
 (0)