Completed
Push — master ( 69939e...ded049 )
by Enrico
02:49
created

ConstFetch::compile()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 19
ccs 8
cts 9
cp 0.8889
crap 4.0218
rs 9.2
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 4
    protected function compile($expr, Context $context)
21
    {
22 4
        $compiler = $context->getExpressionCompiler();
23
24 4
        if ($expr->name instanceof Node\Name) {
25 4
            if ($expr->name->toString() === 'true') {
26 3
                return new CompiledExpression(CompiledExpression::BOOLEAN, true);
27
            }
28
29 2
            if ($expr->name->toString() === 'false') {
30
                return new CompiledExpression(CompiledExpression::BOOLEAN, false);
31
            }
32 2
        }
33
34
        /**
35
         * @todo Implement check
36
         */
37 2
        return $compiler->compile($expr->name);
38
    }
39
}
40