Skip to content

Commit 1654cef

Browse files
authored
[traversing] Decouple Rector rules from PhpParser NodeVisitor (#8541)
1 parent eb70369 commit 1654cef

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

‎src/Contract/Rector/RectorInterface.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpParser\NodeVisitor;
99
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
1010

11-
interface RectorInterface extends NodeVisitor, DocumentedRuleInterface
11+
interface RectorInterface extends DocumentedRuleInterface
1212
{
1313
/**
1414
* List of nodes this class checks, classes that implements \PhpParser\Node
@@ -18,6 +18,11 @@ interface RectorInterface extends NodeVisitor, DocumentedRuleInterface
1818
*/
1919
public function getNodeTypes(): array;
2020

21+
/**
22+
* @return int|Node|Node[]|null
23+
*/
24+
public function enterNode(Node $node): int|Node|array|null;
25+
2126
/**
2227
* Process Node of matched type
2328
* @return Node|Node[]|null|NodeVisitor::REMOVE_NODE

‎src/Rector/AbstractRector.php‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Rector\Rector;
66

7-
use Deprecated;
87
use PhpParser\Node;
98
use PhpParser\Node\Expr;
109
use PhpParser\Node\Name;
@@ -17,7 +16,6 @@
1716
use PhpParser\NodeTraverser;
1817
use PhpParser\NodeVisitor;
1918
use PhpParser\NodeVisitor\CloningVisitor;
20-
use PhpParser\NodeVisitorAbstract;
2119
use PHPStan\Analyser\MutatingScope;
2220
use PHPStan\Type\ObjectType;
2321
use PHPStan\Type\Type;
@@ -40,7 +38,7 @@
4038
use Rector\Skipper\ValueObject\SkipMatch;
4139
use Rector\ValueObject\Application\File;
4240

43-
abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface
41+
abstract class AbstractRector implements RectorInterface
4442
{
4543
private const string EMPTY_NODE_ARRAY_MESSAGE = <<<CODE_SAMPLE
4644
Array of nodes cannot be empty. Ensure "%s->refactor()" returns non-empty array for Nodes.
@@ -103,26 +101,6 @@ public function autowire(
103101
$this->commentsMerger = $commentsMerger;
104102
}
105103

106-
/**
107-
* @return Node[]|null
108-
*
109-
* @internal
110-
*/
111-
final public function beforeTraverse(array $nodes): ?array
112-
{
113-
return null;
114-
}
115-
116-
/**
117-
* @return Node[]|null
118-
*
119-
* @internal
120-
*/
121-
final public function afterTraverse(array $nodes)
122-
{
123-
return null;
124-
}
125-
126104
/**
127105
* @return NodeVisitor::REMOVE_NODE|Node|null|Node[]
128106
*/
@@ -190,12 +168,6 @@ final public function enterNode(Node $node): int|Node|null|array
190168
return $this->postRefactorProcess($originalNode, $node, $refactoredNodeOrState, $filePath);
191169
}
192170

193-
#[Deprecated(message: 'no longer used')]
194-
final public function leaveNode(Node $node): array|int|Node|null
195-
{
196-
return null;
197-
}
198-
199171
protected function getFile(): File
200172
{
201173
$file = $this->currentFileProvider->getFile();

0 commit comments

Comments
 (0)