Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ public function refactor(Node $node): ?Node
return $node;
}

private function createAttributeGroup(string $annotationValue): AttributeGroup
private function createAttributeGroup(string $annotationValue): ?AttributeGroup
{
if (str_starts_with($annotationValue, '::')) {
$attributeClass = self::COVERS_FUNCTION_ATTRIBUTE;
$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;
Expand All @@ -161,6 +165,9 @@ private function createAttributeGroup(string $annotationValue): AttributeGroup

if ($classReflection->isTrait()) {
$attributeClass = self::COVERTS_TRAIT_ATTRIBUTE;
if (! $this->reflectionProvider->hasClass($attributeClass)) {
return null;
}
}
}

Expand Down Expand Up @@ -206,7 +213,13 @@ private function handleCoversDefaultClass(PhpDocInfo $phpDocInfo): array
continue;
}

$attributeGroups[] = $this->createAttributeGroup($desiredTagValueNode->value->value);
$attributeGroup = $this->createAttributeGroup($desiredTagValueNode->value->value);
// phpunit 10 may not fully support attribute
if (! $attributeGroup instanceof AttributeGroup) {
continue;
}

$attributeGroups[] = $attributeGroup;
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
}

Expand All @@ -226,10 +239,15 @@ private function handleCovers(PhpDocInfo $phpDocInfo, bool $hasCoversDefault): a
}

$covers = $desiredTagValueNode->value->value;
if (str_starts_with($covers, '\\')) {
$attributeGroups[$covers] = $this->createAttributeGroup($covers);
} elseif (! $hasCoversDefault && str_starts_with($covers, '::')) {
$attributeGroups[$covers] = $this->createAttributeGroup($covers);
if (str_starts_with($covers, '\\') || (! $hasCoversDefault && str_starts_with($covers, '::'))) {
$attributeGroup = $this->createAttributeGroup($covers);

// phpunit 10 may not fully support attribute
if (! $attributeGroup instanceof AttributeGroup) {
continue;
}

$attributeGroups[$covers] = $attributeGroup;
}

$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
Expand All @@ -256,10 +274,15 @@ private function resolveMethodAttributes(ClassMethod $classMethod, bool $hasCove
}

$covers = $desiredTagValueNode->value->value;
if (str_starts_with($covers, '\\')) {
$attributeGroups[$covers] = $this->createAttributeGroup($covers);
} elseif (! $hasCoversDefault && str_starts_with($covers, '::')) {
$attributeGroups[$covers] = $this->createAttributeGroup($covers);
if (str_starts_with($covers, '\\') || (! $hasCoversDefault && str_starts_with($covers, '::'))) {
$attributeGroup = $this->createAttributeGroup($covers);

// phpunit 10 may not fully support attribute
if (! $attributeGroup instanceof AttributeGroup) {
continue;
}

$attributeGroups[$covers] = $attributeGroup;
}
}

Expand Down
Loading