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

Variable::compile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.5

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 16
ccs 5
cts 10
cp 0.5
crap 2.5
rs 9.4285
c 0
b 0
f 0
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