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

NotIdentical::compile()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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