GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — feature/cron_notation_support ( ddb1da...9d1836 )
by Aleh
01:59
created

CronRule::getRecurrences()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
eloc 8
nc 4
nop 3
crap 3
1
<?php
2
3
namespace Scheduler\Job;
4
5
use DateTimeInterface;
6
use Cron\CronExpression;
7
8
/**
9
 * Class CronRule
10
 * @package Scheduler\Job
11
 * @author Aleh Hutnikau, <[email protected]>
12
 */
13
class CronRule extends AbstractRule
14
{
15
16
    /**
17
     * @param DateTimeInterface $from
18
     * @param DateTimeInterface $to
19
     * @param boolean $inc
20
     * @throws
21
     * @return DateTimeInterface[]
22
     */
23 1
    public function getRecurrences(DateTimeInterface $from, DateTimeInterface $to, $inc = true)
24
    {
25 1
        $rRule = CronExpression::factory($this->getRrule());
26 1
        $result = [];
27
28 1
        if ($from->getTimestamp() < $this->getStartDate()->getTimestamp()) {
29 1
            $from = clone $this->getStartDate();
30 1
        }
31
32 1
        if (($to->getTimestamp() + (int) $inc) > $this->getStartDate()->getTimestamp()) {
33 1
            $result = $this->getDates($rRule, $from, $to, $inc);
34 1
        }
35
36 1
        return $result;
37
    }
38
39
    /**
40
     * @param CronExpression $rRule
41
     * @param DateTimeInterface $from
42
     * @param DateTimeInterface $to
43
     * @param $inc
44
     * @return DateTimeInterface[]
45
     */
46 1
    private function getDates(CronExpression $rRule, DateTimeInterface $from, DateTimeInterface $to, $inc)
47
    {
48 1
        $firstIteration = true;
49 1
        $result = [];
50
        do {
51 1
            $nextRunDate = $rRule->getNextRunDate($from, 0, $firstIteration && $inc);
0 ignored issues
show
Bug introduced by
It seems like $from defined by parameter $from on line 46 can also be of type object<DateTimeInterface>; however, Cron\CronExpression::getNextRunDate() does only seem to accept string|object<DateTime>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
52 1
            if ($nextRunDate->getTimestamp() < ($to->getTimestamp() + (int) $inc) && $from->getTimestamp() <= $nextRunDate->getTimestamp()) {
53 1
                $result[] = $nextRunDate;
54 1
            }
55 1
            $firstIteration = false;
56 1
            $from = $nextRunDate;
57 1
        } while ($nextRunDate->getTimestamp() < ($to->getTimestamp() + (int) $inc));
58 1
        return $result;
59
    }
60
}