From 405de11da196053ecf55499e6b13ec183db4e5f9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 22 May 2025 14:00:57 +0700 Subject: [PATCH 1/5] Only remove @covers when target exists --- .../Class_/CoversAnnotationWithValueToAttributeRector.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php index 1569cc15..29bc9878 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php @@ -248,9 +248,8 @@ private function handleCovers(PhpDocInfo $phpDocInfo, bool $hasCoversDefault): a } $attributeGroups[$covers] = $attributeGroup; + $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode); } - - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode); } return $attributeGroups; From a61707cfc1f0423a791adef45866ad99cdef8dcc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 22 May 2025 14:11:33 +0700 Subject: [PATCH 2/5] remove @covers ::__construct on class level --- .../Fixture/covers_class_default.php.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc b/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc index 4b666909..7475f229 100644 --- a/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc +++ b/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc @@ -6,7 +6,6 @@ use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingClass - * @covers ::__construct */ final class CoversClassDefault extends TestCase { From 0324c77799340e5d6a12d63ce4cd415274f39949 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 22 May 2025 14:47:27 +0700 Subject: [PATCH 3/5] check exists --- .../Class_/CoversAnnotationWithValueToAttributeRector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php index 29bc9878..97d67a53 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php @@ -303,6 +303,10 @@ 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; } From f157f93efc84a1bfe071e4ac553fd9cd4dd6b288 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 22 May 2025 14:49:11 +0700 Subject: [PATCH 4/5] cs fix --- .../Class_/CoversAnnotationWithValueToAttributeRector.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php index 97d67a53..74f21990 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php @@ -303,7 +303,9 @@ private function removeMethodCoversAnnotations(ClassMethod $classMethod): bool continue; } - if (str_contains($desiredTagValueNode->value->value, '::') && ! $this->reflectionProvider->hasClass(self::COVERS_METHOD_ATTRIBUTE)) { + if (str_contains($desiredTagValueNode->value->value, '::') && ! $this->reflectionProvider->hasClass( + self::COVERS_METHOD_ATTRIBUTE + )) { continue; } From 7da389b26703b53eeecaa309225309688d9ddffd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 22 May 2025 14:52:39 +0700 Subject: [PATCH 5/5] keep --- .../Fixture/covers_class_default.php.inc | 1 + .../Class_/CoversAnnotationWithValueToAttributeRector.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc b/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc index 7475f229..4b666909 100644 --- a/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc +++ b/rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class_default.php.inc @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingClass + * @covers ::__construct */ final class CoversClassDefault extends TestCase { diff --git a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php index 74f21990..25d79096 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php @@ -249,6 +249,8 @@ private function handleCovers(PhpDocInfo $phpDocInfo, bool $hasCoversDefault): a $attributeGroups[$covers] = $attributeGroup; $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode); + } elseif ($hasCoversDefault && str_starts_with($covers, '::')) { + $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode); } }