diff --git a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EmbeddableClassAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EmbeddableClassAttributeTransformer.php index 7b1ea62d..7bba8e24 100644 --- a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EmbeddableClassAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EmbeddableClassAttributeTransformer.php @@ -12,16 +12,17 @@ final class EmbeddableClassAttributeTransformer implements ClassAttributeTransformerInterface { - public function transform(EntityMapping $entityMapping, Class_ $class): void + public function transform(EntityMapping $entityMapping, Class_ $class): bool { $classMapping = $entityMapping->getClassMapping(); $type = $classMapping['type'] ?? null; if ($type !== 'embeddable') { - return; + return false; } $class->attrGroups[] = AttributeFactory::createGroup($this->getClassName()); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EntityClassAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EntityClassAttributeTransformer.php index 1334cac7..c2ca684e 100644 --- a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EntityClassAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/EntityClassAttributeTransformer.php @@ -19,13 +19,13 @@ final class EntityClassAttributeTransformer implements ClassAttributeTransformer */ private const REPOSITORY_CLASS_KEY = 'repositoryClass'; - public function transform(EntityMapping $entityMapping, Class_ $class): void + public function transform(EntityMapping $entityMapping, Class_ $class): bool { $classMapping = $entityMapping->getClassMapping(); $type = $classMapping['type'] ?? null; if ($type !== 'entity') { - return; + return false; } $args = []; @@ -37,6 +37,7 @@ public function transform(EntityMapping $entityMapping, Class_ $class): void } $class->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/InheritanceClassAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/InheritanceClassAttributeTransformer.php index 9df9f01a..14b173b9 100644 --- a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/InheritanceClassAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/InheritanceClassAttributeTransformer.php @@ -24,13 +24,13 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Class_ $class): void + public function transform(EntityMapping $entityMapping, Class_ $class): bool { $classMapping = $entityMapping->getClassMapping(); $inheritanceType = $classMapping['inheritanceType'] ?? null; if ($inheritanceType === null) { - return; + return false; } $class->attrGroups[] = AttributeFactory::createGroup(MappingClass::INHERITANCE_TYPE, [$inheritanceType]); @@ -45,6 +45,7 @@ public function transform(EntityMapping $entityMapping, Class_ $class): void if (isset($classMapping['discriminatorMap'])) { $this->addDiscriminatorMap($classMapping['discriminatorMap'], $class); } + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/SoftDeletableClassAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/SoftDeletableClassAttributeTransformer.php index 9f302042..9c59d45c 100644 --- a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/SoftDeletableClassAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/SoftDeletableClassAttributeTransformer.php @@ -20,13 +20,13 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Class_ $class): void + public function transform(EntityMapping $entityMapping, Class_ $class): bool { $classMapping = $entityMapping->getClassMapping(); $softDeletableMapping = $classMapping['gedmo']['soft_deleteable'] ?? null; if (! is_array($softDeletableMapping)) { - return; + return false; } $args = $this->nodeFactory->createArgs($softDeletableMapping); @@ -40,6 +40,7 @@ public function transform(EntityMapping $entityMapping, Class_ $class): void } $class->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/TableClassAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/TableClassAttributeTransformer.php index 53ae050b..35f8ac2f 100644 --- a/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/TableClassAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/ClassAttributeTransformer/TableClassAttributeTransformer.php @@ -24,13 +24,13 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Class_ $class): void + public function transform(EntityMapping $entityMapping, Class_ $class): bool { $classMapping = $entityMapping->getClassMapping(); $table = $classMapping[self::TABLE_KEY] ?? null; if (isset($classMapping['type']) && $classMapping['type'] !== 'entity') { - return; + return false; } $args = []; @@ -42,6 +42,7 @@ public function transform(EntityMapping $entityMapping, Class_ $class): void $this->addIndexes($classMapping['indexes'] ?? [], $class, MappingClass::INDEX); $this->addIndexes($classMapping['uniqueConstraints'] ?? [], $class, MappingClass::UNIQUE_CONSTRAINT); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ColumnAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ColumnAttributeTransformer.php index af0e259a..eec1a000 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ColumnAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ColumnAttributeTransformer.php @@ -20,11 +20,11 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $propertyMapping = $entityMapping->matchFieldPropertyMapping($property); if ($propertyMapping === null) { - return; + return false; } // handled in another mapper @@ -42,6 +42,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property $args = array_merge($args, $this->nodeFactory->createArgs($propertyMapping)); $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/EmbeddedPropertyAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/EmbeddedPropertyAttributeTransformer.php index dc783748..31ab97ea 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/EmbeddedPropertyAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/EmbeddedPropertyAttributeTransformer.php @@ -20,11 +20,11 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $propertyMapping = $entityMapping->matchEmbeddedPropertyMapping($property); if ($propertyMapping === null) { - return; + return false; } // handled in another attribute @@ -34,6 +34,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); NodeValueNormalizer::ensureKeyIsClassConstFetch($args, 'class'); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/GedmoTimestampableAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/GedmoTimestampableAttributeTransformer.php index fe38663e..daf11705 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/GedmoTimestampableAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/GedmoTimestampableAttributeTransformer.php @@ -19,17 +19,18 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $fieldPropertyMapping = $entityMapping->matchFieldPropertyMapping($property); $timestampableMapping = $fieldPropertyMapping['gedmo']['timestampable'] ?? null; if (! is_array($timestampableMapping)) { - return; + return false; } $args = $this->nodeFactory->createArgs($timestampableMapping); $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdAttributeTransformer.php index 53a5e760..7eba2e57 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdAttributeTransformer.php @@ -13,14 +13,15 @@ final class IdAttributeTransformer implements PropertyAttributeTransformerInterface { - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $idMapping = $entityMapping->matchIdPropertyMapping($property); if (! is_array($idMapping)) { - return; + return false; } $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName()); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdColumnAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdColumnAttributeTransformer.php index c1bb8697..e8161bf1 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdColumnAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdColumnAttributeTransformer.php @@ -13,11 +13,11 @@ final class IdColumnAttributeTransformer implements PropertyAttributeTransformerInterface { - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $idMapping = $entityMapping->matchIdPropertyMapping($property); if (! is_array($idMapping)) { - return; + return false; } $args = []; @@ -28,6 +28,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property } $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdGeneratorAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdGeneratorAttributeTransformer.php index 2182c0a8..4f598a0c 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdGeneratorAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdGeneratorAttributeTransformer.php @@ -27,16 +27,16 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $idMapping = $entityMapping->matchIdPropertyMapping($property); if (! is_array($idMapping)) { - return; + return false; } $generator = $idMapping[EntityMappingKey::GENERATOR] ?? null; if (! is_array($generator)) { - return; + return false; } // make sure strategy is uppercase as constant value @@ -44,6 +44,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property $args = $this->nodeFactory->createArgs($generator); $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/InverseJoinColumnAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/InverseJoinColumnAttributeTransformer.php index 1c358220..2680ed56 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/InverseJoinColumnAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/InverseJoinColumnAttributeTransformer.php @@ -20,21 +20,22 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $joinTableMapping = $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null; if (! is_array($joinTableMapping)) { - return; + return false; } $joinColumns = $joinTableMapping['inverseJoinColumns'] ?? null; if (! is_array($joinColumns)) { - return; + return false; } foreach ($joinColumns as $columnName => $joinColumn) { $property->attrGroups[] = $this->createInverseJoinColumnAttrGroup($columnName, $joinColumn); } + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinColumnAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinColumnAttributeTransformer.php index 22a00c33..4ffa6e03 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinColumnAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinColumnAttributeTransformer.php @@ -20,13 +20,17 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { - $this->transformMapping( + $hasChangedManyToMany = $this->transformMapping( $property, $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null ); - $this->transformMapping($property, $entityMapping->matchManyToOnePropertyMapping($property)); + $hasChangedManyToOne = $this->transformMapping( + $property, + $entityMapping->matchManyToOnePropertyMapping($property) + ); + return $hasChangedManyToMany || $hasChangedManyToOne; } public function getClassName(): string @@ -37,10 +41,10 @@ public function getClassName(): string /** * @param array>|null $mapping */ - private function transformMapping(Property|Param $property, ?array $mapping): void + private function transformMapping(Property|Param $property, ?array $mapping): bool { if (! is_array($mapping)) { - return; + return false; } $singleJoinColumn = $mapping['joinColumn'] ?? null; @@ -52,12 +56,15 @@ private function transformMapping(Property|Param $property, ?array $mapping): vo $joinColumns = $mapping['joinColumns'] ?? null; if (! is_array($joinColumns)) { - return; + return false; } + $hasChanged = false; foreach ($joinColumns as $columnName => $joinColumn) { + $hasChanged = true; $property->attrGroups[] = $this->createJoinColumnAttrGroup($columnName, $joinColumn); } + return $hasChanged; } private function createJoinColumnAttrGroup(int|string $columnName, mixed $joinColumn): AttributeGroup diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php index 11bce03f..e738cced 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php @@ -21,11 +21,11 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $joinTableMapping = $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null; if (! is_array($joinTableMapping)) { - return; + return false; } // handled by another mapper @@ -35,6 +35,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToManyAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToManyAttributeTransformer.php index cc19554d..d42b430d 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToManyAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToManyAttributeTransformer.php @@ -21,11 +21,11 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $manyToManyMapping = $entityMapping->matchManyToManyPropertyMapping($property); if (! is_array($manyToManyMapping)) { - return; + return false; } // handled by another mapper @@ -35,6 +35,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToOneAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToOneAttributeTransformer.php index 6226cf20..766000c6 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToOneAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToOneAttributeTransformer.php @@ -21,11 +21,11 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $manyToOneMapping = $entityMapping->matchManyToOnePropertyMapping($property); if (! is_array($manyToOneMapping)) { - return; + return false; } // handled by another mapper @@ -38,6 +38,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OneToManyAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OneToManyAttributeTransformer.php index 512448b2..cd775175 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OneToManyAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OneToManyAttributeTransformer.php @@ -21,11 +21,11 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $oneToManyMapping = $entityMapping->matchOneToManyPropertyMapping($property); if (! is_array($oneToManyMapping)) { - return; + return false; } // handled by OrderBy mapping rule as standalone entity class @@ -35,6 +35,7 @@ public function transform(EntityMapping $entityMapping, Property|Param $property NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY); $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php index 0a47638d..068bbfa1 100644 --- a/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php @@ -20,22 +20,23 @@ public function __construct( ) { } - public function transform(EntityMapping $entityMapping, Property|Param $property): void + public function transform(EntityMapping $entityMapping, Property|Param $property): bool { $oneToManyMapping = $entityMapping->matchOneToManyPropertyMapping($property); if (! is_array($oneToManyMapping)) { - return; + return false; } // we handle OrderBy here only if (! isset($oneToManyMapping[EntityMappingKey::ORDER_BY])) { - return; + return false; } $orderBy = $oneToManyMapping[EntityMappingKey::ORDER_BY]; $args = $this->nodeFactory->createArgs([$orderBy]); $property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args); + return true; } public function getClassName(): string diff --git a/rules/CodeQuality/AttributeTransformer/YamlToAttributeTransformer.php b/rules/CodeQuality/AttributeTransformer/YamlToAttributeTransformer.php index 4dcf77aa..9ca11ab5 100644 --- a/rules/CodeQuality/AttributeTransformer/YamlToAttributeTransformer.php +++ b/rules/CodeQuality/AttributeTransformer/YamlToAttributeTransformer.php @@ -25,39 +25,49 @@ public function __construct( ) { } - public function transform(Class_ $class, EntityMapping $entityMapping): void + public function transform(Class_ $class, EntityMapping $entityMapping): bool { - $this->transformClass($class, $entityMapping); - $this->transformProperties($class, $entityMapping); + $hasTrasnformedClass = $this->transformClass($class, $entityMapping); + $hasTrasnformedProperties = $this->transformProperties($class, $entityMapping); + return $hasTrasnformedClass || $hasTrasnformedProperties; } - private function transformClass(Class_ $class, EntityMapping $entityMapping): void + private function transformClass(Class_ $class, EntityMapping $entityMapping): bool { + $hasChanged = false; foreach ($this->classAttributeTransformers as $classAttributeTransformer) { if ($this->hasAttribute($class, $classAttributeTransformer->getClassName())) { continue; } - $classAttributeTransformer->transform($entityMapping, $class); + $hasTransformedAttribute = $classAttributeTransformer->transform($entityMapping, $class); + if ($hasTransformedAttribute) { + $hasChanged = true; + } } + return $hasChanged; } - private function transformProperties(Class_ $class, EntityMapping $entityMapping): void + private function transformProperties(Class_ $class, EntityMapping $entityMapping): bool { + $hasChanged = false; foreach ($class->getProperties() as $property) { foreach ($this->propertyAttributeTransformers as $propertyAttributeTransformer) { if ($this->hasAttribute($property, $propertyAttributeTransformer->getClassName())) { continue; } - $propertyAttributeTransformer->transform($entityMapping, $property); + $hasTransformedAttribute = $propertyAttributeTransformer->transform($entityMapping, $property); + if ($hasTransformedAttribute) { + $hasChanged = true; + } } } // handle promoted properties $constructorClassMethod = $class->getMethod(MethodName::CONSTRUCT); if (! $constructorClassMethod instanceof ClassMethod) { - return; + return $hasChanged; } foreach ($constructorClassMethod->getParams() as $param) { @@ -71,9 +81,13 @@ private function transformProperties(Class_ $class, EntityMapping $entityMapping continue; } - $propertyAttributeTransformer->transform($entityMapping, $param); + $hasTransformedAttribute = $propertyAttributeTransformer->transform($entityMapping, $param); + if ($hasTransformedAttribute) { + $hasChanged = true; + } } } + return $hasChanged; } private function hasAttribute(Class_|Property|Param $stmt, string $attributeClassName): bool diff --git a/rules/CodeQuality/Contract/ClassAttributeTransformerInterface.php b/rules/CodeQuality/Contract/ClassAttributeTransformerInterface.php index 9e9f33c5..21d59a26 100644 --- a/rules/CodeQuality/Contract/ClassAttributeTransformerInterface.php +++ b/rules/CodeQuality/Contract/ClassAttributeTransformerInterface.php @@ -15,5 +15,5 @@ interface ClassAttributeTransformerInterface */ public function getClassName(): string; - public function transform(EntityMapping $entityMapping, Class_ $class): void; + public function transform(EntityMapping $entityMapping, Class_ $class): bool; } diff --git a/rules/CodeQuality/Contract/PropertyAttributeTransformerInterface.php b/rules/CodeQuality/Contract/PropertyAttributeTransformerInterface.php index 13094869..24829a1c 100644 --- a/rules/CodeQuality/Contract/PropertyAttributeTransformerInterface.php +++ b/rules/CodeQuality/Contract/PropertyAttributeTransformerInterface.php @@ -15,5 +15,5 @@ interface PropertyAttributeTransformerInterface */ public function getClassName(): string; - public function transform(EntityMapping $entityMapping, Property|Param $property): void; + public function transform(EntityMapping $entityMapping, Property|Param $property): bool; } diff --git a/rules/CodeQuality/Rector/Class_/YamlToAttributeDoctrineMappingRector.php b/rules/CodeQuality/Rector/Class_/YamlToAttributeDoctrineMappingRector.php index 579b6ae3..fcd6ff8c 100644 --- a/rules/CodeQuality/Rector/Class_/YamlToAttributeDoctrineMappingRector.php +++ b/rules/CodeQuality/Rector/Class_/YamlToAttributeDoctrineMappingRector.php @@ -92,7 +92,11 @@ public function refactor(Node $node): ?Class_ return null; } - $this->yamlToAttributeTransformer->transform($node, $entityMapping); + $hasChanged = $this->yamlToAttributeTransformer->transform($node, $entityMapping); + + if (! $hasChanged) { + return null; + } return $node; }