Completed
Push — master ( 1de1e9...5b3eaa )
by Дмитрий
02:56
created

Concat::compile()   D

Complexity

Conditions 13
Paths 124

Size

Total Lines 49
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 20.2458

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 13
eloc 36
c 2
b 1
f 0
nc 124
nop 2
dl 0
loc 49
ccs 26
cts 40
cp 0.65
crap 20.2458
rs 4.814

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
 * PHP Smart Analysis project 2015-2016
4
 *
5
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
6
 */
7
8
namespace PHPSA\Compiler\Expression\Operators;
9
10
use PhpParser\Node;
11
use PHPSA\CompiledExpression;
12
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
13
use PHPSA\Context;
14
use PHPSA\Compiler\Expression;
15
16
class Concat extends AbstractExpressionCompiler
17
{
18
    protected $name = 'PhpParser\Node\Expr\BinaryOp\Concat';
19
20
    /**
21
     * @param \PhpParser\Node\Expr\BinaryOp\Concat $expr
22
     * @param Context $context
23
     * @return CompiledExpression
24
     */
25 1
    protected function compile($expr, Context $context)
26
    {
27 1
        $expressionCompiler = $context->getExpressionCompiler();
28 1
        $leftExpression = $expressionCompiler->compile($expr->left);
29 1
        $rightExpression = $expressionCompiler->compile($expr->right);
30
31 1
        switch ($leftExpression->getType()) {
32 1
            case CompiledExpression::ARR:
33
                $context->notice(
34
                    'unsupported-operand-types',
35
                    'Unsupported operand types -{array}',
36
                    $expr
37
                );
38
                break;
39 1
        }
40
41 1
        switch ($rightExpression->getType()) {
42 1
            case CompiledExpression::ARR:
43
                $context->notice(
44
                    'unsupported-operand-types',
45
                    'Unsupported operand types -{array}',
46
                    $expr
47
                );
48
                break;
49 1
        }
50
51 1
        switch ($leftExpression->getType()) {
52 1
            case CompiledExpression::STRING:
53 1
            case CompiledExpression::NUMBER:
54 1
            case CompiledExpression::INTEGER:
55 1
            case CompiledExpression::DOUBLE:
56 1
            case CompiledExpression::BOOLEAN:
57 1
                switch ($rightExpression->getType()) {
58 1
                    case CompiledExpression::STRING:
59 1
                    case CompiledExpression::NUMBER:
60 1
                    case CompiledExpression::INTEGER:
61 1
                    case CompiledExpression::DOUBLE:
62 1
                    case CompiledExpression::BOOLEAN:
63
                        return new CompiledExpression(
64
                            CompiledExpression::STRING,
65
                            $leftExpression->getValue() . $rightExpression->getValue()
66
                        );
67
                        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...
68 1
                }
69 1
                break;
70 1
        }
71
72 1
        return new CompiledExpression(CompiledExpression::STRING);
73
    }
74
}
75