| Conditions | 4 |
| Paths | 8 |
| Total Lines | 25 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | public function provide(Recurrence $recurrence): array |
||
| 13 | { |
||
| 14 | 1 | $interval = $recurrence->getFrequency()->convertToDateIntervalFormat(); |
|
| 15 | |||
| 16 | 1 | $periodEndAt = ($recurrence->hasPeriodEndAt()) ? $recurrence->getPeriodEndAt() : $this->estimatePeriodEndAt($recurrence); |
|
| 17 | |||
| 18 | // Transform interval in Datetime interval expression |
||
| 19 | 1 | if ($recurrence->getInterval() !== 1) { |
|
| 20 | 1 | $interval = str_replace('1', $recurrence->getInterval(), $interval); |
|
| 21 | } |
||
| 22 | |||
| 23 | 1 | $dateInterval = new \DateInterval($interval); |
|
| 24 | |||
| 25 | 1 | $recurrences = iterator_to_array(new \DatePeriod( |
|
| 26 | 1 | $recurrence->getPeriodStartAt(), |
|
| 27 | $dateInterval, |
||
| 28 | $periodEndAt |
||
|
1 ignored issue
–
show
|
|||
| 29 | )); |
||
| 30 | |||
| 31 | // When having count option, return only amount of recurrences requested |
||
| 32 | 1 | if ($recurrence->hasCount()) { |
|
| 33 | 1 | return array_slice($recurrences, 0, $recurrence->getCount()); |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | return $recurrences; |
|
| 37 | } |
||
| 39 |