Skip to content

Commit 32a4549

Browse files
authored
cleanup StringClassNameToClassConstantRector (#7691)
1 parent 6ef19d6 commit 32a4549

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ final class StringClassNameToClassConstantRector extends AbstractRector implemen
3131
*/
3232
public const SHOULD_KEEP_PRE_SLASH = 'should_keep_pre_slash';
3333

34-
/**
35-
* @var string
36-
*/
37-
private const IS_UNDER_CLASS_CONST = 'is_under_class_const';
38-
3934
/**
4035
* @var string[]
4136
*/
@@ -105,9 +100,7 @@ public function refactor(Node $node): Concat|ClassConstFetch|null|int
105100
{
106101
// allow class strings to be part of class const arrays, as probably on purpose
107102
if ($node instanceof ClassConst) {
108-
$this->decorateClassConst($node);
109-
110-
return null;
103+
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
111104
}
112105

113106
// keep allowed string as condition
@@ -119,10 +112,6 @@ public function refactor(Node $node): Concat|ClassConstFetch|null|int
119112
return null;
120113
}
121114

122-
if ($node->getAttribute(self::IS_UNDER_CLASS_CONST) === true) {
123-
return null;
124-
}
125-
126115
$classLikeName = $node->value;
127116

128117
// remove leading slash
@@ -201,15 +190,4 @@ private function shouldSkip(string $classLikeName): bool
201190

202191
return false;
203192
}
204-
205-
private function decorateClassConst(ClassConst $classConst): void
206-
{
207-
$this->traverseNodesWithCallable($classConst->consts, static function (Node $subNode): null {
208-
if ($subNode instanceof String_) {
209-
$subNode->setAttribute(self::IS_UNDER_CLASS_CONST, true);
210-
}
211-
212-
return null;
213-
});
214-
}
215193
}

src/Rector/AbstractRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ protected function mirrorComments(Node $newNode, Node $oldNode): void
297297

298298
private function decorateCurrentAndChildren(Node $node): void
299299
{
300+
// skip sole type, as no other nodes to filter out
301+
if (count($this->getNodeTypes()) === 1) {
302+
return;
303+
}
304+
300305
// filter only types that
301306
// 1. registered in getNodesTypes() method
302307
// 2. different with current node type, as already decorated above

0 commit comments

Comments
 (0)