Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
51 / 51 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
| Gender | |
100.00% |
51 / 51 |
|
100.00% |
14 / 14 |
17 | |
100.00% |
1 / 1 |
| label | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| fullNamePtBr | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| shortName | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| pronoun | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| pronounPtBr | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| isMale | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isFemale | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isNonBinary | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isSpecified | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| labelList | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toArrayWithLabels | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toArrayPtBr | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| binary | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace DevToolbelt\Enums\Personal; |
| 6 | |
| 7 | use DevToolbelt\Enums\EnumInterface; |
| 8 | |
| 9 | enum Gender: string implements EnumInterface |
| 10 | { |
| 11 | case MALE = 'M'; |
| 12 | case FEMALE = 'F'; |
| 13 | case NON_BINARY = 'NB'; |
| 14 | case OTHER = 'O'; |
| 15 | case PREFER_NOT_TO_SAY = 'N'; |
| 16 | |
| 17 | public function label(): string |
| 18 | { |
| 19 | return match ($this) { |
| 20 | self::MALE => 'Male', |
| 21 | self::FEMALE => 'Female', |
| 22 | self::NON_BINARY => 'Non-binary', |
| 23 | self::OTHER => 'Other', |
| 24 | self::PREFER_NOT_TO_SAY => 'Prefer not to say', |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | public function fullNamePtBr(): string |
| 29 | { |
| 30 | return match ($this) { |
| 31 | self::MALE => 'Masculino', |
| 32 | self::FEMALE => 'Feminino', |
| 33 | self::NON_BINARY => 'Não-binário', |
| 34 | self::OTHER => 'Outro', |
| 35 | self::PREFER_NOT_TO_SAY => 'Prefiro não informar', |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | public function shortName(): string |
| 40 | { |
| 41 | return match ($this) { |
| 42 | self::MALE => 'M', |
| 43 | self::FEMALE => 'F', |
| 44 | self::NON_BINARY => 'NB', |
| 45 | self::OTHER => 'O', |
| 46 | self::PREFER_NOT_TO_SAY => 'N/A', |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | public function pronoun(): string |
| 51 | { |
| 52 | return match ($this) { |
| 53 | self::MALE => 'he/him', |
| 54 | self::FEMALE => 'she/her', |
| 55 | self::NON_BINARY => 'they/them', |
| 56 | self::OTHER, self::PREFER_NOT_TO_SAY => 'they/them', |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | public function pronounPtBr(): string |
| 61 | { |
| 62 | return match ($this) { |
| 63 | self::MALE => 'ele/dele', |
| 64 | self::FEMALE => 'ela/dela', |
| 65 | self::NON_BINARY => 'elu/delu', |
| 66 | self::OTHER, self::PREFER_NOT_TO_SAY => 'elu/delu', |
| 67 | }; |
| 68 | } |
| 69 | |
| 70 | public function isMale(): bool |
| 71 | { |
| 72 | return $this === self::MALE; |
| 73 | } |
| 74 | |
| 75 | public function isFemale(): bool |
| 76 | { |
| 77 | return $this === self::FEMALE; |
| 78 | } |
| 79 | |
| 80 | public function isNonBinary(): bool |
| 81 | { |
| 82 | return $this === self::NON_BINARY; |
| 83 | } |
| 84 | |
| 85 | public function isSpecified(): bool |
| 86 | { |
| 87 | return $this !== self::PREFER_NOT_TO_SAY; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return string[] |
| 92 | */ |
| 93 | public function labelList(): array |
| 94 | { |
| 95 | return array_map(fn (self $case) => $case->label(), self::cases()); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @return array<string, string> |
| 100 | */ |
| 101 | public static function toArray(): array |
| 102 | { |
| 103 | $result = []; |
| 104 | |
| 105 | foreach (self::cases() as $gender) { |
| 106 | $result[$gender->value] = $gender->value; |
| 107 | } |
| 108 | |
| 109 | return $result; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return array<string, string> |
| 114 | */ |
| 115 | public static function toArrayWithLabels(): array |
| 116 | { |
| 117 | $result = []; |
| 118 | |
| 119 | foreach (self::cases() as $gender) { |
| 120 | $result[$gender->value] = $gender->label(); |
| 121 | } |
| 122 | |
| 123 | return $result; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @return array<string, string> |
| 128 | */ |
| 129 | public static function toArrayPtBr(): array |
| 130 | { |
| 131 | $result = []; |
| 132 | |
| 133 | foreach (self::cases() as $gender) { |
| 134 | $result[$gender->value] = $gender->fullNamePtBr(); |
| 135 | } |
| 136 | |
| 137 | return $result; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @return self[] |
| 142 | */ |
| 143 | public static function binary(): array |
| 144 | { |
| 145 | return [self::MALE, self::FEMALE]; |
| 146 | } |
| 147 | } |