Completed
Pull Request — master (#38)
by Pádraic
02:51
created

ParentConnectorVisitor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeTraverse() 0 4 1
A enterNode() 0 7 2
A leaveNode() 0 4 1
1
<?php
2
3
namespace PHPMND\Visitor;
4
5
use PhpParser\Node;
6
use PhpParser\NodeVisitorAbstract;
7
8
class ParentConnectorVisitor extends NodeVisitorAbstract
9
{
10
    /**
11
     * @var array
12
     */
13
    private $stack;
14
15
    /**
16
     * @inheritdoc
17
     */
18
    public function beforeTraverse(array $nodes)
19
    {
20
        $this->stack = [];
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function enterNode(Node $node)
27
    {
28
        if (false === empty($this->stack)) {
29
            $node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
30
        }
31
        $this->stack[] = $node;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function leaveNode(Node $node)
38
    {
39
        array_pop($this->stack);
40
    }
41
}
42