Completed
Push — master ( 19c440...922200 )
by Дмитрий
06:07 queued 02:02
created

Identical::compile()   C

Complexity

Conditions 11
Paths 31

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 11

Importance

Changes 0
Metric Value
cc 11
eloc 17
nc 31
nop 2
dl 0
loc 23
ccs 19
cts 19
cp 1
crap 11
rs 5.3929
c 0
b 0
f 0

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::NUMBER:
32 28
            case CompiledExpression::NULL:
33 27
                switch ($right->getType()) {
34 27
                    case CompiledExpression::INTEGER:
35 27
                    case CompiledExpression::DOUBLE:
36 27
                    case CompiledExpression::BOOLEAN:
37 27
                    case CompiledExpression::NUMBER:
38 27
                    case CompiledExpression::NULL:
39 26
                        return new CompiledExpression(CompiledExpression::BOOLEAN, $left->getValue() === $right->getValue());
40 1
                }
41 2
        }
42
43 2
        return new CompiledExpression(CompiledExpression::BOOLEAN);
44
    }
45
}
46