From b427d0674eec6fbbd32cace4266d6dc808b2a1b7 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 1 Dec 2025 12:10:01 +0100 Subject: [PATCH] cleanup StringClassNameToClassConstantRector --- .../StringClassNameToClassConstantRector.php | 24 +------------------ src/Rector/AbstractRector.php | 5 ++++ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php b/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php index 5e258d6383c..fc243eab971 100644 --- a/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php +++ b/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php @@ -31,11 +31,6 @@ final class StringClassNameToClassConstantRector extends AbstractRector implemen */ public const SHOULD_KEEP_PRE_SLASH = 'should_keep_pre_slash'; - /** - * @var string - */ - private const IS_UNDER_CLASS_CONST = 'is_under_class_const'; - /** * @var string[] */ @@ -105,9 +100,7 @@ public function refactor(Node $node): Concat|ClassConstFetch|null|int { // allow class strings to be part of class const arrays, as probably on purpose if ($node instanceof ClassConst) { - $this->decorateClassConst($node); - - return null; + return NodeVisitor::DONT_TRAVERSE_CHILDREN; } // keep allowed string as condition @@ -119,10 +112,6 @@ public function refactor(Node $node): Concat|ClassConstFetch|null|int return null; } - if ($node->getAttribute(self::IS_UNDER_CLASS_CONST) === true) { - return null; - } - $classLikeName = $node->value; // remove leading slash @@ -201,15 +190,4 @@ private function shouldSkip(string $classLikeName): bool return false; } - - private function decorateClassConst(ClassConst $classConst): void - { - $this->traverseNodesWithCallable($classConst->consts, static function (Node $subNode): null { - if ($subNode instanceof String_) { - $subNode->setAttribute(self::IS_UNDER_CLASS_CONST, true); - } - - return null; - }); - } } diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 789560ff739..cabf128dd16 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -297,6 +297,11 @@ protected function mirrorComments(Node $newNode, Node $oldNode): void private function decorateCurrentAndChildren(Node $node): void { + // skip sole type, as no other nodes to filter out + if (count($this->getNodeTypes()) === 1) { + return; + } + // filter only types that // 1. registered in getNodesTypes() method // 2. different with current node type, as already decorated above