Completed
Push — master ( be4467...8bad52 )
by Дмитрий
02:43
created

Variable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 5
cts 10
cp 0.5
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 16 2
1
<?php
2
3
namespace PHPSA\Compiler\Expression;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
class Variable extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\Variable';
13
14
    /**
15
     * $a
16
     *
17
     * @param \PhpParser\Node\Expr\Variable $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 2
    protected function compile($expr, Context $context)
22
    {
23 2
        $variable = $context->getSymbol($expr->name);
24 2
        if ($variable) {
25 2
            $variable->incGets();
26 2
            return new CompiledExpression($variable->getType(), $variable->getValue(), $variable);
27
        }
28
29
        $context->notice(
30
            'undefined-variable',
31
            sprintf('You are trying to use an undefined variable $%s', $expr->name),
32
            $expr
33
        );
34
35
        return new CompiledExpression();
36
    }
37
}
38