Skip to content

Commit 3d3fbc0

Browse files
committed
Use repositoryClass as default
1 parent a9d33a5 commit 3d3fbc0

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

extension.neon

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ parameters:
22
doctrine:
33
repositoryClass: Doctrine\ORM\EntityRepository
44
allCollectionsSelectable: true
5-
objectManagerLoader: ~
5+
objectManagerLoader: null
66

77
conditionalTags:
88
PHPStan\Reflection\Doctrine\DoctrineSelectableClassReflectionExtension:
@@ -33,11 +33,10 @@ services:
3333
- phpstan.broker.dynamicMethodReturnTypeExtension
3434
-
3535
class: PHPStan\Type\Doctrine\ManagerRegistryGetRepositoryDynamicReturnTypeExtension
36-
arguments:
37-
repositoryClass: %doctrine.repositoryClass%
3836
tags:
3937
- phpstan.broker.dynamicMethodReturnTypeExtension
4038
-
4139
class: PHPStan\Type\Doctrine\ObjectMetadataResolver
4240
arguments:
4341
objectManagerLoader: %doctrine.objectManagerLoader%
42+
repositoryClass: %doctrine.repositoryClass%

src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public function getTypeFromMethodCall(
4545
$objectName = $argType->getValue();
4646
$repositoryClass = $this->metadataResolver->getRepositoryClass($objectName);
4747

48-
if ($repositoryClass === null) {
49-
return new MixedType();
50-
}
51-
5248
return new ObjectRepositoryType($objectName, $repositoryClass);
5349
}
5450

src/Type/Doctrine/ObjectMetadataResolver.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
final class ObjectMetadataResolver
1313
{
1414

15-
/** @var ObjectManager */
15+
/** @var ?ObjectManager */
1616
private $objectManager;
1717

18-
public function __construct(string $objectManagerLoader)
18+
/** @var string */
19+
private $repositoryClass;
20+
21+
public function __construct(?string $objectManagerLoader, string $repositoryClass)
1922
{
20-
$this->objectManager = $this->getObjectManager($objectManagerLoader);
23+
if ($objectManagerLoader !== null) {
24+
$this->objectManager = $this->getObjectManager($objectManagerLoader);
25+
}
26+
$this->repositoryClass = $repositoryClass;
2127
}
2228

2329
private function getObjectManager(string $objectManagerLoader): ObjectManager
@@ -29,8 +35,12 @@ private function getObjectManager(string $objectManagerLoader): ObjectManager
2935
return require $objectManagerLoader;
3036
}
3137

32-
public function getRepositoryClass(string $className): ?string
38+
public function getRepositoryClass(string $className): string
3339
{
40+
if ($this->objectManager === null) {
41+
return $this->repositoryClass;
42+
}
43+
3444
$metadata = $this->objectManager->getClassMetadata($className);
3545

3646
if ($metadata instanceof ORMMetadata) {
@@ -41,7 +51,7 @@ public function getRepositoryClass(string $className): ?string
4151
return $metadata->customRepositoryClassName ?? 'Doctrine\ODM\MongoDB\DocumentRepository';
4252
}
4353

44-
return null;
54+
return $this->repositoryClass;
4555
}
4656

4757
}

0 commit comments

Comments
 (0)