Skip to content

Commit

Permalink
Add odm support to ExplicitRelationCollectionRector
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 25, 2024
1 parent 9b7efa4 commit ab09af5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\ExplicitRelationCollectionRector\Fixture;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\ManyToMany;

/**
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\Document
*/
class OdmDocument
{
/**
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany()
*/
private $items = [];
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\ExplicitRelationCollectionRector\Fixture;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\ManyToMany;

/**
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\Document
*/
class OdmDocument
{
/**
* @\Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany()
*/
private \Doctrine\Common\Collections\Collection $items;
public function __construct()
{
$this->items = new \Doctrine\Common\Collections\ArrayCollection();
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,20 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (! $this->attrinationFinder->hasByOne($node, 'Doctrine\ORM\Mapping\Entity')) {
if (
! $this->attrinationFinder->hasByOne($node, 'Doctrine\\ORM\\Mapping\\Entity') &&
! $this->attrinationFinder->hasByOne($node, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document')
) {
return null;
}

$arrayCollectionAssigns = [];

foreach ($node->getProperties() as $property) {
if (! $this->attrinationFinder->hasByMany($property, [
'Doctrine\ORM\Mapping\OneToMany',
'Doctrine\ORM\Mapping\ManyToMany',
'Doctrine\\ORM\\Mapping\\OneToMany',
'Doctrine\\ORM\\Mapping\\ManyToMany',
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany',
])) {
continue;
}
Expand Down

0 comments on commit ab09af5

Please sign in to comment.