Completed
Push — master ( 40ee83...aecd2c )
by Дмитрий
07:12 queued 02:11
created

BooleanOr::compile()   C

Complexity

Conditions 12
Paths 31

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 22
cp 0
rs 5.1612
cc 12
eloc 20
nc 31
nop 2
crap 156

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