EndOfMonthProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A provide() 0 19 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