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

NotEqual::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
 * PHP Smart Analysis project 2015-2016
4
 *
5
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
6
 */
7
8
namespace PHPSA\Compiler\Expression\BinaryOp;
9
10
use PHPSA\CompiledExpression;
11
use PHPSA\Context;
12
use PHPSA\Compiler\Expression;
13
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
14
15
class NotEqual extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\BinaryOp\NotEqual';
18
19
    /**
20
     * It's used in conditions
21
     * {left-expr} != {right-expr}
22
     *
23
     * @param \PhpParser\Node\Expr\BinaryOp\NotEqual $expr
24
     * @param Context $context
25
     * @return CompiledExpression
26
     */
27 17
    protected function compile($expr, Context $context)
28
    {
29 17
        $left = $context->getExpressionCompiler()->compile($expr->left);
30 17
        $right = $context->getExpressionCompiler()->compile($expr->right);
31
32 17
        switch ($left->getType()) {
33 17
            case CompiledExpression::INTEGER:
34 17
            case CompiledExpression::DOUBLE:
35 17
            case CompiledExpression::BOOLEAN:
36 17
            case CompiledExpression::ARR:
37 17
            case CompiledExpression::OBJECT:
38 17
            case CompiledExpression::STRING:
39 17
            case CompiledExpression::NUMBER:
40 17
            case CompiledExpression::RESOURCE:
41 17
            case CompiledExpression::CALLABLE_TYPE:
42 17
            case CompiledExpression::NULL:
43 16
                switch ($right->getType()) {
44 16
                    case CompiledExpression::INTEGER:
45 16
                    case CompiledExpression::DOUBLE:
46 16
                    case CompiledExpression::BOOLEAN:
47 16
                    case CompiledExpression::ARR:
48 16
                    case CompiledExpression::OBJECT:
49 16
                    case CompiledExpression::STRING:
50 16
                    case CompiledExpression::NUMBER:
51 16
                    case CompiledExpression::RESOURCE:
52 16
                    case CompiledExpression::CALLABLE_TYPE:
53 16
                    case CompiledExpression::NULL:
54 15
                        return CompiledExpression::fromZvalValue(
55 15
                            $left->getValue() != $right->getValue()
56 15
                        );
57 1
                }
58 2
        }
59
60 2
        return new CompiledExpression();
61
    }
62
}
63