Skip to content

Commit

Permalink
Add mapping class
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 25, 2024
1 parent ab09af5 commit 8b3e368
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use Rector\Doctrine\Enum\MappingClass;
use Rector\Doctrine\Enum\OdmMappingClass;
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
use Rector\Doctrine\NodeFactory\ArrayCollectionAssignFactory;
use Rector\NodeManipulator\ClassDependencyManipulator;
Expand Down Expand Up @@ -86,8 +88,8 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
if (
! $this->attrinationFinder->hasByOne($node, 'Doctrine\\ORM\\Mapping\\Entity') &&
! $this->attrinationFinder->hasByOne($node, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document')
! $this->attrinationFinder->hasByOne($node, MappingClass::ENTITY) &&
! $this->attrinationFinder->hasByOne($node, OdmMappingClass::DOCUMENT)
) {
return null;
}
Expand All @@ -96,9 +98,9 @@ public function refactor(Node $node): ?Node

foreach ($node->getProperties() as $property) {
if (! $this->attrinationFinder->hasByMany($property, [
'Doctrine\\ORM\\Mapping\\OneToMany',
'Doctrine\\ORM\\Mapping\\ManyToMany',
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany',
MappingClass::ONE_TO_MANY,
MappingClass::MANY_TO_MANY,
OdmMappingClass::REFERENCE_MANY,
])) {
continue;
}
Expand Down
18 changes: 18 additions & 0 deletions src/Enum/OdmMappingClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Enum;

final class OdmMappingClass
{
/**
* @var string
*/
public const DOCUMENT = 'Doctrine\ODM\MongoDB\Mapping\Annotations\Document';

/**
* @var string
*/
public const REFERENCE_MANY = 'Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceMany';
}

0 comments on commit 8b3e368

Please sign in to comment.