Completed
Pull Request — master (#177)
by
unknown
04:21 queued 01:12
created

Concat::compile()   C

Complexity

Conditions 11
Paths 31

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 11.6363

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 11
eloc 20
nc 31
nop 2
dl 0
loc 27
ccs 19
cts 23
cp 0.8261
crap 11.6363
rs 5.2653
c 3
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::STRING:
32 1
            case CompiledExpression::NUMBER:
33 1
            case CompiledExpression::INTEGER:
34 1
            case CompiledExpression::DOUBLE:
35 1
            case CompiledExpression::BOOLEAN:
36 1
                switch ($rightExpression->getType()) {
37 1
                    case CompiledExpression::STRING:
38 1
                    case CompiledExpression::NUMBER:
39 1
                    case CompiledExpression::INTEGER:
40 1
                    case CompiledExpression::DOUBLE:
41 1
                    case CompiledExpression::BOOLEAN:
42
                        return new CompiledExpression(
43
                            CompiledExpression::STRING,
44
                            $leftExpression->getValue() . $rightExpression->getValue()
45
                        );
46 1
                }
47 1
        }
48
49 1
        return new CompiledExpression();
50
    }
51
}
52