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

Concat   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 74.36%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 57
ccs 29
cts 39
cp 0.7436
rs 10
c 2
b 0
f 0
wmc 13
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
C compile() 0 47 13
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 15
    protected function compile($expr, Context $context)
25
    {
26 15
        $expressionCompiler = $context->getExpressionCompiler();
27 15
        $leftExpression = $expressionCompiler->compile($expr->left);
28 15
        $rightExpression = $expressionCompiler->compile($expr->right);
29
30 15
        switch ($leftExpression->getType()) {
31 15
            case CompiledExpression::ARR:
32
                $context->notice(
33
                    'unsupported-operand-types',
34
                    'Unsupported operand types -{array}',
35
                    $expr
36
                );
37
                return new CompiledExpression();
38 15
        }
39
40 15
        switch ($rightExpression->getType()) {
41 15
            case CompiledExpression::ARR:
42
                $context->notice(
43
                    'unsupported-operand-types',
44
                    'Unsupported operand types -{array}',
45
                    $expr
46
                );
47
                return new CompiledExpression();
48 15
        }
49
50 15
        switch ($leftExpression->getType()) {
51 15
            case CompiledExpression::STRING:
52 15
            case CompiledExpression::NUMBER:
53 15
            case CompiledExpression::INTEGER:
54 15
            case CompiledExpression::DOUBLE:
55 15
            case CompiledExpression::BOOLEAN:
56 14
                switch ($rightExpression->getType()) {
57 14
                    case CompiledExpression::STRING:
58 14
                    case CompiledExpression::NUMBER:
59 14
                    case CompiledExpression::INTEGER:
60 14
                    case CompiledExpression::DOUBLE:
61 14
                    case CompiledExpression::BOOLEAN:
62 12
                        return new CompiledExpression(
63 12
                            CompiledExpression::STRING,
64 12
                            $leftExpression->getValue() . $rightExpression->getValue()
65 12
                        );
66 2
                }
67 3
        }
68
69 3
        return new CompiledExpression();
70
    }
71
}
72