Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Fixture\ODM;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Source\TrainingTerm;

final class CollectionOfSuperClass
{
/**
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\EmbedMany()
*/
private ?Collection $trainingTerms = null;

public function __construct()
{
}
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Fixture\ODM;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector\Source\TrainingTerm;

final class CollectionOfSuperClass
{
/**
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\EmbedMany()
* @var \Doctrine\Common\Collections\Collection
*/
private \Doctrine\Common\Collections\Collection $trainingTerms;

public function __construct()
{
}
}

?>
4 changes: 3 additions & 1 deletion src/NodeManipulator/ToManyRelationPropertyTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
Expand Down Expand Up @@ -65,7 +66,8 @@ private function processToManyRelation(
EntityMappingKey::TARGET_ENTITY
) ?: $doctrineAnnotationTagValueNode->getValue(OdmMappingKey::TARGET_DOCUMENT);
if (! $targetEntityArrayItemNode instanceof ArrayItemNode) {
return null;
// most likely mapped superclass
return new ObjectType(DoctrineClass::COLLECTION);
}

$targetEntityClass = $targetEntityArrayItemNode->value;
Expand Down
Loading