From 1337e2a876ec8844e1f9d4af7c98b300d88e3bd6 Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Mon, 31 Mar 2025 11:11:28 +0200 Subject: [PATCH] Fix ImproveDoctrineCollectionDocTypeInEntityRector --- ...octrineCollectionDocTypeInEntityRector.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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; }