1 | <?php |
||
13 | class MissingBreakStatement implements Pass\AnalyzerPassInterface |
||
14 | { |
||
15 | use DefaultMetadataPassTrait; |
||
16 | |||
17 | const DESCRIPTION = 'Checks for a missing break or return statement in switch cases. Can ignore empty cases and the last case.'; |
||
18 | |||
19 | /** |
||
20 | * @param Stmt\Switch_ $switchStmt |
||
21 | * @param Context $context |
||
22 | * @return bool |
||
23 | */ |
||
24 | 2 | public function pass(Stmt\Switch_ $switchStmt, Context $context) |
|
25 | { |
||
26 | 2 | $result = false; |
|
27 | 2 | $caseStmts = $switchStmt->cases; |
|
28 | |||
29 | 2 | if (count($caseStmts) < 2) { |
|
30 | 1 | return $result; |
|
31 | } |
||
32 | |||
33 | 2 | array_pop($caseStmts); // the last case statement CAN have no "break" or "return" |
|
34 | |||
35 | /** @var Stmt\Case_ $case */ |
||
36 | 2 | foreach ($caseStmts as $case) { |
|
37 | 2 | $result = $this->checkCaseStatement($case, $context) || $result; |
|
38 | } |
||
39 | |||
40 | 2 | return $result; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return array |
||
45 | */ |
||
46 | 2 | public function getRegister() |
|
52 | |||
53 | /** |
||
54 | * @param Stmt\Case_ $case |
||
55 | * @param Context $context |
||
56 | * @return bool |
||
57 | */ |
||
58 | 2 | private function checkCaseStatement(Stmt\Case_ $case, Context $context) |
|
94 | } |
||
95 |