1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\PhpDocParser\Ast; |
4: | |
5: | /** |
6: | * Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd4927802f7df1 |
7: | * |
8: | * Copyright (c) 2011, Nikita Popov |
9: | * All rights reserved. |
10: | */ |
11: | interface NodeVisitor |
12: | { |
13: | |
14: | /** |
15: | * Called once before traversal. |
16: | * |
17: | * Return value semantics: |
18: | * * null: $nodes stays as-is |
19: | * * otherwise: $nodes is set to the return value |
20: | * |
21: | * @param Node[] $nodes Array of nodes |
22: | * |
23: | * @return Node[]|null Array of nodes |
24: | */ |
25: | public function beforeTraverse(array $nodes): ?array; |
26: | |
27: | /** |
28: | * Called when entering a node. |
29: | * |
30: | * Return value semantics: |
31: | * * null |
32: | * => $node stays as-is |
33: | * * array (of Nodes) |
34: | * => The return value is merged into the parent array (at the position of the $node) |
35: | * * NodeTraverser::REMOVE_NODE |
36: | * => $node is removed from the parent array |
37: | * * NodeTraverser::DONT_TRAVERSE_CHILDREN |
38: | * => Children of $node are not traversed. $node stays as-is |
39: | * * NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN |
40: | * => Further visitors for the current node are skipped, and its children are not |
41: | * traversed. $node stays as-is. |
42: | * * NodeTraverser::STOP_TRAVERSAL |
43: | * => Traversal is aborted. $node stays as-is |
44: | * * otherwise |
45: | * => $node is set to the return value |
46: | * |
47: | * @param Node $node Node |
48: | * |
49: | * @return Node|Node[]|NodeTraverser::*|null Replacement node (or special return value) |
50: | */ |
51: | public function enterNode(Node $node); |
52: | |
53: | /** |
54: | * Called when leaving a node. |
55: | * |
56: | * Return value semantics: |
57: | * * null |
58: | * => $node stays as-is |
59: | * * NodeTraverser::REMOVE_NODE |
60: | * => $node is removed from the parent array |
61: | * * NodeTraverser::STOP_TRAVERSAL |
62: | * => Traversal is aborted. $node stays as-is |
63: | * * array (of Nodes) |
64: | * => The return value is merged into the parent array (at the position of the $node) |
65: | * * otherwise |
66: | * => $node is set to the return value |
67: | * |
68: | * @param Node $node Node |
69: | * |
70: | * @return Node|Node[]|NodeTraverser::REMOVE_NODE|NodeTraverser::STOP_TRAVERSAL|null Replacement node (or special return value) |
71: | */ |
72: | public function leaveNode(Node $node); |
73: | |
74: | /** |
75: | * Called once after traversal. |
76: | * |
77: | * Return value semantics: |
78: | * * null: $nodes stays as-is |
79: | * * otherwise: $nodes is set to the return value |
80: | * |
81: | * @param Node[] $nodes Array of nodes |
82: | * |
83: | * @return Node[]|null Array of nodes |
84: | */ |
85: | public function afterTraverse(array $nodes): ?array; |
86: | |
87: | } |
88: |