Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| HasNameLookup | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| tryFromName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| fromName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| hasName | |
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\Trait; |
| 20 | |
| 21 | use FastForward\Enum\Helper\EnumHelper; |
| 22 | |
| 23 | trait HasNameLookup |
| 24 | { |
| 25 | /** |
| 26 | * @param string $name |
| 27 | * |
| 28 | * @return self|null |
| 29 | */ |
| 30 | public static function tryFromName(string $name): ?self |
| 31 | { |
| 32 | /** @var self|null $case */ |
| 33 | $case = EnumHelper::tryFromName(self::class, $name); |
| 34 | |
| 35 | return $case; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param string $name |
| 40 | * |
| 41 | * @return self |
| 42 | */ |
| 43 | public static function fromName(string $name): self |
| 44 | { |
| 45 | /** @var self $case */ |
| 46 | $case = EnumHelper::fromName(self::class, $name); |
| 47 | |
| 48 | return $case; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param string $name |
| 53 | * |
| 54 | * @return bool |
| 55 | */ |
| 56 | public static function hasName(string $name): bool |
| 57 | { |
| 58 | return EnumHelper::hasName(self::class, $name); |
| 59 | } |
| 60 | } |