Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CaseSensitivity | |
100.00% |
8 / 8 |
|
100.00% |
5 / 5 |
8 | |
100.00% |
1 / 1 |
| reverse | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| isSensitive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isInsensitive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| normalize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| equals | |
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\Sort; |
| 20 | |
| 21 | use FastForward\Enum\ReversibleInterface; |
| 22 | use FastForward\Enum\Trait\Comparable; |
| 23 | use FastForward\Enum\Trait\HasNameLookup; |
| 24 | use FastForward\Enum\Trait\HasNameMap; |
| 25 | use FastForward\Enum\Trait\HasNames; |
| 26 | |
| 27 | enum CaseSensitivity implements ReversibleInterface |
| 28 | { |
| 29 | use Comparable; |
| 30 | use HasNameLookup; |
| 31 | use HasNameMap; |
| 32 | use HasNames; |
| 33 | |
| 34 | case Sensitive; |
| 35 | case Insensitive; |
| 36 | |
| 37 | /** |
| 38 | * @return static |
| 39 | */ |
| 40 | public function reverse(): static |
| 41 | { |
| 42 | return match ($this) { |
| 43 | self::Sensitive => self::Insensitive, |
| 44 | self::Insensitive => self::Sensitive, |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return bool |
| 50 | */ |
| 51 | public function isSensitive(): bool |
| 52 | { |
| 53 | return $this->is(self::Sensitive); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return bool |
| 58 | */ |
| 59 | public function isInsensitive(): bool |
| 60 | { |
| 61 | return $this->is(self::Insensitive); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @param string $value |
| 66 | * |
| 67 | * @return string |
| 68 | */ |
| 69 | public function normalize(string $value): string |
| 70 | { |
| 71 | return $this->isInsensitive() ? mb_strtolower($value) : $value; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param string $left |
| 76 | * @param string $right |
| 77 | * |
| 78 | * @return bool |
| 79 | */ |
| 80 | public function equals(string $left, string $right): bool |
| 81 | { |
| 82 | return $this->normalize($left) === $this->normalize($right); |
| 83 | } |
| 84 | } |