Completed
Push — master ( f4ee71...8ccc11 )
by Povilas
02:10
created

HintVisitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B enterNode() 0 19 5
1
<?php
2
3
namespace Povils\PHPMND\Visitor;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Const_;
7
use PhpParser\Node\Scalar;
8
use PhpParser\Node\Stmt\Class_;
9
use PhpParser\Node\Stmt\ClassConst;
10
use PhpParser\NodeTraverser;
11
use PhpParser\NodeVisitorAbstract;
12
use Povils\PHPMND\HintList;
13
14
/**
15
 * Class HintVisitor
16
 *
17
 * @package Povils\PHPMND\Visitor
18
 */
19
class HintVisitor extends NodeVisitorAbstract
20
{
21
    /**
22
     * @var HintList
23
     */
24
    private $hintList;
25
26
    /**
27
     * @param HintList $hintList
28
     */
29
    public function __construct(HintList $hintList)
30
    {
31
        $this->hintList = $hintList;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function enterNode(Node $node)
38
    {
39
        if ($node instanceof Const_) {
40
            if (false === $node->value instanceof Scalar) {
41
                return NodeTraverser::DONT_TRAVERSE_CHILDREN;
42
            }
43
44
            $constantValue = $node->value->value;
1 ignored issue
show
Bug introduced by
The property value does not seem to exist in PhpParser\Node\Scalar.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
45
            $constParent = $node->getAttribute('parent');
46
            if ($constParent instanceof ClassConst) {
47
                $classConstParent = $constParent->getAttribute('parent');
48
                if ($classConstParent instanceof Class_) {
49
                    $this->hintList->addClassCont($constantValue, $classConstParent->name, $node->name);
50
                }
51
            }
52
        }
53
54
        return null;
55
    }
56
}
57