Completed
Push — master ( 30de07...1799ff )
by Дмитрий
03:30
created

ConstFetch::compile()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 2
dl 0
loc 19
ccs 9
cts 9
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
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 14
    protected function compile($expr, Context $context)
21
    {
22 14
        $compiler = $context->getExpressionCompiler();
23
24 14
        if ($expr->name instanceof Node\Name) {
25 14
            if ($expr->name->parts[0] === 'true') {
0 ignored issues
show
Deprecated Code introduced by
The property PhpParser\Node\Name::$parts has been deprecated with message: Avoid directly accessing $parts, use methods instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
26 10
                return new CompiledExpression(CompiledExpression::BOOLEAN, true);
27
            }
28
29 9
            if ($expr->name->parts[0] === 'false') {
0 ignored issues
show
Deprecated Code introduced by
The property PhpParser\Node\Name::$parts has been deprecated with message: Avoid directly accessing $parts, use methods instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
30 5
                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