EndOfMonthProvider::provide()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 9.9666
cc 4
nc 8
nop 1
crap 4
1
<?php
2
3
namespace Recurrence\Provider;
4
5
use Recurrence\Model\Recurrence;
6
7
class EndOfMonthProvider extends AbstractDatetimeProvider
8
{
9
    /**
10
     * @return array<\DateTime>
11
     */
12
    public function provide(Recurrence $recurrence): array
13
    {
14 1
        $periodEndAt = ($recurrence->hasPeriodEndAt()) ? $recurrence->getPeriodEndAt() : $this->estimatePeriodEndAt($recurrence);
15
16 1
        $recurrences = [];
17
18 1
        $date = clone $recurrence->getPeriodStartAt();
19
20 1
        while ($date < $periodEndAt) {
21 1
            $recurrences[] = clone $date;
22 1
            $date->modify('last day of next month');
23
        }
24
25
        // When having count option, return only amount of recurrences requested
26 1
        if ($recurrence->hasCount()) {
27 1
            return array_slice($recurrences, 0, $recurrence->getCount());
28
        }
29
30 1
        return $recurrences;
31
    }
32
}
33