|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Patsura Dmitry https://github.com/ovr <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace PHPSA\Compiler\Statement; |
|
7
|
|
|
|
|
8
|
|
|
use PHPSA\CompiledExpression; |
|
9
|
|
|
use PHPSA\Context; |
|
10
|
|
|
use PHPSA\Definition\ClassMethod; |
|
11
|
|
|
use PHPSA\Compiler\Expression; |
|
12
|
|
|
|
|
13
|
|
|
class SwitchSt extends AbstractCompiler |
|
14
|
|
|
{ |
|
15
|
|
|
protected $name = '\PhpParser\Node\Stmt\Switch_'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param \PhpParser\Node\Stmt\Switch_ $stmt |
|
19
|
|
|
* @param Context $context |
|
20
|
|
|
* @return CompiledExpression |
|
21
|
|
|
*/ |
|
22
|
|
|
public function compile($stmt, Context $context) |
|
23
|
|
|
{ |
|
24
|
|
|
$expression = new Expression($context); |
|
25
|
|
|
$expression->compile($stmt->cond); |
|
26
|
|
|
|
|
27
|
|
|
if (count($stmt->cases)) { |
|
28
|
|
|
foreach ($stmt->cases as $case) { |
|
29
|
|
|
if ($case->cond) { |
|
30
|
|
|
$expression = new Expression($context); |
|
31
|
|
|
$expression->compile($case->cond); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (count($case->stmts) > 0) { |
|
35
|
|
|
$beforeStatement = false; |
|
36
|
|
|
|
|
37
|
|
|
foreach ($case->stmts as $stmt) { |
|
38
|
|
|
\PHPSA\nodeVisitorFactory($stmt, $context); |
|
39
|
|
|
|
|
40
|
|
|
if ($beforeStatement) { |
|
41
|
|
|
if ($beforeStatement instanceof \PhpParser\Node\Stmt\Return_ |
|
42
|
|
|
&& $stmt instanceof \PhpParser\Node\Stmt\Break_) { |
|
43
|
|
|
$context->notice( |
|
44
|
|
|
'switch.unneeded-break', |
|
45
|
|
|
'Break after return statement is not needed', |
|
46
|
|
|
$stmt |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
$beforeStatement = $stmt; |
|
51
|
|
|
} |
|
52
|
|
|
} else { |
|
53
|
|
|
$context->notice('not-implemented-body', 'Missing body', $case); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} else { |
|
57
|
|
|
//@todo implement |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|