| Total Complexity | 6 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | final class DateRange |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var DateTimeImmutable |
||
| 18 | */ |
||
| 19 | protected $startDate; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var DateTimeImmutable |
||
| 23 | */ |
||
| 24 | protected $endDate; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param DateTimeInterface $startDate |
||
| 28 | * @param DateTimeInterface $endDate |
||
| 29 | */ |
||
| 30 | 9 | public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate) |
|
| 31 | { |
||
| 32 | 9 | if ($startDate > $endDate) { |
|
| 33 | 1 | throw new InvalidArgumentException('The start date must be more recent that end date'); |
|
| 34 | } |
||
| 35 | |||
| 36 | 8 | $this->startDate = $this->makeImmutable($startDate); |
|
| 37 | 8 | $this->endDate = $this->makeImmutable($endDate); |
|
| 38 | 8 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @param DateTimeInterface $date |
||
| 42 | * @return DateTimeImmutable |
||
| 43 | */ |
||
| 44 | 8 | private function makeImmutable(DateTimeInterface $date): DateTimeImmutable |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return DateTimeImmutable |
||
| 53 | */ |
||
| 54 | 8 | public function startDate(): DateTimeImmutable |
|
| 55 | { |
||
| 56 | 8 | return $this->startDate; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return DateTimeImmutable |
||
| 61 | */ |
||
| 62 | 8 | public function endDate(): DateTimeImmutable |
|
| 65 | } |
||
| 66 | } |
||
| 67 |