Skip to content

Commit

Permalink
add odm support to AddReturnDocBlockToCollectionPropertyGetterByToMan…
Browse files Browse the repository at this point in the history
…yAnnotationRector
  • Loading branch information
TomasVotruba committed Jul 25, 2024
1 parent df90845 commit d6d0f4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 35 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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<int, \\Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector\Source\Training>
*/
public function getItems()
{
return $this->items;
}
}

?>

2 changes: 1 addition & 1 deletion rules/CodeQuality/Enum/ToManyMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ToManyMappings
{
/**
* @var class-string[]
* @var string[]
*/
final public const TO_MANY_CLASSES = [
MappingClass::ONE_TO_MANY,
Expand Down
11 changes: 5 additions & 6 deletions src/TypeAnalyzer/CollectionTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d6d0f4f

Please sign in to comment.