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

Identical::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 Identical extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BinaryOp\Identical';
13
14
    /**
15
     * It's used in conditions
16
     * {left-expr} === {right-expr}
17
     *
18
     * @param \PhpParser\Node\Expr\BinaryOp\Identical $expr
19
     * @param Context $context
20
     * @return CompiledExpression
21
     */
22 28
    protected function compile($expr, Context $context)
23
    {
24 28
        $left = $context->getExpressionCompiler()->compile($expr->left);
25 28
        $right = $context->getExpressionCompiler()->compile($expr->right);
26
27 28
        switch ($left->getType()) {
28 28
            case CompiledExpression::INTEGER:
29 28
            case CompiledExpression::DOUBLE:
30 28
            case CompiledExpression::BOOLEAN:
31 28
            case CompiledExpression::ARR:
32 28
            case CompiledExpression::OBJECT:
33 28
            case CompiledExpression::STRING:
34 28
            case CompiledExpression::NUMBER:
35 28
            case CompiledExpression::RESOURCE:
36 28
            case CompiledExpression::CALLABLE_TYPE:
37 28
            case CompiledExpression::NULL:
38 27
                switch ($right->getType()) {
39 27
                    case CompiledExpression::INTEGER:
40 27
                    case CompiledExpression::DOUBLE:
41 27
                    case CompiledExpression::BOOLEAN:
42 27
                    case CompiledExpression::ARR:
43 27
                    case CompiledExpression::OBJECT:
44 27
                    case CompiledExpression::STRING:
45 27
                    case CompiledExpression::NUMBER:
46 27
                    case CompiledExpression::RESOURCE:
47 27
                    case CompiledExpression::CALLABLE_TYPE:
48 27
                    case CompiledExpression::NULL:
49 26
                        return CompiledExpression::fromZvalValue(
50 26
                            $left->getValue() === $right->getValue()
51 26
                        );
52 1
                }
53 2
        }
54
55 2
        return new CompiledExpression();
56
    }
57
}
58