EventCollectionTrait::ensureJobs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
crap 6
1
<?php
2
3
namespace flipbox\queue\jobs\traits;
4
5
use flipbox\queue\events\RegisterJobs;
6
use yii\base\Event;
7
8
trait EventCollectionTrait
9
{
10
    use CollectionTrait {
11
        addJob as parentAddJob;
12
        addJobs as parentAddJobs;
13
        findJob as parentFindJob;
14
        getJobs as parentGetJobs;
15
    }
16
17
    /**
18
     * @param $name
19
     * @param Event|null $event
20
     * @return mixed
21
     */
22
    public abstract function trigger($name, Event $event = null);
23
24
    /**
25
     * @inheritdoc
26
     */
27
    protected function addJobs(array $jobs = [])
28
    {
29
        $this->ensureJobs();
30
        return $this->parentAddJobs($jobs);
0 ignored issues
show
Bug introduced by
The method parentAddJobs() does not exist on flipbox\queue\jobs\traits\EventCollectionTrait. Did you maybe mean addJobs()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function addJob($key, $job)
37
    {
38
        $this->ensureJobs();
39
        return $this->parentAddJob($key, $job);
0 ignored issues
show
Bug introduced by
The method parentAddJob() does not exist on flipbox\queue\jobs\traits\EventCollectionTrait. Did you maybe mean addJob()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function getJobs()
46
    {
47
        $this->ensureJobs();
48
        return $this->parentGetJobs();
0 ignored issues
show
Bug introduced by
The method parentGetJobs() does not exist on flipbox\queue\jobs\traits\EventCollectionTrait. Did you maybe mean getJobs()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function findJob($identifier)
55
    {
56
        $this->ensureJobs();
57
        return $this->parentFindJob($identifier);
0 ignored issues
show
Bug introduced by
The method parentFindJob() does not exist on flipbox\queue\jobs\traits\EventCollectionTrait. Did you maybe mean findJob()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
58
    }
59
60
    /**
61
     * Ensure the jobs are all loaded
62
     *
63
     * @return static
64
     */
65
    protected function ensureJobs()
66
    {
67
        if (null === $this->jobs) {
68
            $this->jobs = [];
69
70
            $this->trigger(
71
                RegisterJobs::EVENT_REGISTER_JOBS,
72
                $event = new RegisterJobs()
73
            );
74
75
            $this->addJobs($event->jobs);
76
        }
77
78
        return $this;
79
    }
80
}
81