Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
});
}
}
5 changes: 5 additions & 0 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down