1: <?php declare(strict_types=1);
2:
3: namespace PhpParser;
4:
5: interface NodeVisitor
6: {
7: /**
8: * Called once before traversal.
9: *
10: * Return value semantics:
11: * * null: $nodes stays as-is
12: * * otherwise: $nodes is set to the return value
13: *
14: * @param Node[] $nodes Array of nodes
15: *
16: * @return null|Node[] Array of nodes
17: */
18: public function beforeTraverse(array $nodes);
19:
20: /**
21: * Called when entering a node.
22: *
23: * Return value semantics:
24: * * null
25: * => $node stays as-is
26: * * NodeTraverser::DONT_TRAVERSE_CHILDREN
27: * => Children of $node are not traversed. $node stays as-is
28: * * NodeTraverser::STOP_TRAVERSAL
29: * => Traversal is aborted. $node stays as-is
30: * * otherwise
31: * => $node is set to the return value
32: *
33: * @param Node $node Node
34: *
35: * @return null|int|Node Replacement node (or special return value)
36: */
37: public function enterNode(Node $node);
38:
39: /**
40: * Called when leaving a node.
41: *
42: * Return value semantics:
43: * * null
44: * => $node stays as-is
45: * * NodeTraverser::REMOVE_NODE
46: * => $node is removed from the parent array
47: * * NodeTraverser::STOP_TRAVERSAL
48: * => Traversal is aborted. $node stays as-is
49: * * array (of Nodes)
50: * => The return value is merged into the parent array (at the position of the $node)
51: * * otherwise
52: * => $node is set to the return value
53: *
54: * @param Node $node Node
55: *
56: * @return null|int|Node|Node[] Replacement node (or special return value)
57: */
58: public function leaveNode(Node $node);
59:
60: /**
61: * Called once after traversal.
62: *
63: * Return value semantics:
64: * * null: $nodes stays as-is
65: * * otherwise: $nodes is set to the return value
66: *
67: * @param Node[] $nodes Array of nodes
68: *
69: * @return null|Node[] Array of nodes
70: */
71: public function afterTraverse(array $nodes);
72: }
73: