From 2f38105001867c15fb1b2001767b37566428719f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 28 Aug 2023 13:59:30 +0200 Subject: [PATCH] fix cs --- src/Rector/AbstractRector.php | 54 ++++++++++--------- .../RenameString/config/configured_rule.php | 7 +-- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index eb148236a37..0fd0557f7df 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -195,7 +195,11 @@ final public function enterNode(Node $node): int|Node|null if (is_int($refactoredNode)) { $this->createdByRuleDecorator->decorate($node, $originalNode, static::class); - if (! in_array($refactoredNode, [NodeTraverser::DONT_TRAVERSE_CHILDREN, NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN], true)) { + if (! in_array( + $refactoredNode, + [NodeTraverser::DONT_TRAVERSE_CHILDREN, NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN], + true + )) { // notify this rule changing code $rectorWithLineChange = new RectorWithLineChange(static::class, $originalNode->getLine()); $this->file->addRectorClassWithLine($rectorWithLineChange); @@ -220,30 +224,6 @@ final public function enterNode(Node $node): int|Node|null return $this->postRefactorProcess($originalNode, $node, $refactoredNode, $filePath); } - private function decorateCurrentAndChildren(Node $node): void - { - // filter only types that - // 1. registered in getNodesTypes() method - // 2. different with current node type, as already decorated above - // - $otherTypes = array_filter( - $this->getNodeTypes(), - static fn (string $nodeType): bool => $nodeType !== $node::class - ); - - if ($otherTypes === []) { - return; - } - - $this->traverseNodesWithCallable($node, static function (Node $subNode) use ($otherTypes) { - if (in_array($subNode::class, $otherTypes, true)) { - $subNode->setAttribute(AttributeKey::SKIPPED_BY_RECTOR_RULE, static::class); - } - - return null; - }); - } - /** * Replacing nodes in leaveNode() method avoids infinite recursion * see"infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown @@ -316,6 +296,30 @@ protected function mirrorComments(Node $newNode, Node $oldNode): void } } + private function decorateCurrentAndChildren(Node $node): void + { + // filter only types that + // 1. registered in getNodesTypes() method + // 2. different with current node type, as already decorated above + // + $otherTypes = array_filter( + $this->getNodeTypes(), + static fn (string $nodeType): bool => $nodeType !== $node::class + ); + + if ($otherTypes === []) { + return; + } + + $this->traverseNodesWithCallable($node, static function (Node $subNode) use ($otherTypes) { + if (in_array($subNode::class, $otherTypes, true)) { + $subNode->setAttribute(AttributeKey::SKIPPED_BY_RECTOR_RULE, static::class); + } + + return null; + }); + } + /** * @param Node|Node[] $refactoredNode */ diff --git a/tests/Issues/RenameString/config/configured_rule.php b/tests/Issues/RenameString/config/configured_rule.php index 00197eb620c..d715e670f4e 100644 --- a/tests/Issues/RenameString/config/configured_rule.php +++ b/tests/Issues/RenameString/config/configured_rule.php @@ -1,10 +1,11 @@ rule(StringClassNameToClassConstantRector::class); @@ -12,7 +13,7 @@ $rectorConfig->ruleWithConfiguration( RenameStringRector::class, [ - 'Rector\Core\Tests\Issues\DoubleRun\Fixture\RenameString' => 'new test', + 'Rector\Core\Tests\Issues\DoubleRun\Fixture\RenameString' => 'new test', ] ); };