ContextualVisitor   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 6
dl 0
loc 95
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A beforeTraverse() 0 8 1
B enterNode() 0 26 6
B leaveNode() 0 18 6
A afterTraverse() 0 4 1
A before() 0 4 1
A enter() 0 4 1
A leave() 0 4 1
A after() 0 4 1
1
<?php
2
3
namespace Solidifier\Parser\Visitors;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Stmt\Class_;
7
use PhpParser\Node\Stmt\Interface_;
8
use PhpParser\Node\Stmt\Trait_;
9
use PhpParser\Node\Stmt\Namespace_;
10
use PhpParser\Node\Stmt\ClassMethod;
11
use Solidifier\Visitors\ObjectType;
12
13
abstract class ContextualVisitor extends AbstractVisitor
14
{
15
    protected
16
        $nodeStack,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $nodeStack.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
17
        $currentNamespace,
18
        $currentObjectType,
19
        $currentMethod;
20
21
    public function __construct()
22
    {
23
        parent::__construct();
24
        
25
        $this->nodeStack = new \SplStack();
26
    }
27
    
28
    final public function beforeTraverse(array $nodes)
29
    {
30
        $this->currentNamespace = null;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        $this->currentObjectType = null;
32
        $this->currentMethod = null;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
        
34
        $this->before($nodes);
35
    }
36
    
37
    final public function enterNode(Node $node)
38
    {
39
        if($node instanceof Namespace_)
40
        {
41
            $this->currentNamespace = $node->name;
42
        }
43
        elseif($node instanceof Class_)
44
        {
45
            $this->currentObjectType = new ObjectType($this->currentNamespace, $node->name);
46
        }
47
        elseif($node instanceof Interface_)
48
        {
49
            $this->currentObjectType = new ObjectType($this->currentNamespace, $node->name, ObjectType::TYPE_INTERFACE);
50
        }
51
        elseif($node instanceof Trait_)
52
        {
53
            $this->currentObjectType = new ObjectType($this->currentNamespace, $node->name, ObjectType::TYPE_TRAIT);
54
        }
55
        elseif($node instanceof ClassMethod)
56
        {
57
            $this->currentMethod = $node;
58
        }
59
        
60
        $this->enter($node);
61
        $this->nodeStack->push($node);
62
    }
63
    
64
    final public function leaveNode(Node $node)
65
    {
66
        if($node instanceof Namespace_)
67
        {
68
            $this->currentNamespace = null;
69
        }
70
        elseif($node instanceof Class_ || $node instanceof Interface_ || $node instanceof Trait_)
71
        {
72
            $this->currentObjectType = null;
73
        }
74
        elseif($node instanceof ClassMethod)
75
        {
76
            $this->currentMethod = null;
77
        }
78
        
79
        $this->leave($node);
80
        $this->nodeStack->pop();
81
    }
82
    
83
    final public function afterTraverse(array $nodes)
84
    {
85
        $this->after($nodes);
86
    }
87
    
88
    protected function before(array $nodes)
0 ignored issues
show
Unused Code introduced by
The parameter $nodes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
    {
90
        
91
    }
92
    
93
    protected function enter(Node $node)
94
    {
95
        
96
    }
97
    
98
    protected function leave(Node $node)
99
    {
100
        
101
    }
102
    
103
    protected function after(array $nodes)
0 ignored issues
show
Unused Code introduced by
The parameter $nodes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
    {
105
        
106
    }
107
}