Completed
Pull Request — master (#124)
by Enrico
04:04
created

NotIdentical::compile()   D

Complexity

Conditions 21
Paths 111

Size

Total Lines 35
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 21

Importance

Changes 0
Metric Value
cc 21
eloc 28
c 0
b 0
f 0
nc 111
nop 2
dl 0
loc 35
ccs 31
cts 31
cp 1
crap 21
rs 4.7032

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        $left = $context->getExpressionCompiler()->compile($expr->left);
25 14
        $right = $context->getExpressionCompiler()->compile($expr->right);
26
27 14
        switch ($left->getType()) {
28 14
            case CompiledExpression::INTEGER:
29 14
            case CompiledExpression::DOUBLE:
30 14
            case CompiledExpression::BOOLEAN:
31 14
            case CompiledExpression::ARR:
32 14
            case CompiledExpression::OBJECT:
33 14
            case CompiledExpression::STRING:
34 14
            case CompiledExpression::NUMBER:
35 14
            case CompiledExpression::RESOURCE:
36 14
            case CompiledExpression::CALLABLE_TYPE:
37 14
            case CompiledExpression::NULL:
38 13
                switch ($right->getType()) {
39 13
                    case CompiledExpression::INTEGER:
40 13
                    case CompiledExpression::DOUBLE:
41 13
                    case CompiledExpression::BOOLEAN:
42 13
                    case CompiledExpression::ARR:
43 13
                    case CompiledExpression::OBJECT:
44 13
                    case CompiledExpression::STRING:
45 13
                    case CompiledExpression::NUMBER:
46 13
                    case CompiledExpression::RESOURCE:
47 13
                    case CompiledExpression::CALLABLE_TYPE:
48 13
                    case CompiledExpression::NULL:
49 12
                        return CompiledExpression::fromZvalValue(
50 12
                            $left->getValue() !== $right->getValue()
51 12
                        );
52 1
                }
53 2
        }
54
55 2
        return new CompiledExpression();
56
    }
57
}
58