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