Completed
Pull Request — master (#341)
by Strahinja
04:06
created

NotIdentical   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 14 3
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 1
    protected function compile($expr, Context $context)
23
    {
24 1
        $left = $context->getExpressionCompiler()->compile($expr->left);
25 1
        $right = $context->getExpressionCompiler()->compile($expr->right);
26
27 1
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
28 1
            return CompiledExpression::fromZvalValue(
29 1
                $left->getValue() !== $right->getValue()
30 1
            );
31
        }
32
33
34
        return new CompiledExpression();
35
    }
36
}
37