Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| NullsPosition | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
12 | |
100.00% |
1 / 1 |
| reverse | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| isFirst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isLast | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| compareNullability | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
7 | |||
| 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 NullsPosition implements ReversibleInterface |
| 28 | { |
| 29 | use Comparable; |
| 30 | use HasNameLookup; |
| 31 | use HasNameMap; |
| 32 | use HasNames; |
| 33 | |
| 34 | case First; |
| 35 | case Last; |
| 36 | |
| 37 | /** |
| 38 | * @return static |
| 39 | */ |
| 40 | public function reverse(): static |
| 41 | { |
| 42 | return match ($this) { |
| 43 | self::First => self::Last, |
| 44 | self::Last => self::First, |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return bool |
| 50 | */ |
| 51 | public function isFirst(): bool |
| 52 | { |
| 53 | return $this->is(self::First); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return bool |
| 58 | */ |
| 59 | public function isLast(): bool |
| 60 | { |
| 61 | return $this->is(self::Last); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @param mixed $left |
| 66 | * @param mixed $right |
| 67 | * |
| 68 | * @return int |
| 69 | */ |
| 70 | public function compareNullability(mixed $left, mixed $right): int |
| 71 | { |
| 72 | if (null === $left && null === $right) { |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | if (null === $left) { |
| 77 | return $this->isFirst() ? -1 : 1; |
| 78 | } |
| 79 | |
| 80 | if (null === $right) { |
| 81 | return $this->isFirst() ? 1 : -1; |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | } |