Completed
Pull Request — master (#196)
by Enrico
06:58
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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 1
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 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