Completed
Push — master ( 45984e...e3e24d )
by Enrico
17:48 queued 11:36
created

BooleanAnd::compile()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 2
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Compiler\Expression\Operators\Logical;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
class BooleanAnd extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BinaryOp\BooleanAnd';
13
14
    /**
15
     * {expr} && {expr}
16
     *
17
     * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 16
    protected function compile($expr, Context $context)
22
    {
23 16
        $left = $context->getExpressionCompiler()->compile($expr->left);
24 16
        $right = $context->getExpressionCompiler()->compile($expr->right);
25
26 16
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
27 15
            return CompiledExpression::fromZvalValue(
28 15
                $left->getValue() && $right->getValue()
29 15
            );
30
        }
31
32 1
        return new CompiledExpression();
33
    }
34
}
35