diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php deleted file mode 100644 index 41e6d460..00000000 --- a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php +++ /dev/null @@ -1,25 +0,0 @@ -items; - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php.inc b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php.inc index 7a25f8d4..e0b12f0e 100644 --- a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php.inc +++ b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector/Fixture/Odm/orm_many.php.inc @@ -12,7 +12,7 @@ use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectio final class OdmMany { /** - * @\Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany() + * @\Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany(targetDocument="\Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector\Source\Training") */ private $items = []; @@ -38,10 +38,17 @@ use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectio final class OdmMany { /** - * @\Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany() + * @\Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany(targetDocument="\Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector\Source\Training") */ private $items = []; + + /** + * @return \Doctrine\Common\Collections\Collection + */ + public function getItems() + { + return $this->items; + } } ?> - diff --git a/rules/CodeQuality/Enum/ToManyMappings.php b/rules/CodeQuality/Enum/ToManyMappings.php index ccbbb027..acc462c2 100644 --- a/rules/CodeQuality/Enum/ToManyMappings.php +++ b/rules/CodeQuality/Enum/ToManyMappings.php @@ -10,7 +10,7 @@ class ToManyMappings { /** - * @var class-string[] + * @var string[] */ final public const TO_MANY_CLASSES = [ MappingClass::ONE_TO_MANY, diff --git a/src/TypeAnalyzer/CollectionTypeResolver.php b/src/TypeAnalyzer/CollectionTypeResolver.php index 1c552504..57419d8d 100644 --- a/src/TypeAnalyzer/CollectionTypeResolver.php +++ b/src/TypeAnalyzer/CollectionTypeResolver.php @@ -15,7 +15,6 @@ use Rector\BetterPhpDocParser\PhpDoc\StringNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Doctrine\CodeQuality\Enum\ToManyMappings; -use Rector\Doctrine\Enum\OdmMappingClass; use Rector\Doctrine\PhpDoc\ShortClassExpander; use Rector\StaticTypeMapper\Naming\NameScopeFactory; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; @@ -59,15 +58,15 @@ public function resolveFromToManyProperties(Property $property): ?FullyQualified } $targetEntityArrayItemNode = $doctrineAnnotationTagValueNode->getValue('targetEntity'); + // in case of odm + $targetDocumentArrayItemNode = $doctrineAnnotationTagValueNode->getValue('targetDocument'); - dump($targetEntityArrayItemNode); - die; - - if (! $targetEntityArrayItemNode instanceof ArrayItemNode) { + $targetArrayItemNode = $targetEntityArrayItemNode ?: $targetDocumentArrayItemNode; + if (! $targetArrayItemNode instanceof ArrayItemNode) { return null; } - $targetEntityClass = $targetEntityArrayItemNode->value; + $targetEntityClass = $targetArrayItemNode->value; if ($targetEntityClass instanceof StringNode) { $targetEntityClass = $targetEntityClass->value;