NodeTraverser::addVisitor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SQLParser\Node\Traverser;
4
5
use SQLParser\Node\NodeInterface;
6
7
/**
8
 * This class can be used to traverse the tree of nodes.
9
 */
10
class NodeTraverser
11
{
12
    const DONT_TRAVERSE_CHILDREN = 'DONT_TRAVERSE_CHILDREN';
13
    const REMOVE_NODE = 'REMOVE_NODE';
14
15
    private $visitor;
16
17
    public function __construct()
18
    {
19
        $this->visitor = new CompositeVisitor();
20
    }
21
22
    /**
23
     * Registers a new visitor with this traverser.
24
     *
25
     * @param VisitorInterface $visitor
26
     */
27
    public function addVisitor(VisitorInterface $visitor)
28
    {
29
        $this->visitor->addVisitor($visitor);
30
    }
31
32
    /**
33
     * Starts traversing the tree, calling each visitor on each node.
34
     *
35
     * @param NodeInterface $node
36
     */
37
    public function walk(NodeInterface $node)
38
    {
39
        $node->walk($this->visitor);
40
    }
41
}
42