Completed
Pull Request — master (#149)
by Enrico
03:38
created

EmptyOp   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 6
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 22 6
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
use PhpParser\Node\Expr\Variable;
10
use PhpParser\Node\Name;
11
12
class EmptyOp extends AbstractExpressionCompiler
13
{
14
    protected $name = 'PhpParser\Node\Expr\Empty_';
15
16
    /**
17
     * empty({expr]})
18
     *
19
     * @param \PhpParser\Node\Expr\Empty_ $expr
20
     * @param Context $context
21
     * @return CompiledExpression
22
     */
23 5
    protected function compile($expr, Context $context)
24
    {
25 5
        if ($expr->expr instanceof Variable) {
26 5
            $varName = $expr->expr->name;
27
28 5
            if ($varName instanceof Name) {
29 5
                $varName = $varName->parts[0];
30 5
            }
31
32 5
            $variable = $context->getSymbol($varName);
33
34 5
            if ($variable) {
35 4
                $variable->incUse();
36
37 4
                if ($variable->getValue() !== null && $variable->getValue() != false) {
38 1
                    return CompiledExpression::fromZvalValue(true);
39
                }
40 3
            }
41 4
        }
42
43 4
        return CompiledExpression::fromZvalValue(false);
44
    }
45
}
46