Completed
Push — master ( fba3d8...90421b )
by Дмитрий
04:23 queued 23s
created

LogicalAnd::compile()   D

Complexity

Conditions 18
Paths 73

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 18

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 18
eloc 24
nc 73
nop 2
dl 0
loc 30
ccs 26
cts 26
cp 1
crap 18
rs 4.947
c 1
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\Operators\Logical;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
class LogicalAnd extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BinaryOp\LogicalAnd';
13
14
    /**
15
     * {expr} and {expr}
16
     *
17
     * @param \PhpParser\Node\Expr\BinaryOp\LogicalAnd $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 15
    protected function compile($expr, Context $context)
22
    {
23 15
        $left = $context->getExpressionCompiler()->compile($expr->left);
24 15
        $right = $context->getExpressionCompiler()->compile($expr->right);
25
26 15
        switch ($left->getType()) {
27 15
            case CompiledExpression::INTEGER:
28 15
            case CompiledExpression::DOUBLE:
29 15
            case CompiledExpression::STRING:
30 15
            case CompiledExpression::BOOLEAN:
31 15
            case CompiledExpression::NULL:
32 15
            case CompiledExpression::ARR:
33 15
            case CompiledExpression::NUMBER:
34 15
            case CompiledExpression::OBJECT:
35 15
                switch ($right->getType()) {
36 15
                    case CompiledExpression::INTEGER:
37 15
                    case CompiledExpression::DOUBLE:
38 15
                    case CompiledExpression::STRING:
39 15
                    case CompiledExpression::BOOLEAN:
40 15
                    case CompiledExpression::NULL:
41 15
                    case CompiledExpression::ARR:
42 15
                    case CompiledExpression::NUMBER:
43 15
                    case CompiledExpression::OBJECT:
44 14
                        return CompiledExpression::fromZvalValue($left->getValue() and $right->getValue());
45 1
                }
46 1
                break;
47 1
        }
48
49 1
        return new CompiledExpression(CompiledExpression::BOOLEAN);
50
    }
51
}
52