Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
94.74% |
18 / 19 |
|
74.07% |
20 / 27 |
|
44.44% |
8 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OffenseLevel | |
94.74% |
18 / 19 |
|
74.07% |
20 / 27 |
|
44.44% |
8 / 18 |
|
0.00% |
0 / 1 |
41.98 | |
0.00% |
0 / 1 |
| fromString | |
94.74% |
18 / 19 |
|
74.07% |
20 / 27 |
|
44.44% |
8 / 18 |
|
0.00% |
0 / 1 |
41.98 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Enum; |
| 4 | |
| 5 | /** |
| 6 | * @author Wilhelm Zwertvaegher |
| 7 | */ |
| 8 | enum OffenseLevel: int implements Enum |
| 9 | { |
| 10 | case LOW = 1; |
| 11 | |
| 12 | case MEDIUM = 5; |
| 13 | |
| 14 | case HIGH = 10; |
| 15 | |
| 16 | case VERY_HIGH = 15; |
| 17 | |
| 18 | case MAX = 20; |
| 19 | |
| 20 | public static function fromString(string $value): self |
| 21 | { |
| 22 | if (filter_var($value, FILTER_VALIDATE_INT)) { |
| 23 | $v = (int) $value; |
| 24 | try { |
| 25 | return self::from($v); |
| 26 | } catch (\Throwable $e) { |
| 27 | return ($v >= self::MAX->value) ? self::MAX : |
| 28 | ($v >= self::VERY_HIGH->value ? self::VERY_HIGH : |
| 29 | ($v >= self::HIGH->value ? self::HIGH : |
| 30 | ($v >= self::MEDIUM->value ? self::MEDIUM : |
| 31 | self::LOW |
| 32 | ))); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | $normalized = strtoupper(preg_replace('/[^A-Za-z_]/', '_', $value)); |
| 37 | |
| 38 | return match ($normalized) { |
| 39 | 'LOW' => self::LOW, |
| 40 | 'MEDIUM' => self::MEDIUM, |
| 41 | 'HIGH' => self::HIGH, |
| 42 | 'VERY_HIGH' => self::VERY_HIGH, |
| 43 | 'MAX' => self::MAX, |
| 44 | default => throw new \ValueError("Unknown offense level: {$normalized}"), |
| 45 | }; |
| 46 | } |
| 47 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 20 | public static function fromString(string $value): self |
| 21 | { |
| 22 | if (filter_var($value, FILTER_VALIDATE_INT)) { |
| 23 | $v = (int) $value; |
| 24 | try { |
| 25 | return self::from($v); |
| 26 | } catch (\Throwable $e) { |
| 27 | return ($v >= self::MAX->value) ? self::MAX : |
| 27 | return ($v >= self::MAX->value) ? self::MAX : |
| 28 | ($v >= self::VERY_HIGH->value ? self::VERY_HIGH : |
| 28 | ($v >= self::VERY_HIGH->value ? self::VERY_HIGH : |
| 29 | ($v >= self::HIGH->value ? self::HIGH : |
| 29 | ($v >= self::HIGH->value ? self::HIGH : |
| 30 | ($v >= self::MEDIUM->value ? self::MEDIUM : |
| 30 | ($v >= self::MEDIUM->value ? self::MEDIUM : |
| 31 | self::LOW |
| 31 | self::LOW |
| 31 | self::LOW |
| 31 | self::LOW |
| 31 | self::LOW |
| 36 | $normalized = strtoupper(preg_replace('/[^A-Za-z_]/', '_', $value)); |
| 36 | $normalized = strtoupper(preg_replace('/[^A-Za-z_]/', '_', $value)); |
| 36 | $normalized = strtoupper(preg_replace('/[^A-Za-z_]/', '_', $value)); |
| 36 | $normalized = strtoupper(preg_replace('/[^A-Za-z_]/', '_', $value)); |
| 37 | |
| 38 | return match ($normalized) { |
| 39 | 'LOW' => self::LOW, |
| 40 | 'MEDIUM' => self::MEDIUM, |
| 41 | 'HIGH' => self::HIGH, |
| 42 | 'VERY_HIGH' => self::VERY_HIGH, |
| 43 | 'MAX' => self::MAX, |
| 44 | default => throw new \ValueError("Unknown offense level: {$normalized}"), |
| 44 | default => throw new \ValueError("Unknown offense level: {$normalized}"), |
| 45 | }; |
| 46 | } |