Completed
Pull Request — master (#196)
by Enrico
05:34 queued 41s
created

Variable::compile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

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