Skip to content

Commit 5b72bb2

Browse files
authored
Add mapped superclass case to ToManyRelationPropertyTypeResolver (#387)
1 parent 2e42ddd commit 5b72bb2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Fixture\ODM;
4+
5+
use Doctrine\Common\Collections\ArrayCollection;
6+
use Doctrine\Common\Collections\Collection;
7+
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Source\TrainingTerm;
8+
9+
final class CollectionOfSuperClass
10+
{
11+
/**
12+
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\EmbedMany()
13+
*/
14+
private ?Collection $trainingTerms = null;
15+
16+
public function __construct()
17+
{
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Fixture\ODM;
26+
27+
use Doctrine\Common\Collections\ArrayCollection;
28+
use Doctrine\Common\Collections\Collection;
29+
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Source\TrainingTerm;
30+
31+
final class CollectionOfSuperClass
32+
{
33+
/**
34+
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\EmbedMany()
35+
* @var \Doctrine\Common\Collections\Collection
36+
*/
37+
private \Doctrine\Common\Collections\Collection $trainingTerms;
38+
39+
public function __construct()
40+
{
41+
}
42+
}
43+
44+
?>

src/NodeManipulator/ToManyRelationPropertyTypeResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\Expr;
88
use PhpParser\Node\Param;
99
use PhpParser\Node\Stmt\Property;
10+
use PHPStan\Type\ObjectType;
1011
use PHPStan\Type\Type;
1112
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
1213
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
@@ -65,7 +66,8 @@ private function processToManyRelation(
6566
EntityMappingKey::TARGET_ENTITY
6667
) ?: $doctrineAnnotationTagValueNode->getValue(OdmMappingKey::TARGET_DOCUMENT);
6768
if (! $targetEntityArrayItemNode instanceof ArrayItemNode) {
68-
return null;
69+
// most likely mapped superclass
70+
return new ObjectType(DoctrineClass::COLLECTION);
6971
}
7072

7173
$targetEntityClass = $targetEntityArrayItemNode->value;

0 commit comments

Comments
 (0)