Schedule::dueEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace yii2mod\scheduling;
4
5
use yii\base\Application;
6
use yii\base\Component;
7
8
/**
9
 * Class Schedule
10
 */
11
class Schedule extends Component
12
{
13
    /**
14
     * All of the events on the schedule.
15
     *
16
     * @var Event[]
17
     */
18
    protected $_events = [];
19
20
    /**
21
     * Add a new callback event to the schedule.
22
     *
23
     * @param  string $callback
24
     * @param  array $parameters
25
     *
26
     * @return Event
27
     */
28
    public function call($callback, array $parameters = [])
29
    {
30
        $this->_events[] = $event = new CallbackEvent($callback, $parameters);
31
32
        return $event;
33
    }
34
35
    /**
36
     * Add a new cli command event to the schedule.
37
     *
38
     * @param  string $command
39
     *
40
     * @return Event
41
     */
42
    public function command($command)
43
    {
44
        return $this->exec(PHP_BINARY . ' yii ' . $command);
45
    }
46
47
    /**
48
     * Add a new command event to the schedule.
49
     *
50
     * @param  string $command
51
     *
52
     * @return Event
53
     */
54
    public function exec($command)
55
    {
56
        $this->_events[] = $event = new Event($command);
57
58
        return $event;
59
    }
60
61
    /**
62
     * Get events
63
     *
64
     * @return Event[]
65
     */
66
    public function getEvents()
67
    {
68
        return $this->_events;
69
    }
70
71
    /**
72
     * Get all of the events on the schedule that are due.
73
     *
74
     * @param \yii\base\Application $app
75
     *
76
     * @return Event[]
77
     */
78
    public function dueEvents(Application $app)
79
    {
80
        return array_filter($this->_events, function (Event $event) use ($app) {
81
            return $event->isDue($app);
82
        });
83
    }
84
}
85