diff --git a/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php b/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php index 0925143c..13978149 100644 --- a/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php +++ b/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php @@ -177,7 +177,7 @@ private function refactorClassMethod(Class_ $class): ?Class_ /** @var string $parameterName */ $parameterName = $this->getName($param); - $this->phpDocTypeChanger->changeParamType( + $hasChangedParamType = $this->phpDocTypeChanger->changeParamType( $classMethod, $phpDocInfo, $collectionObjectType, @@ -185,7 +185,9 @@ private function refactorClassMethod(Class_ $class): ?Class_ $parameterName ); - $hasChanged = true; + if ($hasChangedParamType) { + $hasChanged = true; + } } if ($hasChanged) { @@ -213,7 +215,7 @@ private function refactorPropertyPhpDocInfo(Property $property, PhpDocInfo $phpD $this->collectionTypeResolver->hasIndexBy($property), $property ); - $this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType); + $hasChanged = $this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType); } else { $collectionObjectType = $this->collectionTypeResolver->resolveFromToManyProperty($property); if (! $collectionObjectType instanceof FullyQualifiedObjectType) { @@ -225,7 +227,11 @@ private function refactorPropertyPhpDocInfo(Property $property, PhpDocInfo $phpD $this->collectionTypeResolver->hasIndexBy($property), $property ); - $this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType); + $hasChanged = $this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType); + } + + if (!$hasChanged) { + return null; } return $property; @@ -262,7 +268,11 @@ private function refactorAttribute(Expr $expr, PhpDocInfo $phpDocInfo, Property $this->collectionTypeResolver->hasIndexBy($property), $property ); - $this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $genericObjectType); + $hasChanged = $this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $genericObjectType); + + if (! $hasChanged) { + return null; + } return $property; }