Completed
Pull Request — master (#120)
by Enrico
02:58
created

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