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

VariableVariableUsage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
ccs 10
cts 15
cp 0.6667
rs 10
wmc 4
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 14 2
A getRegister() 0 6 1
A getConfiguration() 0 9 1
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