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 PhpParser\Node; |
11
|
|
|
use PHPSA\CompiledExpression; |
12
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
13
|
|
|
use PHPSA\Context; |
14
|
|
|
use PHPSA\Compiler\Expression; |
15
|
|
|
|
16
|
|
|
class Concat extends AbstractExpressionCompiler |
17
|
|
|
{ |
18
|
|
|
protected $name = 'PhpParser\Node\Expr\BinaryOp\Concat'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\Concat $expr |
22
|
|
|
* @param Context $context |
23
|
|
|
* @return CompiledExpression |
24
|
|
|
*/ |
25
|
1 |
|
protected function compile($expr, Context $context) |
26
|
|
|
{ |
27
|
1 |
|
$leftExpression = $context->getExpressionCompiler()->compile($expr->left); |
28
|
1 |
|
$rightExpression = $context->getExpressionCompiler()->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
|
|
|
break; |
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
|
|
|
break; |
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 |
|
switch ($rightExpression->getType()) { |
56
|
1 |
|
case CompiledExpression::STRING: |
57
|
1 |
|
case CompiledExpression::NUMBER: |
58
|
1 |
|
case CompiledExpression::INTEGER: |
59
|
1 |
|
case CompiledExpression::DOUBLE: |
60
|
|
|
return new CompiledExpression( |
61
|
|
|
CompiledExpression::STRING, |
62
|
|
|
$leftExpression->getValue() . $rightExpression->getValue() |
63
|
|
|
); |
64
|
|
|
break; |
|
|
|
|
65
|
1 |
|
} |
66
|
1 |
|
break; |
67
|
1 |
|
} |
68
|
|
|
|
69
|
1 |
|
return new CompiledExpression(CompiledExpression::NULL); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
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.