Completed
Pull Request — master (#124)
by Enrico
07:25
created

Concat::compile()   C

Complexity

Conditions 13
Paths 33

Size

Total Lines 49
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 20.2458

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 13
eloc 36
nc 33
nop 2
dl 0
loc 49
ccs 26
cts 40
cp 0.65
crap 20.2458
rs 5.1401
c 2
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
 * 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 PHPSA\CompiledExpression;
11
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
12
use PHPSA\Context;
13
use PHPSA\Compiler\Expression;
14
15
class Concat extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\BinaryOp\Concat';
18
19
    /**
20
     * @param \PhpParser\Node\Expr\BinaryOp\Concat $expr
21
     * @param Context $context
22
     * @return CompiledExpression
23
     */
24 1
    protected function compile($expr, Context $context)
25
    {
26 1
        $expressionCompiler = $context->getExpressionCompiler();
27 1
        $leftExpression = $expressionCompiler->compile($expr->left);
28 1
        $rightExpression = $expressionCompiler->compile($expr->right);
29
30 1
        switch ($leftExpression->getType()) {
31 1
            case CompiledExpression::ARR:
32
                $context->notice(
33
                    'unsupported-operand-types',
34
                    'Unsupported operand types -{array}',
35
                    $expr
36
                );
37
                return new CompiledExpression(CompiledExpression::UNKNOWN);
38 1
        }
39
40 1
        switch ($rightExpression->getType()) {
41 1
            case CompiledExpression::ARR:
42
                $context->notice(
43
                    'unsupported-operand-types',
44
                    'Unsupported operand types -{array}',
45
                    $expr
46
                );
47
                return new CompiledExpression(CompiledExpression::UNKNOWN);
48 1
        }
49
50 1
        switch ($leftExpression->getType()) {
51 1
            case CompiledExpression::STRING:
52 1
            case CompiledExpression::NUMBER:
53 1
            case CompiledExpression::INTEGER:
54 1
            case CompiledExpression::DOUBLE:
55 1
            case CompiledExpression::BOOLEAN:
56 1
                switch ($rightExpression->getType()) {
57 1
                    case CompiledExpression::STRING:
58 1
                    case CompiledExpression::NUMBER:
59 1
                    case CompiledExpression::INTEGER:
60 1
                    case CompiledExpression::DOUBLE:
61 1
                    case CompiledExpression::BOOLEAN:
62
                        return new CompiledExpression(
63
                            CompiledExpression::STRING,
64
                            $leftExpression->getValue() . $rightExpression->getValue()
65
                        );
66
                        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...
67 1
                }
68 1
                break;
69 1
        }
70
71 1
        return new CompiledExpression(CompiledExpression::STRING);
72
    }
73
}
74