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 — master ( 5ad53e...930849 )
by Aleh
29:28 queued 27:44
created

CronRule::getRecurrences()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 17
rs 9.4285
cc 3
eloc 9
nc 4
nop 3
1
<?php
2
3
namespace Scheduler\Job;
4
5
use DateTimeInterface;
6
use DateTime;
7
use Cron\CronExpression;
8
9
/**
10
 * Class CronRule
11
 * @package Scheduler\Job
12
 * @author Aleh Hutnikau, <[email protected]>
13
 */
14
class CronRule extends AbstractRule
15
{
16
17
    /**
18
     * @param DateTimeInterface $from
19
     * @param DateTimeInterface $to
20
     * @param boolean $inc
21
     * @throws
22
     * @return DateTimeInterface[]
23
     */
24
    public function getRecurrences(DateTimeInterface $from, DateTimeInterface $to, $inc = true)
25
    {
26
        $rRule = CronExpression::factory($this->getRrule());
27
        $result = [];
28
29
        if ($from->getTimestamp() < $this->getStartDate()->getTimestamp()) {
30
            $from = clone $this->getStartDate();
31
        }
32
33
        if (($to->getTimestamp() + (int) $inc) > $this->getStartDate()->getTimestamp()) {
34
            //make sure that $from is DateTime instance
35
            $from = new DateTime('@'.$from->getTimestamp());
36
            $result = $this->getDates($rRule, $from, $to, $inc);
37
        }
38
39
        return $result;
40
    }
41
42
    /**
43
     * @param CronExpression $rRule
44
     * @param DateTime $from
45
     * @param DateTimeInterface $to
46
     * @param $inc
47
     * @return DateTimeInterface[]
48
     */
49
    private function getDates(CronExpression $rRule, DateTime $from, DateTimeInterface $to, $inc)
50
    {
51
        $result = [];
52
        $toTimestamp = $to->getTimestamp() + (int) $inc;
53
        do {
54
            $nextRunDate = $rRule->getNextRunDate($from, 0, $inc);
55
            $nextRunTimestamp = $nextRunDate->getTimestamp();
56
            if ($nextRunTimestamp < $toTimestamp && $from->getTimestamp() <= $nextRunTimestamp) {
57
                $result[] = $nextRunDate;
58
            }
59
            $inc = false;
60
            $from = $nextRunDate;
61
        } while ($nextRunTimestamp < $toTimestamp);
62
        return $result;
63
    }
64
}