Skip to content

Commit b430be2

Browse files
authored
Only remove @Covers when target exists (#494)
* Only remove @Covers when target exists * remove @Covers ::__construct on class level * check exists * cs fix * keep
1 parent 90755cf commit b430be2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ private function handleCovers(PhpDocInfo $phpDocInfo, bool $hasCoversDefault): a
248248
}
249249

250250
$attributeGroups[$covers] = $attributeGroup;
251+
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
252+
} elseif ($hasCoversDefault && str_starts_with($covers, '::')) {
253+
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
251254
}
252-
253-
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
254255
}
255256

256257
return $attributeGroups;
@@ -304,6 +305,12 @@ private function removeMethodCoversAnnotations(ClassMethod $classMethod): bool
304305
continue;
305306
}
306307

308+
if (str_contains($desiredTagValueNode->value->value, '::') && ! $this->reflectionProvider->hasClass(
309+
self::COVERS_METHOD_ATTRIBUTE
310+
)) {
311+
continue;
312+
}
313+
307314
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
308315
$hasChanged = true;
309316
}

0 commit comments

Comments
 (0)