| Conditions | 4 |
| Paths | 8 |
| Total Lines | 31 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4.0378 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | public function provide(Recurrence $recurrence) |
||
| 18 | { |
||
| 19 | 1 | $interval = $recurrence->getFrequency()->convertToDateIntervalFormat(); |
|
| 20 | |||
| 21 | // Transform interval in Datetime interval expression |
||
| 22 | 1 | if ($recurrence->getInterval() !== 1) { |
|
| 23 | $interval = str_replace('1', $recurrence->getInterval(), $interval); |
||
| 24 | } |
||
| 25 | |||
| 26 | 1 | $dateInterval = new \DateInterval($interval); |
|
| 27 | |||
| 28 | // Estimate end date in case of count option |
||
| 29 | 1 | $periodEndAt = $recurrence->getPeriodEndAt(); |
|
| 30 | 1 | if ($recurrence->hasCount()) { |
|
| 31 | 1 | $periodEndAt = clone $recurrence->getPeriodStartAt(); |
|
| 32 | 1 | $periodEndAt->modify(str_replace('1', ($recurrence->getCount()*$recurrence->getInterval()), $recurrence->getFrequency()->convertToDateTimeFormat())); |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | $recurrences = iterator_to_array(new \DatePeriod( |
|
| 36 | 1 | $recurrence->getPeriodStartAt(), |
|
| 37 | 1 | $dateInterval, |
|
| 38 | 1 | $periodEndAt |
|
| 39 | )); |
||
| 40 | |||
| 41 | // When having count option, return only amount of recurrences requested |
||
| 42 | 1 | if ($recurrence->hasCount()) { |
|
| 43 | 1 | return array_slice($recurrences, 0, $recurrence->getCount()); |
|
| 44 | } |
||
| 45 | |||
| 46 | return $recurrences; |
||
| 47 | } |
||
| 48 | } |
||
| 49 |