| Conditions | 3 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 46 | 3 | public static function caseWhen(array $cases, string $value = '', string $else = null): string |
|
| 47 | { |
||
| 48 | 3 | $command = "CASE {$value}"; |
|
| 49 | |||
| 50 | 3 | foreach ($cases as $condition => $statement) { |
|
| 51 | 3 | $command .= " WHEN {$condition} THEN {$statement}"; |
|
| 52 | } |
||
| 53 | |||
| 54 | 3 | if ($else) { |
|
|
|
|||
| 55 | 1 | $command .= " ELSE {$else}"; |
|
| 56 | } |
||
| 57 | |||
| 58 | 3 | $command .= " END"; |
|
| 59 | |||
| 60 | 3 | return new Expression($command); |
|
| 61 | } |
||
| 62 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: