Skip to content

Commit 000dc25

Browse files
committed
EntityRelationRule - catch MappingException
1 parent cab43df commit 000dc25

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Rules/Doctrine/ORM/EntityRelationRule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public function processNode(Node $node, Scope $scope): array
5252
return [];
5353
}
5454

55-
$metadata = $objectManager->getClassMetadata($className);
55+
try {
56+
$metadata = $objectManager->getClassMetadata($className);
57+
} catch (\Doctrine\ORM\Mapping\MappingException $e) {
58+
return [];
59+
}
60+
5661
$classMetadataInfo = 'Doctrine\ORM\Mapping\ClassMetadataInfo';
5762
if (!$metadata instanceof $classMetadataInfo) {
5863
return [];

tests/Rules/Doctrine/ORM/data/EntityWithRelations.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,28 @@ class EntityWithRelations
5252
*/
5353
private $never;
5454

55+
/**
56+
* @ORM\OneToMany(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity", mappedBy="manyToOne")
57+
* @var \Doctrine\Common\Collections\Collection<AnotherEntity>
58+
*/
59+
private $genericCollection;
60+
61+
/**
62+
* @ORM\OneToMany(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity", mappedBy="manyToOne")
63+
* @var \Doctrine\Common\Collections\Collection<mixed, AnotherEntity>
64+
*/
65+
private $genericCollection2;
66+
67+
/**
68+
* @ORM\OneToMany(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity", mappedBy="manyToOne")
69+
* @var \Doctrine\Common\Collections\Collection<int, AnotherEntity>
70+
*/
71+
private $genericCollection3;
72+
73+
/**
74+
* @ORM\OneToMany(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
75+
* @var \Doctrine\Common\Collections\Collection<int, AnotherEntity>
76+
*/
77+
private $brokenCollectionAnnotation;
78+
5579
}

0 commit comments

Comments
 (0)