diff --git a/src/Application/ChangedNodeScopeRefresher.php b/src/Application/ChangedNodeScopeRefresher.php index be0f30fa624..10730b42da1 100644 --- a/src/Application/ChangedNodeScopeRefresher.php +++ b/src/Application/ChangedNodeScopeRefresher.php @@ -95,6 +95,12 @@ public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingSc // the class node itself is not part of its stmts, e.g. an Enum_ replaced by a new Class_ has no scope yet $node->setAttribute(AttributeKey::SCOPE, $mutatingScope); $this->phpStanNodeScopeResolver->processNodes($node->stmts, $filePath, $mutatingScope); + + // the class attributes are not part of its stmts either, e.g. one converted from an annotation + foreach ($node->attrGroups as $attrGroup) { + $this->phpStanNodeScopeResolver->processNodes($this->resolveStmts($attrGroup), $filePath, $mutatingScope); + } + return; } diff --git a/tests/Issues/ClassAttributeStringClassName/ClassAttributeStringClassNameTest.php b/tests/Issues/ClassAttributeStringClassName/ClassAttributeStringClassNameTest.php new file mode 100644 index 00000000000..a791a4216e4 --- /dev/null +++ b/tests/Issues/ClassAttributeStringClassName/ClassAttributeStringClassNameTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/ClassAttributeStringClassName/Fixture/discriminator_map.php.inc b/tests/Issues/ClassAttributeStringClassName/Fixture/discriminator_map.php.inc new file mode 100644 index 00000000000..048a20f7f26 --- /dev/null +++ b/tests/Issues/ClassAttributeStringClassName/Fixture/discriminator_map.php.inc @@ -0,0 +1,27 @@ + +----- + \Rector\Tests\Issues\ClassAttributeStringClassName\Source\Page::class])] +class Statistic +{ +} + +?> diff --git a/tests/Issues/ClassAttributeStringClassName/Source/Page.php b/tests/Issues/ClassAttributeStringClassName/Source/Page.php new file mode 100644 index 00000000000..d80fc2a956a --- /dev/null +++ b/tests/Issues/ClassAttributeStringClassName/Source/Page.php @@ -0,0 +1,9 @@ +withConfiguredRule(AnnotationToAttributeRector::class, [ + new AnnotationToAttribute('Doctrine\ORM\Mapping\DiscriminatorMap'), + ]) + ->withRules([StringClassNameToClassConstantRector::class]);