Skip to content

Commit 861a7f4

Browse files
committed
Add getVisitorsForNode() method to NodeTraverser
1 parent 0105ba1 commit 861a7f4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/PhpParser/NodeTraverser.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ protected function traverseNode(Node $node): void {
110110
$traverseChildren = true;
111111
$visitorIndex = -1;
112112

113-
foreach ($this->visitors as $visitorIndex => $visitor) {
113+
$visitors = $this->getVisitorsForNode($subNode);
114+
foreach ($visitors as $visitorIndex => $visitor) {
114115
$return = $visitor->enterNode($subNode);
115116
if (null !== $return) {
116117
if ($return instanceof Node) {
@@ -143,7 +144,7 @@ protected function traverseNode(Node $node): void {
143144
}
144145

145146
for (; $visitorIndex >= 0; --$visitorIndex) {
146-
$visitor = $this->visitors[$visitorIndex];
147+
$visitor = $visitors[$visitorIndex];
147148
$return = $visitor->leaveNode($subNode);
148149

149150
if (null !== $return) {
@@ -192,7 +193,8 @@ protected function traverseArray(array $nodes): array {
192193
$traverseChildren = true;
193194
$visitorIndex = -1;
194195

195-
foreach ($this->visitors as $visitorIndex => $visitor) {
196+
$visitors = $this->getVisitorsForNode($node);
197+
foreach ($visitors as $visitorIndex => $visitor) {
196198
$return = $visitor->enterNode($node);
197199
if (null !== $return) {
198200
if ($return instanceof Node) {
@@ -231,7 +233,7 @@ protected function traverseArray(array $nodes): array {
231233
}
232234

233235
for (; $visitorIndex >= 0; --$visitorIndex) {
234-
$visitor = $this->visitors[$visitorIndex];
236+
$visitor = $visitors[$visitorIndex];
235237
$return = $visitor->leaveNode($node);
236238

237239
if (null !== $return) {
@@ -268,6 +270,14 @@ protected function traverseArray(array $nodes): array {
268270
return $nodes;
269271
}
270272

273+
/**
274+
* @return NodeVisitor[]
275+
*/
276+
public function getVisitorsForNode(Node $node)
277+
{
278+
return $this->visitors;
279+
}
280+
271281
private function ensureReplacementReasonable(Node $old, Node $new): void {
272282
if ($old instanceof Node\Stmt && $new instanceof Node\Expr) {
273283
throw new \LogicException(

0 commit comments

Comments
 (0)