Documentation

NodeVisitor

Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd4927802f7df1

Copyright (c) 2011, Nikita Popov All rights reserved.

Table of Contents

afterTraverse()  : array<string|int, Node>|null
Called once after traversal.
beforeTraverse()  : array<string|int, Node>|null
Called once before traversal.
enterNode()  : Node|array<string|int, Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser::*|null
Called when entering a node.
leaveNode()  : Node|array<string|int, Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser::REMOVE_NODE|\PHPStan\PhpDocParser\Ast\NodeTraverser::STOP_TRAVERSAL|null
Called when leaving a node.

Methods

afterTraverse()

Called once after traversal.

public afterTraverse(array<string|int, Node$nodes) : array<string|int, Node>|null

Return value semantics:

  • null: $nodes stays as-is
  • otherwise: $nodes is set to the return value
Parameters
$nodes : array<string|int, Node>

Array of nodes

Return values
array<string|int, Node>|null

Array of nodes

beforeTraverse()

Called once before traversal.

public beforeTraverse(array<string|int, Node$nodes) : array<string|int, Node>|null

Return value semantics:

  • null: $nodes stays as-is
  • otherwise: $nodes is set to the return value
Parameters
$nodes : array<string|int, Node>

Array of nodes

Return values
array<string|int, Node>|null

Array of nodes

enterNode()

Called when entering a node.

public enterNode(Node $node) : Node|array<string|int, Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser::*|null

Return value semantics:

  • null => $node stays as-is
  • array (of Nodes) => The return value is merged into the parent array (at the position of the $node)
  • NodeTraverser::REMOVE_NODE => $node is removed from the parent array
  • NodeTraverser::DONT_TRAVERSE_CHILDREN => Children of $node are not traversed. $node stays as-is
  • NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN => Further visitors for the current node are skipped, and its children are not traversed. $node stays as-is.
  • NodeTraverser::STOP_TRAVERSAL => Traversal is aborted. $node stays as-is
  • otherwise => $node is set to the return value
Parameters
$node : Node

Node

Return values
Node|array<string|int, Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser::*|null

Replacement node (or special return value)

leaveNode()

Called when leaving a node.

public leaveNode(Node $node) : Node|array<string|int, Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser::REMOVE_NODE|\PHPStan\PhpDocParser\Ast\NodeTraverser::STOP_TRAVERSAL|null

Return value semantics:

  • null => $node stays as-is
  • NodeTraverser::REMOVE_NODE => $node is removed from the parent array
  • NodeTraverser::STOP_TRAVERSAL => Traversal is aborted. $node stays as-is
  • array (of Nodes) => The return value is merged into the parent array (at the position of the $node)
  • otherwise => $node is set to the return value
Parameters
$node : Node

Node

Return values
Node|array<string|int, Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser::REMOVE_NODE|\PHPStan\PhpDocParser\Ast\NodeTraverser::STOP_TRAVERSAL|null

Replacement node (or special return value)

Search results