Completed
Push — master ( 8bad52...c13fe7 )
by Дмитрий
03:41
created

Variable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 10
cts 10
cp 1
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 24
    protected function compile($expr, Context $context)
22
    {
23 24
        $variable = $context->getSymbol($expr->name);
24 24
        if ($variable) {
25 23
            $variable->incGets();
26 24
            return new CompiledExpression($variable->getType(), $variable->getValue(), $variable);
27
        }
28
29 2
        $context->notice(
30 2
            'undefined-variable',
31 2
            sprintf('You are trying to use an undefined variable $%s', $expr->name),
32
            $expr
33 2
        );
34
35 2
        return new CompiledExpression();
36
    }
37
}
38