Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Result | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
| description | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| isSuccessful | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isCompleteSuccess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isFailure | |
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\Outcome; |
| 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 Result: string 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 Success = 'success'; |
| 44 | case Partial = 'partial'; |
| 45 | case Failure = 'failure'; |
| 46 | |
| 47 | /** |
| 48 | * @return string |
| 49 | */ |
| 50 | public function description(): string |
| 51 | { |
| 52 | return match ($this) { |
| 53 | self::Success => 'Operation completed successfully without notable issues.', |
| 54 | self::Partial => 'Operation completed only in part and may require follow-up.', |
| 55 | self::Failure => 'Operation did not complete successfully.', |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return bool |
| 61 | */ |
| 62 | public function isSuccessful(): bool |
| 63 | { |
| 64 | return $this->in([self::Success, self::Partial]); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return bool |
| 69 | */ |
| 70 | public function isCompleteSuccess(): bool |
| 71 | { |
| 72 | return $this->is(self::Success); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return bool |
| 77 | */ |
| 78 | public function isFailure(): bool |
| 79 | { |
| 80 | return $this->is(self::Failure); |
| 81 | } |
| 82 | } |