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
Branch master (c91cad)
by Aleh
02:07
created

Scheduler   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 72
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getIterator() 0 12 3
A addJob() 0 4 1
A appendActions() 0 7 2
A sortActions() 0 9 3
1
<?php
2
3
namespace Scheduler;
4
5
use Scheduler\Action\ActionIterator;
6
use Scheduler\Job\JobInterface;
7
use Scheduler\Job\JobIterator;
8
use DateTimeInterface;
9
10
/**
11
 * Class Scheduler
12
 * @package Scheduler
13
 * @author Aleh Hutnikau, <[email protected]>
14
 */
15
class Scheduler implements SchedulerInterface
16
{
17
    /**
18
     * @var JobInterface[]
19
     */
20
    protected $jobs = [];
21
22
    /**
23
     * Scheduler constructor.
24
     * @param JobInterface[] $jobs
25
     */
26 12
    public function __construct(array $jobs = [])
27
    {
28 12
        foreach ($jobs as $job) {
29 11
            $this->addJob($job);
30
        }
31 12
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36 12
    public function getIterator(DateTimeInterface $from, DateTimeInterface $to = null, $inc = true)
37
    {
38 12
        $iterator = new \ArrayIterator();
39 12
        if ($to === null) {
40 2
            $to = new \DateTime('now', $from->getTimezone());
41
        }
42 12
        foreach ($this->jobs as $job) {
43 12
            $this->appendActions($iterator, $job, $from, $to, $inc);
44
        }
45 12
        $this->sortActions($iterator);
46 12
        return $iterator;
47
    }
48
49
    /**
50
     * @param JobInterface $job
51
     * @return mixed|void
52
     */
53 12
    public function addJob(JobInterface $job)
54
    {
55 12
        $this->jobs[] = $job;
56 12
    }
57
58
    /**
59
     * @param \ArrayIterator $iterator - iterator to append actions
60
     * @param JobInterface $job
61
     * @param DateTimeInterface $from
62
     * @param DateTimeInterface $to
63
     * @param $inc
64
     */
65 12
    protected function appendActions(\ArrayIterator $iterator, JobInterface $job, DateTimeInterface $from, DateTimeInterface $to, $inc)
66
    {
67 12
        $actionIterator = new ActionIterator($job, $from, $to, $inc);
68 12
        foreach ($actionIterator as $action) {
69 11
            $iterator->append($action);
70
        }
71 12
    }
72
73
    /**
74
     * Sort actions by execution time
75
     * @param \ArrayIterator $iterator - iterator to append actions
76
     */
77
    protected function sortActions(\ArrayIterator $iterator)
78
    {
79 12
        $iterator->uasort(function ($a, $b) {
80 6
            if ($a->getTime()->getTimestamp() == $b->getTime()->getTimestamp()) {
81 1
                return 0;
82
            }
83 6
            return ($a->getTime()->getTimestamp() < $b->getTime()->getTimestamp()) ? -1 : 1;
84 12
        });
85
    }
86
}