Completed
Pull Request — master (#122)
by Enrico
03:22
created

Concat   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 39
ccs 0
cts 22
cp 0
rs 10
wmc 11
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
C compile() 0 27 11
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
                        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
                }
43
                break;
44
        }
45
46
        return new CompiledExpression(CompiledExpression::UNKNOWN);
47
    }
48
}
49