Completed
Push — master ( 28d1f7...8f0d0f )
by Enrico
05:45
created

ConstFetch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 19 4
1
<?php
2
3
namespace PHPSA\Compiler\Expression;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PhpParser\Node;
8
9
class ConstFetch extends AbstractExpressionCompiler
10
{
11
    protected $name = 'PhpParser\Node\Expr\ConstFetch';
12
13
    /**
14
     * true, CONSTANTNAME, ...
15
     *
16
     * @param \PhpParser\Node\Expr\ConstFetch $expr
17
     * @param Context $context
18
     * @return CompiledExpression
19
     */
20 15
    protected function compile($expr, Context $context)
21
    {
22 15
        $compiler = $context->getExpressionCompiler();
23
24 15
        if ($expr->name instanceof Node\Name) {
25 15
            if ($expr->name->toString() === 'true') {
26 10
                return new CompiledExpression(CompiledExpression::BOOLEAN, true);
27
            }
28
29 10
            if ($expr->name->toString() === 'false') {
30 6
                return new CompiledExpression(CompiledExpression::BOOLEAN, false);
31
            }
32 4
        }
33
34
        /**
35
         * @todo Implement check
36
         */
37 4
        return $compiler->compile($expr->name);
38
    }
39
}
40