| Total Complexity | 8 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | final class FiniteState extends RangeState |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var DateTimeInterface |
||
| 15 | */ |
||
| 16 | private $startDate; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var DateTimeInterface |
||
| 20 | */ |
||
| 21 | private $endDate; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param DateTimeInterface $startDate |
||
| 25 | * @param DateTimeInterface $endDate |
||
| 26 | */ |
||
| 27 | 13 | public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate) |
|
| 28 | { |
||
| 29 | 13 | if ($endDate <= $startDate) { |
|
| 30 | 2 | throw new DateRangeException('Invalid end date, must be after start'); |
|
| 31 | } |
||
| 32 | |||
| 33 | 13 | $this->startDate = $startDate; |
|
| 34 | 13 | $this->endDate = $endDate; |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | 3 | public function hasStartDate(): bool |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | 3 | public function hasEndDate(): bool |
|
| 49 | { |
||
| 50 | 3 | return true; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | 9 | public function getStartDate(): DateTimeInterface |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * {@inheritdoc} |
||
| 63 | */ |
||
| 64 | 9 | public function getEndDate(): DateTimeInterface |
|
| 65 | { |
||
| 66 | 9 | return $this->endDate; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | 2 | public function setStartDate(DateTimeInterface $start): RangeState |
|
| 73 | { |
||
| 74 | 2 | return new FiniteState($start, $this->endDate); |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | 2 | public function setEndDate(DateTimeInterface $end): RangeState |
|
| 83 | } |
||
| 84 | } |
||
| 85 |