NodeVisitor.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  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: $node stays as-is
  22. * * otherwise: $node is set to the return value
  23. *
  24. * @param Node $node Node
  25. *
  26. * @return null|Node Node
  27. */
  28. public function enterNode(Node $node);
  29. /**
  30. * Called when leaving a node.
  31. *
  32. * Return value semantics:
  33. * * null: $node stays as-is
  34. * * false: $node is removed from the parent array
  35. * * array: The return value is merged into the parent array (at the position of the $node)
  36. * * otherwise: $node is set to the return value
  37. *
  38. * @param Node $node Node
  39. *
  40. * @return null|Node|false|Node[] Node
  41. */
  42. public function leaveNode(Node $node);
  43. /**
  44. * Called once after traversal.
  45. *
  46. * Return value semantics:
  47. * * null: $nodes stays as-is
  48. * * otherwise: $nodes is set to the return value
  49. *
  50. * @param Node[] $nodes Array of nodes
  51. *
  52. * @return null|Node[] Array of nodes
  53. */
  54. public function afterTraverse(array $nodes);
  55. }