PromoRepository.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Promo; |
| 6 | |
| 7 | use AC\Type\DateRange; |
| 8 | use AC\Type\Promo; |
| 9 | use AC\Type\PromoCollection; |
| 10 | use DateTime; |
| 11 | |
| 12 | class PromoRepository |
| 13 | { |
| 14 | |
| 15 | public function find_all(): PromoCollection |
| 16 | { |
| 17 | return new PromoCollection([ |
| 18 | new BlackFriday( |
| 19 | new DateRange( |
| 20 | new DateTime('2026-11-26'), |
| 21 | new DateTime('2026-12-03') |
| 22 | ), |
| 23 | 'BlackFriday26' |
| 24 | ), |
| 25 | ]); |
| 26 | } |
| 27 | |
| 28 | public function find_active(): ?Promo |
| 29 | { |
| 30 | foreach ($this->find_all() as $promo) { |
| 31 | if ($promo->is_active()) { |
| 32 | return $promo; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return null; |
| 37 | } |
| 38 | |
| 39 | } |