NodeTraverser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addVisitor() 0 4 1
A walk() 0 4 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