Schedule::getEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the mytheam/yii2-schedule.
5
 *
6
 * (c) mytheam <[email protected]>
7
 *
8
 * This source file is subject to the BSD license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace mythteam\schedule;
13
14
use yii\base\Component;
15
use yii\base\Application;
16
17
class Schedule extends Component
18
{
19
    /**
20
     * @var array All the events to scheduled
21
     */
22
    protected $_events = [];
23
24
    /**
25
     * Register a callback style schedule event.
26
     *
27
     * @param \Closure $callback
28
     * @param array  $parameters
29
     *
30
     * @return Event
31
     */
32 1
    public function call($callback, array $parameters = [])
33
    {
34 1
        $this->_events[] = $event = new CallbackEvent($callback, $parameters);
0 ignored issues
show
Documentation introduced by
$callback is of type object<Closure>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
36 1
        return $event;
37
    }
38
39
    /**
40
     * Register a yii console command.
41
     *
42
     * @param string $command
43
     *
44
     * @return Event
45
     */
46 2
    public function command($command)
47
    {
48 2
        return $this->exec(PHP_BINARY . ' yii ' . $command);
49
    }
50
51
    /**
52
     * Register a new command event to schedule.
53
     *
54
     * @param string $command
55
     *
56
     * @return Event
57
     */
58 3
    public function exec($command)
59
    {
60 3
        $this->_events[] = $event = new Event($command);
61
62 3
        return $event;
63
    }
64
65
    /**
66
     * Get all scheduled events.
67
     *
68
     * @return array
69
     */
70 3
    public function getEvents()
71
    {
72 3
        return $this->_events;
73
    }
74
75
    /**
76
     * Get all of the events on the schedule that are due.
77
     *
78
     * @param Application $app
79
     *
80
     * @return array
81
     */
82
    public function dueEvents(Application $app)
83
    {
84 1
        return array_filter($this->_events, function (Event $event) use ($app) {
85 1
            return $event->isDue($app);
86 1
        });
87
    }
88
}
89