Skip to content

Commit

Permalink
fix cs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 28, 2023
1 parent eac3d46 commit 2f38105
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
54 changes: 29 additions & 25 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
7 changes: 4 additions & 3 deletions tests/Issues/RenameString/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

declare(strict_types=1);
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Renaming\Rector\String_\RenameStringRector;

use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;

use Rector\Renaming\Rector\String_\RenameStringRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(StringClassNameToClassConstantRector::class);

$rectorConfig->ruleWithConfiguration(
RenameStringRector::class,
[
'Rector\Core\Tests\Issues\DoubleRun\Fixture\RenameString' => 'new test',
'Rector\Core\Tests\Issues\DoubleRun\Fixture\RenameString' => 'new test',
]
);
};

0 comments on commit 2f38105

Please sign in to comment.