Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Priority | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
| description | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
5 | |||
| weight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isHigherThan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isLowerThan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ordered | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Ergonomic utilities for PHP enums, including names, values, lookups, and option maps. |
| 7 | * |
| 8 | * This file is part of fast-forward/enum project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/enum |
| 14 | * @see https://github.com/php-fast-forward/enum/issues |
| 15 | * @see https://php-fast-forward.github.io/enum/ |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\Enum\Common; |
| 20 | |
| 21 | use FastForward\Enum\DescribedEnumInterface; |
| 22 | use FastForward\Enum\LabeledEnumInterface; |
| 23 | use FastForward\Enum\Trait\Comparable; |
| 24 | use FastForward\Enum\Trait\HasLabel; |
| 25 | use FastForward\Enum\Trait\HasNameLookup; |
| 26 | use FastForward\Enum\Trait\HasNameMap; |
| 27 | use FastForward\Enum\Trait\HasNames; |
| 28 | use FastForward\Enum\Trait\HasOptions; |
| 29 | use FastForward\Enum\Trait\HasValueMap; |
| 30 | use FastForward\Enum\Trait\HasValues; |
| 31 | |
| 32 | enum Priority: int implements DescribedEnumInterface, LabeledEnumInterface |
| 33 | { |
| 34 | use Comparable; |
| 35 | use HasLabel; |
| 36 | use HasNameLookup; |
| 37 | use HasNameMap; |
| 38 | use HasNames; |
| 39 | use HasOptions; |
| 40 | use HasValueMap; |
| 41 | use HasValues; |
| 42 | |
| 43 | case Low = 10; |
| 44 | case Normal = 20; |
| 45 | case High = 30; |
| 46 | case Critical = 40; |
| 47 | |
| 48 | /** |
| 49 | * @return string |
| 50 | */ |
| 51 | public function description(): string |
| 52 | { |
| 53 | return match ($this) { |
| 54 | self::Low => 'Can be handled later with minimal impact if delayed.', |
| 55 | self::Normal => 'Default priority for routine work and expected processing order.', |
| 56 | self::High => 'Needs prompt attention because delays may affect users or delivery.', |
| 57 | self::Critical => 'Requires immediate attention due to severe business or operational impact.', |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return int |
| 63 | */ |
| 64 | public function weight(): int |
| 65 | { |
| 66 | return $this->value; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @param self $other |
| 71 | * |
| 72 | * @return bool |
| 73 | */ |
| 74 | public function isHigherThan(self $other): bool |
| 75 | { |
| 76 | return $this->value > $other->value; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @param self $other |
| 81 | * |
| 82 | * @return bool |
| 83 | */ |
| 84 | public function isLowerThan(self $other): bool |
| 85 | { |
| 86 | return $this->value < $other->value; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @return list<self> |
| 91 | */ |
| 92 | public static function ordered(): array |
| 93 | { |
| 94 | return [self::Low, self::Normal, self::High, self::Critical]; |
| 95 | } |
| 96 | } |