No Description

NodeVisitor.php 2.0KB

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