From 8b3e3684b346dc4833001541ca56dab2feadd0e8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 25 Jul 2024 11:58:05 +0200 Subject: [PATCH] Add mapping class --- .../ExplicitRelationCollectionRector.php | 12 +++++++----- src/Enum/OdmMappingClass.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/Enum/OdmMappingClass.php diff --git a/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php b/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php index ecf425a9..58021769 100644 --- a/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php +++ b/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php @@ -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; @@ -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; } @@ -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; } diff --git a/src/Enum/OdmMappingClass.php b/src/Enum/OdmMappingClass.php new file mode 100644 index 00000000..d171b765 --- /dev/null +++ b/src/Enum/OdmMappingClass.php @@ -0,0 +1,18 @@ +