Completed
Push — master ( 090344...474eef )
by Дмитрий
02:42
created

NotIdentical   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 11
c 4
b 0
f 1
lcom 0
cbo 4
dl 0
loc 39
ccs 21
cts 21
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C compile() 0 26 11
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 14
    protected function compile($expr, Context $context)
23
    {
24 14
        $expression = new Expression($context);
25 14
        $left = $expression->compile($expr->left);
26
27 14
        $expression = new Expression($context);
28 14
        $right = $expression->compile($expr->right);
29
30 14
        switch ($left->getType()) {
31 14
            case CompiledExpression::INTEGER:
32 14
            case CompiledExpression::DOUBLE:
33 14
            case CompiledExpression::BOOLEAN:
34 14
            case CompiledExpression::NUMBER:
35 14
            case CompiledExpression::NULL:
36 13
                switch ($right->getType()) {
37 13
                    case CompiledExpression::INTEGER:
38 13
                    case CompiledExpression::DOUBLE:
39 13
                    case CompiledExpression::BOOLEAN:
40 13
                    case CompiledExpression::NUMBER:
41 13
                    case CompiledExpression::NULL:
42 12
                        return new CompiledExpression(CompiledExpression::BOOLEAN, $left->getValue() !== $right->getValue());
43 1
                }
44 2
        }
45
46 2
        return new CompiledExpression(CompiledExpression::BOOLEAN);
47
    }
48
}
49