Completed
Push — master ( 558809...774145 )
by Дмитрий
03:36
created

Concat::compile()   C

Complexity

Conditions 11
Paths 31

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 11

Importance

Changes 0
Metric Value
cc 11
eloc 20
nc 31
nop 2
dl 0
loc 27
ccs 22
cts 22
cp 1
crap 11
rs 5.2653
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\AssignOp;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Compiler\Expression;
7
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
8
use PHPSA\Context;
9
10
class Concat extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\AssignOp\Concat';
13
14
    /**
15
     * {left-expr} .= {right-expr}
16
     *
17
     * @param \PhpParser\Node\Expr\AssignOp\Concat $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 14
    protected function compile($expr, Context $context)
22
    {
23 14
        $left = $context->getExpressionCompiler()->compile($expr->var);
24 14
        $expExpression = $context->getExpressionCompiler()->compile($expr->expr);
25
26 14
        switch ($left->getType()) {
27 14
            case CompiledExpression::INTEGER:
28 14
            case CompiledExpression::DOUBLE:
29 14
            case CompiledExpression::NUMBER:
30 14
            case CompiledExpression::STRING:
31 14
            case CompiledExpression::BOOLEAN:
32 13
                switch ($expExpression->getType()) {
33 13
                    case CompiledExpression::INTEGER:
34 13
                    case CompiledExpression::DOUBLE:
35 13
                    case CompiledExpression::NUMBER:
36 13
                    case CompiledExpression::STRING:
37 13
                    case CompiledExpression::BOOLEAN:
38 12
                        return CompiledExpression::fromZvalValue(
39 12
                            $left->getValue() . $expExpression->getValue()
40 12
                        );
41
                        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
42 1
                }
43 1
                break;
44 2
        }
45
46 2
        return new CompiledExpression(CompiledExpression::UNKNOWN);
47
    }
48
}
49