Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
30 / 30 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Month | |
100.00% |
30 / 30 |
|
100.00% |
4 / 4 |
16 | |
100.00% |
1 / 1 |
| description | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
13 | |||
| quarter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isQuarterEnd | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ordered | |
100.00% |
14 / 14 |
|
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\Calendar; |
| 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 Month: int 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 January = 1; |
| 44 | case February = 2; |
| 45 | case March = 3; |
| 46 | case April = 4; |
| 47 | case May = 5; |
| 48 | case June = 6; |
| 49 | case July = 7; |
| 50 | case August = 8; |
| 51 | case September = 9; |
| 52 | case October = 10; |
| 53 | case November = 11; |
| 54 | case December = 12; |
| 55 | |
| 56 | /** |
| 57 | * @return string |
| 58 | */ |
| 59 | public function description(): string |
| 60 | { |
| 61 | return match ($this) { |
| 62 | self::January => 'Month 1 of the Gregorian calendar, commonly associated with yearly planning.', |
| 63 | self::February => 'Month 2 of the Gregorian calendar, with 28 days or 29 in leap years.', |
| 64 | self::March => 'Month 3 of the Gregorian calendar, often used as the end of the first quarter.', |
| 65 | self::April => 'Month 4 of the Gregorian calendar, following the close of Q1 in many businesses.', |
| 66 | self::May => 'Month 5 of the Gregorian calendar, typically part of the second quarter.', |
| 67 | self::June => 'Month 6 of the Gregorian calendar and common end of the first half-year.', |
| 68 | self::July => 'Month 7 of the Gregorian calendar and common start of the second half-year.', |
| 69 | self::August => 'Month 8 of the Gregorian calendar, often used in summer scheduling contexts.', |
| 70 | self::September => 'Month 9 of the Gregorian calendar and common start of many annual cycles.', |
| 71 | self::October => 'Month 10 of the Gregorian calendar, typically within fourth-quarter planning.', |
| 72 | self::November => 'Month 11 of the Gregorian calendar, often used for year-end preparation.', |
| 73 | self::December => 'Month 12 of the Gregorian calendar and common close of fiscal or calendar years.', |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @return int |
| 79 | */ |
| 80 | public function quarter(): int |
| 81 | { |
| 82 | return (int) ceil($this->value / 3); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return bool |
| 87 | */ |
| 88 | public function isQuarterEnd(): bool |
| 89 | { |
| 90 | return $this->in([self::March, self::June, self::September, self::December]); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return list<self> |
| 95 | */ |
| 96 | public static function ordered(): array |
| 97 | { |
| 98 | return [ |
| 99 | self::January, |
| 100 | self::February, |
| 101 | self::March, |
| 102 | self::April, |
| 103 | self::May, |
| 104 | self::June, |
| 105 | self::July, |
| 106 | self::August, |
| 107 | self::September, |
| 108 | self::October, |
| 109 | self::November, |
| 110 | self::December, |
| 111 | ]; |
| 112 | } |
| 113 | } |