Completed
Push — master ( aecd2c...b9491d )
by Дмитрий
09:52 queued 06:00
created

BooleanOr::compile()   C

Complexity

Conditions 12
Paths 31

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 12

Importance

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

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 10
    protected function compile($expr, Context $context)
22
    {
23 10
        $expression = new Expression($context);
24 10
        $left = $expression->compile($expr->left);
25
26 10
        $expression = new Expression($context);
27 10
        $right = $expression->compile($expr->right);
28
29 10
        switch ($left->getType()) {
30 10
            case CompiledExpression::LNUMBER:
31 10
            case CompiledExpression::DNUMBER:
32 10
            case CompiledExpression::STRING:
33 10
            case CompiledExpression::BOOLEAN:
34 10
            case CompiledExpression::NULL:
35 10
                switch ($right->getType()) {
36 10
                    case CompiledExpression::LNUMBER:
37 10
                    case CompiledExpression::DNUMBER:
38 10
                    case CompiledExpression::STRING:
39 10
                    case CompiledExpression::BOOLEAN:
40 10
                    case CompiledExpression::NULL:
41 9
                        return CompiledExpression::fromZvalValue($left->getValue() || $right->getValue());
42 1
                }
43 1
                break;
44 1
        }
45
46 1
        return new CompiledExpression(CompiledExpression::BOOLEAN);
47
    }
48
}
49