| Conditions | 5 |
| Paths | 5 |
| Total Lines | 34 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 53 | 2 | private function checkCaseStatement(Stmt\Case_ $case, Context $context) |
|
| 54 | { |
||
| 55 | /* |
||
| 56 | * switch(…) { |
||
| 57 | * case 41: |
||
| 58 | * case 42: |
||
| 59 | * case 43: |
||
| 60 | * return 'the truth, or almost.'; |
||
| 61 | * } |
||
| 62 | */ |
||
| 63 | 2 | if (!$case->stmts) { |
|
|
|
|||
| 64 | 1 | return false; |
|
| 65 | } |
||
| 66 | |||
| 67 | 2 | foreach ($case->stmts as $node) { |
|
| 68 | // look for a break statement |
||
| 69 | 2 | if ($node instanceof Stmt\Break_) { |
|
| 70 | 2 | return false; |
|
| 71 | } |
||
| 72 | |||
| 73 | // or for a return |
||
| 74 | 1 | if ($node instanceof Stmt\Return_) { |
|
| 75 | 1 | return false; |
|
| 76 | } |
||
| 77 | 1 | } |
|
| 78 | |||
| 79 | 1 | $context->notice( |
|
| 80 | 1 | 'missing_break_statement', |
|
| 81 | 1 | 'Missing "break" statement', |
|
| 82 | $case |
||
| 83 | 1 | ); |
|
| 84 | |||
| 85 | 1 | return true; |
|
| 86 | } |
||
| 87 | } |
||
| 88 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.