From 69b625cd33c1e5b7c8ba7bcda19450ea71cbdda0 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 18 Aug 2022 20:33:43 +0200 Subject: [PATCH] [PHP 8.0] Add class support to NestedAnnotationToAttributeRector (#2782) * [PHP 8.0] Add class support to AnnotationToAttributeRector * cleanup * remove unwrappable check, make it explicit on configuration --- ...eAnnotationAnnotationToAttributeMapper.php | 10 +-- .../InvalidNestedAttributeException.php | 11 --- .../NodeFactory/PhpAttributeGroupFactory.php | 46 ----------- .../UnwrapableAnnotationAnalyzer.php | 76 ------------------- .../Doctrine/multi_nested_indexes.php.inc | 32 -------- .../skip_table_and_unique_constraints.php.inc | 19 +++++ ...nested_index_and_uniqueconstraints.php.inc | 33 -------- .../table_and_unique_constraints.php.inc | 30 -------- ...p_unwrap_symfony_nested_validators.php.inc | 49 ------------ .../multiple_nested_attributes.php.inc | 5 +- .../FixturePhp81/named_argument.php.inc | 31 -------- .../FixturePhp81/nested_attributes.php.inc | 31 -------- .../nested_attributes_with_argument.php.inc | 31 -------- ...nested_index_and_uniqueconstraints.php.inc | 33 -------- .../FixturePhp81/various_arguments.php.inc | 32 -------- .../config/configured_rule.php | 1 - .../Fixture/doctrine_table.php.inc | 40 ++++++++++ .../Fixture/string_annotation_value.php.inc | 6 +- .../config/configured_rule.php | 5 ++ rules/Php80/PhpDoc/PhpDocNodeFinder.php | 38 ---------- .../Class_/AnnotationToAttributeRector.php | 45 +---------- .../NestedAnnotationToAttributeRector.php | 5 +- 22 files changed, 74 insertions(+), 535 deletions(-) delete mode 100644 packages/PhpAttribute/Exception/InvalidNestedAttributeException.php delete mode 100644 packages/PhpAttribute/UnwrapableAnnotationAnalyzer.php delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/multi_nested_indexes.php.inc create mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/skip_table_and_unique_constraints.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/table_and_nested_index_and_uniqueconstraints.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/table_and_unique_constraints.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/skip_unwrap_symfony_nested_validators.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/named_argument.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes_with_argument.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/table_and_nested_index_and_uniqueconstraints.php.inc delete mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/various_arguments.php.inc create mode 100644 rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/doctrine_table.php.inc rename rules-tests/Php80/Rector/{Class_/AnnotationToAttributeRector => Property/NestedAnnotationToAttributeRector}/Fixture/string_annotation_value.php.inc (70%) delete mode 100644 rules/Php80/PhpDoc/PhpDocNodeFinder.php diff --git a/packages/PhpAttribute/AnnotationToAttributeMapper/DoctrineAnnotationAnnotationToAttributeMapper.php b/packages/PhpAttribute/AnnotationToAttributeMapper/DoctrineAnnotationAnnotationToAttributeMapper.php index 55f0e44132c..4b630d6ec7b 100644 --- a/packages/PhpAttribute/AnnotationToAttributeMapper/DoctrineAnnotationAnnotationToAttributeMapper.php +++ b/packages/PhpAttribute/AnnotationToAttributeMapper/DoctrineAnnotationAnnotationToAttributeMapper.php @@ -14,8 +14,6 @@ use Rector\PhpAttribute\AnnotationToAttributeMapper; use Rector\PhpAttribute\AttributeArrayNameInliner; use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface; -use Rector\PhpAttribute\Exception\InvalidNestedAttributeException; -use Rector\PhpAttribute\UnwrapableAnnotationAnalyzer; use Symfony\Contracts\Service\Attribute\Required; /** @@ -27,7 +25,6 @@ final class DoctrineAnnotationAnnotationToAttributeMapper implements AnnotationT public function __construct( private readonly PhpVersionProvider $phpVersionProvider, - private readonly UnwrapableAnnotationAnalyzer $unwrapableAnnotationAnalyzer, private readonly AttributeArrayNameInliner $attributeArrayNameInliner, ) { } @@ -47,7 +44,7 @@ public function isCandidate(mixed $value): bool return false; } - return ! $this->unwrapableAnnotationAnalyzer->areUnwrappable([$value]); + return $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NEW_INITIALIZERS); } /** @@ -55,11 +52,6 @@ public function isCandidate(mixed $value): bool */ public function map($value): New_ { - // if PHP 8.0- throw exception - if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NEW_INITIALIZERS)) { - throw new InvalidNestedAttributeException(); - } - $annotationShortName = $this->resolveAnnotationName($value); $values = $value->getValues(); diff --git a/packages/PhpAttribute/Exception/InvalidNestedAttributeException.php b/packages/PhpAttribute/Exception/InvalidNestedAttributeException.php deleted file mode 100644 index d92fe136693..00000000000 --- a/packages/PhpAttribute/Exception/InvalidNestedAttributeException.php +++ /dev/null @@ -1,11 +0,0 @@ -> - */ - private const UNWRAPPED_ANNOTATIONS = [ - 'Doctrine\ORM\Mapping\Table' => ['indexes', 'uniqueConstraints'], - 'Doctrine\ORM\Mapping\Entity' => ['uniqueConstraints'], - ]; - public function __construct( private readonly AnnotationToAttributeMapper $annotationToAttributeMapper, private readonly AttributeNameFactory $attributeNameFactory, @@ -98,42 +88,6 @@ public function createArgsFromItems(array $items, string $attributeClass): array $items = $this->exprParameterReflectionTypeCorrector->correctItemsByAttributeClass($items, $attributeClass); - $items = $this->removeUnwrappedItems($attributeClass, $items); - return $this->namedArgsFactory->createFromValues($items); } - - /** - * @todo deprecated - * - * @param mixed[] $items - * @return mixed[] - */ - private function removeUnwrappedItems(string $attributeClass, array $items): array - { - // unshift annotations that can be extracted - $unwrappeColumns = self::UNWRAPPED_ANNOTATIONS[$attributeClass] ?? []; - if ($unwrappeColumns === []) { - return $items; - } - - foreach ($items as $key => $item) { - if (! $item instanceof ArrayItem) { - continue; - } - - if (! $item->key instanceof String_) { - continue; - } - - $stringItemKey = $item->key; - if (! in_array($stringItemKey->value, $unwrappeColumns, true)) { - continue; - } - - unset($items[$key]); - } - - return $items; - } } diff --git a/packages/PhpAttribute/UnwrapableAnnotationAnalyzer.php b/packages/PhpAttribute/UnwrapableAnnotationAnalyzer.php deleted file mode 100644 index 163f46d6cef..00000000000 --- a/packages/PhpAttribute/UnwrapableAnnotationAnalyzer.php +++ /dev/null @@ -1,76 +0,0 @@ -annotationsToAttributes = $annotationsToAttributes; - } - - /** - * @param DoctrineAnnotationTagValueNode[] $doctrineAnnotationTagValueNodes - */ - public function areUnwrappable(array $doctrineAnnotationTagValueNodes): bool - { - foreach ($doctrineAnnotationTagValueNodes as $doctrineAnnotationTagValueNode) { - $annotationClassName = $doctrineAnnotationTagValueNode->identifierTypeNode->getAttribute( - PhpDocAttributeKey::RESOLVED_CLASS - ); - - $nestedAnnotationToAttribute = $this->matchAnnotationToAttribute($doctrineAnnotationTagValueNode); - - // the nested annotation should be convertable - if (! $nestedAnnotationToAttribute instanceof AnnotationToAttribute) { - return false; - } - - if (! in_array($annotationClassName, self::UNWRAPEABLE_ANNOTATION_CLASSES, true)) { - return false; - } - } - - return true; - } - - private function matchAnnotationToAttribute( - DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode - ): AnnotationToAttribute|null { - foreach ($this->annotationsToAttributes as $annotationToAttribute) { - if (! $doctrineAnnotationTagValueNode->hasClassName($annotationToAttribute->getTag())) { - continue; - } - - return $annotationToAttribute; - } - - return null; - } -} diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/multi_nested_indexes.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/multi_nested_indexes.php.inc deleted file mode 100644 index 9115a4d768a..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/multi_nested_indexes.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/skip_table_and_unique_constraints.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/skip_table_and_unique_constraints.php.inc new file mode 100644 index 00000000000..5fe606f30a9 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/skip_table_and_unique_constraints.php.inc @@ -0,0 +1,19 @@ + ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/table_and_unique_constraints.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/table_and_unique_constraints.php.inc deleted file mode 100644 index 95568f22757..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Doctrine/table_and_unique_constraints.php.inc +++ /dev/null @@ -1,30 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/skip_unwrap_symfony_nested_validators.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/skip_unwrap_symfony_nested_validators.php.inc deleted file mode 100644 index 0dede670782..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/skip_unwrap_symfony_nested_validators.php.inc +++ /dev/null @@ -1,49 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/multiple_nested_attributes.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/multiple_nested_attributes.php.inc index d9b0ef0f254..1978d242ba8 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/multiple_nested_attributes.php.inc +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/multiple_nested_attributes.php.inc @@ -9,7 +9,8 @@ final class MultipleNestedAttribute /** * @Assert\All({ * @Assert\NotNull(), - * @Assert\NotNumber(), + * @Assert\NotNumber(secondValue=1000), + * @Assert\NotNumber(hey=10, hi="hello"), * }) */ public $value; @@ -25,7 +26,7 @@ use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81 as final class MultipleNestedAttribute { - #[Assert\All([new Assert\NotNull(), new Assert\NotNumber()])] + #[Assert\All([new Assert\NotNull(), new Assert\NotNumber(secondValue: 1000), new Assert\NotNumber(hey: 10, hi: 'hello')])] public $value; } diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/named_argument.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/named_argument.php.inc deleted file mode 100644 index 70ebec2b9cd..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/named_argument.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes.php.inc deleted file mode 100644 index fbaf7ee89bb..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes_with_argument.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes_with_argument.php.inc deleted file mode 100644 index 1591a1c8446..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/nested_attributes_with_argument.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/table_and_nested_index_and_uniqueconstraints.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/table_and_nested_index_and_uniqueconstraints.php.inc deleted file mode 100644 index 4b7f769a2dc..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/table_and_nested_index_and_uniqueconstraints.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/various_arguments.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/various_arguments.php.inc deleted file mode 100644 index 252e3e67e6a..00000000000 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/various_arguments.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php index f875e6c9cda..81d9685ac75 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php @@ -31,7 +31,6 @@ // doctrine new AnnotationToAttribute('Doctrine\ORM\Mapping\Entity'), new AnnotationToAttribute('Doctrine\ORM\Mapping\ManyToMany'), - new AnnotationToAttribute('Doctrine\ORM\Mapping\Table'), new AnnotationToAttribute('Doctrine\ORM\Mapping\Index'), new AnnotationToAttribute('Doctrine\ORM\Mapping\UniqueConstraint'), new AnnotationToAttribute('Doctrine\ORM\Mapping\DiscriminatorMap'), diff --git a/rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/doctrine_table.php.inc b/rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/doctrine_table.php.inc new file mode 100644 index 00000000000..c3be9463270 --- /dev/null +++ b/rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/doctrine_table.php.inc @@ -0,0 +1,40 @@ + +----- + diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/string_annotation_value.php.inc b/rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/string_annotation_value.php.inc similarity index 70% rename from rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/string_annotation_value.php.inc rename to rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/string_annotation_value.php.inc index 7704fa6662d..3c6d47001ba 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/string_annotation_value.php.inc +++ b/rules-tests/Php80/Rector/Property/NestedAnnotationToAttributeRector/Fixture/string_annotation_value.php.inc @@ -1,12 +1,11 @@ 'Doctrine\ORM\Mapping\InverseJoinColumn', ]), + new NestedAnnotationToAttribute('Doctrine\ORM\Mapping\Table', [ + 'indexes' => 'Doctrine\ORM\Mapping\Index', + 'uniqueConstraints' => 'Doctrine\ORM\Mapping\UniqueConstraint', + ]), + /** @see https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#joincolumns */ new NestedAnnotationToAttribute('Doctrine\ORM\Mapping\JoinColumns', [ 'Doctrine\ORM\Mapping\JoinColumn', diff --git a/rules/Php80/PhpDoc/PhpDocNodeFinder.php b/rules/Php80/PhpDoc/PhpDocNodeFinder.php deleted file mode 100644 index 8b0b218ed21..00000000000 --- a/rules/Php80/PhpDoc/PhpDocNodeFinder.php +++ /dev/null @@ -1,38 +0,0 @@ - $nodeType - * @return TNode[] - */ - public function findByType(Node $node, string $nodeType): array - { - $foundNodes = []; - - $phpDocNodeTraverser = new PhpDocNodeTraverser(); - $phpDocNodeTraverser->traverseWithCallable($node, '', static function (Node $node) use ( - &$foundNodes, - $nodeType - ) { - if (! is_a($node, $nodeType, true)) { - return null; - } - - $foundNodes[] = $node; - return null; - }); - - return $foundNodes; - } -} diff --git a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php index 9b4cfc770ab..98ca31d0476 100644 --- a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php +++ b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php @@ -20,17 +20,15 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; -use Rector\Core\Php\PhpVersionProvider; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Naming\Naming\UseImportsResolver; use Rector\Php80\NodeFactory\AttrGroupsFactory; use Rector\Php80\NodeManipulator\AttributeGroupNamedArgumentManipulator; -use Rector\Php80\PhpDoc\PhpDocNodeFinder; use Rector\Php80\ValueObject\AnnotationToAttribute; use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute; use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory; -use Rector\PhpAttribute\UnwrapableAnnotationAnalyzer; +//use Rector\PhpAttribute\UnwrapableAnnotationAnalyzer; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\Astral\PhpDocParser\PhpDocNodeTraverser; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -53,10 +51,7 @@ public function __construct( private readonly PhpAttributeGroupFactory $phpAttributeGroupFactory, private readonly AttrGroupsFactory $attrGroupsFactory, private readonly PhpDocTagRemover $phpDocTagRemover, - private readonly PhpDocNodeFinder $phpDocNodeFinder, - private readonly UnwrapableAnnotationAnalyzer $unwrapableAnnotationAnalyzer, private readonly AttributeGroupNamedArgumentManipulator $attributeGroupNamedArgumentManipulator, - private readonly PhpVersionProvider $phpVersionProvider, private readonly UseImportsResolver $useImportsResolver, ) { } @@ -148,8 +143,6 @@ public function configure(array $configuration): void { Assert::allIsAOf($configuration, AnnotationToAttribute::class); $this->annotationsToAttributes = $configuration; - - $this->unwrapableAnnotationAnalyzer->configure($configuration); } public function provideMinPhpVersion(): int @@ -229,47 +222,11 @@ private function processDoctrineAnnotationClasses(PhpDocInfo $phpDocInfo, array continue; } - $nestedDoctrineAnnotationTagValueNodes = $this->phpDocNodeFinder->findByType( - $doctrineTagValueNode, - DoctrineAnnotationTagValueNode::class - ); - - $shouldInlinedNested = false; - - // depends on PHP 8.1+ - nested values, skip for now - if ($nestedDoctrineAnnotationTagValueNodes !== [] && ! $this->phpVersionProvider->isAtLeastPhpVersion( - PhpVersionFeature::NEW_INITIALIZERS - )) { - if (! $this->unwrapableAnnotationAnalyzer->areUnwrappable($nestedDoctrineAnnotationTagValueNodes)) { - continue; - } - - $shouldInlinedNested = true; - } - - // Inline nested annotations when they can/need to be unwrapped (doctrine @Table(index: [@Index(...)]) - if ($nestedDoctrineAnnotationTagValueNodes !== [] - && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NEW_INITIALIZERS) - && $this->unwrapableAnnotationAnalyzer->areUnwrappable($nestedDoctrineAnnotationTagValueNodes) - ) { - $shouldInlinedNested = true; - } - $doctrineTagAndAnnotationToAttributes[] = new DoctrineTagAndAnnotationToAttribute( $doctrineTagValueNode, $annotationToAttribute, ); - if ($shouldInlinedNested) { - // inline nested - foreach ($nestedDoctrineAnnotationTagValueNodes as $nestedDoctrineAnnotationTagValueNode) { - $doctrineTagAndAnnotationToAttributes[] = new DoctrineTagAndAnnotationToAttribute( - $nestedDoctrineAnnotationTagValueNode, - $annotationToAttribute, - ); - } - } - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $doctrineTagValueNode); } diff --git a/rules/Php80/Rector/Property/NestedAnnotationToAttributeRector.php b/rules/Php80/Rector/Property/NestedAnnotationToAttributeRector.php index 3049e2088ac..7515a9e5ee0 100644 --- a/rules/Php80/Rector/Property/NestedAnnotationToAttributeRector.php +++ b/rules/Php80/Rector/Property/NestedAnnotationToAttributeRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\AttributeGroup; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode; @@ -91,11 +92,11 @@ class SomeEntity */ public function getNodeTypes(): array { - return [Property::class]; + return [Property::class, Class_::class]; } /** - * @param Property $node + * @param Property|Class_ $node */ public function refactor(Node $node): ?Node {