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