Completed
Pull Request — master (#354)
by Strahinja
04:13
created

Concat::compile()   C

Complexity

Conditions 11
Paths 31

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
eloc 18
nc 31
nop 2
dl 0
loc 25
ccs 0
cts 18
cp 0
crap 132
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
    protected function compile($expr, Context $context)
22
    {
23
        $left = $context->getExpressionCompiler()->compile($expr->var);
24
        $expExpression = $context->getExpressionCompiler()->compile($expr->expr);
25
26
        switch ($left->getType()) {
27
            case CompiledExpression::INTEGER:
28
            case CompiledExpression::DOUBLE:
29
            case CompiledExpression::NUMBER:
30
            case CompiledExpression::STRING:
31
            case CompiledExpression::BOOLEAN:
32
                switch ($expExpression->getType()) {
33
                    case CompiledExpression::INTEGER:
34
                    case CompiledExpression::DOUBLE:
35
                    case CompiledExpression::NUMBER:
36
                    case CompiledExpression::STRING:
37
                    case CompiledExpression::BOOLEAN:
38
                        return CompiledExpression::fromZvalValue(
39
                            $left->getValue() . $expExpression->getValue()
40
                        );
41
                }
42
        }
43
44
        return new CompiledExpression();
45
    }
46
}
47