From ee37e524ef676a940c1c103c34ad0fda133e2d2a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 7 Jul 2026 10:45:14 +0700 Subject: [PATCH] [AnnotationsToAttributes] Avoid partial apply on CoversAnnotationWithValueToAttributeRector --- ...ersAnnotationWithValueToAttributeRector.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php index cba8516e8..aa1cd15f5 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php @@ -108,7 +108,13 @@ public function refactor(Node $node): ?Node return null; } - if (! $this->reflectionProvider->hasClass(self::COVERS_FUNCTION_ATTRIBUTE)) { + // avoid partial apply that may cause error + if ( + ! $this->reflectionProvider->hasClass(self::COVERS_FUNCTION_ATTRIBUTE) + || ! $this->reflectionProvider->hasClass(self::COVERTS_CLASS_ATTRIBUTE) + || ! $this->reflectionProvider->hasClass(self::COVERTS_TRAIT_ATTRIBUTE) + || ! $this->reflectionProvider->hasClass(self::COVERS_METHOD_ATTRIBUTE) + ) { return null; } @@ -140,10 +146,6 @@ private function createAttributeGroup(string $annotationValue): ?AttributeGroup $attributeValue = [trim($annotationValue, ':()')]; } elseif (str_contains($annotationValue, '::')) { $attributeClass = self::COVERS_METHOD_ATTRIBUTE; - if (! $this->reflectionProvider->hasClass($attributeClass)) { - return null; - } - $attributeValue = [$this->getClass($annotationValue) . '::class', $this->getMethod($annotationValue)]; } else { $attributeClass = self::COVERTS_CLASS_ATTRIBUTE; @@ -302,12 +304,6 @@ private function removeMethodCoversAnnotations(ClassMethod $classMethod): bool continue; } - if (str_contains($desiredTagValueNode->value->value, '::') && ! $this->reflectionProvider->hasClass( - self::COVERS_METHOD_ATTRIBUTE - )) { - continue; - } - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode); $hasChanged = true; }