diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_only.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_only.php.inc new file mode 100644 index 00000000000..83f2f771e40 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_only.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php b/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php index 6af3acbce3d..9c1e3248e83 100644 --- a/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php +++ b/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php @@ -139,6 +139,7 @@ public function refactor(Node $node): ?Node $requiredDoctrineAnnotationTagValueNode = $propertyPhpDocInfo->getByAnnotationClass( 'Doctrine\Common\Annotations\Annotation\Required' ); + if (! $requiredDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) { continue; } @@ -207,12 +208,14 @@ private function decorateTarget(PhpDocInfo $phpDocInfo, AttributeGroup $attribut } $targets = $targetDoctrineAnnotationTagValueNode->getSilentValue(); - if (! $targets instanceof CurlyListNode) { + if ($targets instanceof CurlyListNode) { + $targetValues = $targets->getValuesWithExplicitSilentAndWithoutQuotes(); + } elseif (is_string($targets)) { + $targetValues = [$targets]; + } else { return; } - $targetValues = $targets->getValuesWithExplicitSilentAndWithoutQuotes(); - $flags = $this->resolveFlags($targetValues); $flagCollection = $this->attributeFlagFactory->createFlagCollection($flags); if ($flagCollection === null) {