Completed
Push — master ( f7db50...090344 )
by Дмитрий
03:31
created

NotEqual::compile()   C

Complexity

Conditions 11
Paths 31

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 27
ccs 0
cts 22
cp 0
rs 5.2653
cc 11
eloc 20
nc 31
nop 2
crap 132

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 Static Analysis project 2015
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
    protected function compile($expr, Context $context)
28
    {
29
        $expression = new Expression($context);
30
        $left = $expression->compile($expr->left);
31
32
        $expression = new Expression($context);
33
        $right = $expression->compile($expr->right);
34
35
        switch ($left->getType()) {
36
            case CompiledExpression::INTEGER:
37
            case CompiledExpression::DOUBLE:
38
            case CompiledExpression::BOOLEAN:
39
            case CompiledExpression::ARR:
40
            case CompiledExpression::OBJECT:
41
                switch ($right->getType()) {
42
                    case CompiledExpression::INTEGER:
43
                    case CompiledExpression::DOUBLE:
44
                    case CompiledExpression::BOOLEAN:
45
                    case CompiledExpression::ARR:
46
                    case CompiledExpression::OBJECT:
47
                        return new CompiledExpression(CompiledExpression::BOOLEAN, $left->getValue() != $right->getValue());
48
                }
49
                break;
50
        }
51
52
        return new CompiledExpression(CompiledExpression::BOOLEAN);
53
    }
54
}
55