Completed
Pull Request — master (#62)
by
unknown
18:09
created

Job::setEventDispatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dtc\QueueBundle\Model;
4
5
use Dtc\QueueBundle\Manager\JobManagerInterface;
6
use Dtc\QueueBundle\EventDispatcher\Event;
7
use Dtc\QueueBundle\EventDispatcher\EventDispatcher;
8
9
class Job extends BaseJob
10
{
11
    const STATUS_EXPIRED = 'expired';
12
13
    protected $id;
14
    protected $message;
15
    protected $crcHash;
16
    protected $expiresAt;
17
    protected $delay;
18
    protected $startedAt;
19
    protected $maxDuration;
20 100
    protected $runId;
21
    protected $finishedAt;
22 100
    protected $elapsed;
23 100
24
    /** @var  EventDispatcher $eventDispatcher */
25
    protected $eventDispatcher;
26 100
27 1
    public function __call($method, $args)
28
    {
29
        $this->method = $method;
30 100
        $this->setArgs($args);
31
32 100
        // Make sure the method exists - job should not be created
33
        if (!method_exists($this->worker, $method)) {
34
            throw new \BadMethodCallException("{$this->className}->{$method}() does not exist");
35
        }
36
37
        $job = $this->jobManager->save($this);
38 41
        $event = new Event($job);
39
        $this->eventDispatcher->dispatch(Event::CREATE_JOB, $event);
40 41
        return $job;
41
    }
42
43
    public function setEventDispatcher(EventDispatcher $eventDispatcher)
44
    {
45
        $this->eventDispatcher = $eventDispatcher;
46 33
    }
47
48 33
    /**
49
     * @return string|null
50 33
     */
51
    public function getMessage()
52
    {
53
        return $this->message;
54
    }
55
56 79
    /**
57
     * @param string $message
58 79
     */
59
    public function setMessage($message)
60
    {
61
        $this->message = $message;
62
63
        return $this;
64 9
    }
65
66 9
    /**
67
     * @return \DateTime|null
68 9
     */
69
    public function getExpiresAt()
70
    {
71
        return $this->expiresAt;
72
    }
73
74 108
    /**
75
     * @param \DateTime $expiresAt
76 108
     */
77
    public function setExpiresAt(\DateTime $expiresAt)
78
    {
79
        $this->expiresAt = $expiresAt;
80
81
        return $this;
82 94
    }
83
84 94
    /**
85
     * @return int
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90 98
    }
91
92 98
    /**
93
     * @return string
94 98
     */
95
    public function getCrcHash()
96
    {
97
        return $this->crcHash;
98
    }
99
100 33
    /**
101
     * @param mixed $id
102 33
     */
103
    public function setId($id)
104
    {
105
        $this->id = $id;
106
107
        return $this;
108 32
    }
109
110 32
    /**
111
     * @return \DateTime|null
112 32
     */
113
    public function getStartedAt()
114
    {
115
        return $this->startedAt;
116
    }
117
118 40
    /**
119
     * @param \DateTime|null $startedAt
120 40
     */
121
    public function setStartedAt(\DateTime $startedAt = null)
122
    {
123
        $this->startedAt = $startedAt;
124
125
        return $this;
126 7
    }
127
128 7
    /**
129
     * @return int|null
130 7
     */
131
    public function getMaxDuration()
132
    {
133
        return $this->maxDuration;
134
    }
135
136 94
    /**
137
     * @param int|null $maxDuration
138 94
     */
139
    public function setMaxDuration($maxDuration)
140 94
    {
141
        $this->maxDuration = $maxDuration;
142
143
        return $this;
144
    }
145
146 47
    /**
147
     * @param string $crcHash
148 47
     */
149
    public function setCrcHash($crcHash)
150
    {
151
        $this->crcHash = $crcHash;
152
153
        return $this;
154 29
    }
155
156 29
    /**
157
     * @return int
158 29
     */
159
    public function getDelay()
160
    {
161
        return $this->delay;
162
    }
163
164 22
    /**
165
     * @param int $delay Delay in seconds
166 22
     */
167
    public function setDelay($delay)
168
    {
169
        $this->delay = $delay;
170
171
        return $this;
172 21
    }
173
174 21
    /**
175
     * @return mixed
176 21
     */
177
    public function getRunId()
178
    {
179
        return $this->runId;
180
    }
181
182 40
    /**
183
     * @param mixed $runId
184 40
     */
185
    public function setRunId($runId)
186
    {
187
        $this->runId = $runId;
188
189
        return $this;
190 23
    }
191
192 23
    /**
193
     * @return \DateTime|null
194 23
     */
195
    public function getFinishedAt()
196
    {
197
        return $this->finishedAt;
198
    }
199
200 41
    /**
201
     * @param \DateTime|null $finishedAt
202 41
     */
203
    public function setFinishedAt($finishedAt)
204
    {
205
        $this->finishedAt = $finishedAt;
206
207
        return $this;
208 23
    }
209
210 23
    /**
211
     * @return int
212 23
     */
213
    public function getElapsed()
214
    {
215
        return $this->elapsed;
216
    }
217
218
    /**
219
     * @param int $elapsed
220
     */
221
    public function setElapsed($elapsed)
222
    {
223
        $this->elapsed = $elapsed;
224
225
        return $this;
226
    }
227
}
228