OptimizedProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A provide() 0 25 4
1
<?php
2
3
namespace Recurrence\Provider;
4
5
use Recurrence\Model\Recurrence;
6
7
class OptimizedProvider extends AbstractDatetimeProvider
8
{
9
    /**
10
     * @return array<\DateTime>
11
     */
12
    public function provide(Recurrence $recurrence): array
13
    {
14 1
        $interval = $recurrence->getFrequency()->convertToDateIntervalFormat();
15
16 1
        $periodEndAt = ($recurrence->hasPeriodEndAt()) ? $recurrence->getPeriodEndAt() : $this->estimatePeriodEndAt($recurrence);
17
18
        // Transform interval in Datetime interval expression
19 1
        if ($recurrence->getInterval() !== 1) {
20 1
            $interval = str_replace('1', $recurrence->getInterval(), $interval);
21
        }
22
23 1
        $dateInterval = new \DateInterval($interval);
24
25 1
        $recurrences = iterator_to_array(new \DatePeriod(
26 1
            $recurrence->getPeriodStartAt(),
27
            $dateInterval,
28
            $periodEndAt
1 ignored issue
show
Bug introduced by
It seems like $periodEndAt can also be of type null; however, parameter $end of DatePeriod::__construct() does only seem to accept DateTimeInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
            /** @scrutinizer ignore-type */ $periodEndAt
Loading history...
29
        ));
30
31
        // When having count option, return only amount of recurrences requested
32 1
        if ($recurrence->hasCount()) {
33 1
            return array_slice($recurrences, 0, $recurrence->getCount());
34
        }
35
36 1
        return $recurrences;
37
    }
38
}
39