Completed
Push — master ( 9bf369...6fddd2 )
by Дмитрий
12:54 queued 09:14
created

VariableVariableUsage::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 9.6666
1
<?php
2
/**
3
 * @author Kévin Gomez https://github.com/K-Phoen <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Expression;
7
8
use PhpParser\Node\Expr;
9
use PHPSA\Analyzer\Pass;
10
use PHPSA\Context;
11
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
12
13
class VariableVariableUsage implements Pass\AnalyzerPassInterface, Pass\ConfigurablePassInterface
14
{
15
    /**
16
     * @param Expr\Assign $expr
17
     * @param Context $context
18
     * @return bool
19
     */
20 4
    public function pass(Expr\Assign $expr, Context $context)
21
    {
22 4
        if ($expr->var->name instanceof Expr\Variable) {
0 ignored issues
show
Bug introduced by
The property name does not seem to exist in PhpParser\Node\Expr.

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...
23 1
            $context->notice(
24 1
                'variable.dynamic_assignment',
25 1
                'Dynamic assignment is greatly discouraged.',
26
                $expr
27 1
            );
28
29 1
            return true;
30
        }
31
32 4
        return false;
33
    }
34
35
    /**
36
     * @return array
37
     */
38 1
    public function getRegister()
39
    {
40
        return [
41
            Expr\Assign::class
42 1
        ];
43
    }
44
45
    /**
46
     * @return TreeBuilder
47
     */
48
    public function getConfiguration()
49
    {
50
        $treeBuilder = new TreeBuilder();
51
        $treeBuilder->root('variable.dynamic_assignment')
52
            ->canBeDisabled()
53
        ;
54
55
        return $treeBuilder;
56
    }
57
}
58