Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Weekday | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
11 | |
100.00% |
1 / 1 |
| description | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
8 | |||
| isWeekend | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isWeekday | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ordered | |
100.00% |
9 / 9 |
|
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 Weekday: 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 Monday = 1; |
| 44 | case Tuesday = 2; |
| 45 | case Wednesday = 3; |
| 46 | case Thursday = 4; |
| 47 | case Friday = 5; |
| 48 | case Saturday = 6; |
| 49 | case Sunday = 7; |
| 50 | |
| 51 | /** |
| 52 | * @return string |
| 53 | */ |
| 54 | public function description(): string |
| 55 | { |
| 56 | return match ($this) { |
| 57 | self::Monday => 'First business day of the ISO week in most workflows and calendars.', |
| 58 | self::Tuesday => 'Second day of the ISO week, commonly used for regular working schedules.', |
| 59 | self::Wednesday => 'Midweek day often used for routine meetings and delivery checkpoints.', |
| 60 | self::Thursday => 'Late-week working day before typical end-of-week wrap-up.', |
| 61 | self::Friday => 'Final common business day before the weekend in many regions.', |
| 62 | self::Saturday => 'Weekend day typically treated as non-working in standard business calendars.', |
| 63 | self::Sunday => 'Weekend day that closes the ISO week and often precedes planning for Monday.', |
| 64 | }; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return bool |
| 69 | */ |
| 70 | public function isWeekend(): bool |
| 71 | { |
| 72 | return $this->in([self::Saturday, self::Sunday]); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return bool |
| 77 | */ |
| 78 | public function isWeekday(): bool |
| 79 | { |
| 80 | return ! $this->isWeekend(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return list<self> |
| 85 | */ |
| 86 | public static function ordered(): array |
| 87 | { |
| 88 | return [ |
| 89 | self::Monday, |
| 90 | self::Tuesday, |
| 91 | self::Wednesday, |
| 92 | self::Thursday, |
| 93 | self::Friday, |
| 94 | self::Saturday, |
| 95 | self::Sunday, |
| 96 | ]; |
| 97 | } |
| 98 | } |