Completed
Push — master ( cdd718...8a683b )
by Matthew
06:43 queued 30s
created

BaseJob::setArgs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace Dtc\QueueBundle\Model;
4
5
abstract class BaseJob
6
{
7
    const STATUS_SUCCESS = 'success';
8
    const STATUS_ERROR = 'error';
9
    const STATUS_NEW = 'new';
10
    const STATUS_RUNNING = 'running';
11
12
    /**
13
     * @var JobManagerInterface
14
     */
15
    protected $jobManager;
16
    protected $worker;
17
    protected $workerName;
18
    protected $className;
19
    protected $args;
20
    protected $batch;
21
    protected $method;
22
    protected $priority;
23
    protected $whenAt;
24
    protected $status;
25
26 8
    public function __construct(Worker $worker = null, $batch = false, $priority = 10, \DateTime $whenAt = null)
27
    {
28 8
        $this->worker = $worker;
29 8
        if ($worker) {
30 7
            $this->jobManager = $worker->getJobManager();
31 7
            $this->className = get_class($worker);
32 7
            $this->workerName = $worker->getName();
33
        }
34
35 8
        $this->whenAt = $whenAt;
36 8
        $this->batch = $batch ? true : false;
37 8
        $this->priority = $priority;
38 8
        $this->status = self::STATUS_NEW;
39 8
    }
40
41
    /**
42
     * @param string $status The status of the job
43
     */
44 2
    public function setStatus($status)
45
    {
46 2
        $this->status = $status;
47
48 2
        return $this;
49
    }
50
51
    /**
52
     * @return string The status of the job
53
     */
54 2
    public function getStatus()
55
    {
56 2
        return $this->status;
57
    }
58
59
    /**
60
     * @return \DateTime|null
61
     */
62 1
    public function getWhenAt()
63
    {
64 1
        return $this->whenAt;
65
    }
66
67
    /**
68
     * @param \DateTime $whenAt
69
     */
70 1
    public function setWhenAt(\DateTime $whenAt)
71
    {
72 1
        $this->whenAt = $whenAt;
73
74 1
        return $this;
75
    }
76
77
    /**
78
     * @return Worker
79
     */
80 2
    public function getWorker()
81
    {
82 2
        return $this->worker;
83
    }
84
85
    /**
86
     * @param Worker $worker
87
     */
88 2
    public function setWorker($worker)
89
    {
90 2
        $this->worker = $worker;
91
92 2
        return $this;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98 2
    public function getBatch()
99
    {
100 2
        return $this->batch;
101
    }
102
103
    /**
104
     * @param bool $batch
105
     */
106 2
    public function setBatch($batch)
107
    {
108 2
        $this->batch = $batch;
109
110 2
        return $this;
111
    }
112
113
    /**
114
     * @return mixed
115
     */
116 7
    public function getArgs()
117
    {
118 7
        return $this->args;
119
    }
120
121
    /**
122
     * @param $args
123
     */
124 8
    public function setArgs($args)
125
    {
126 8
        if (!$this->validateArgs($args)) {
127
            throw new \InvalidArgumentException('Args must not contain object');
128
        }
129
130 8
        $this->args = $args;
131
132 8
        return $this;
133
    }
134
135 8
    protected function validateArgs($args)
136
    {
137 8
        if (is_array($args)) {
138 7
            foreach ($args as $key => $value) {
139 7
                if (!$this->validateArgs($value)) {
140 7
                    return false;
141
                }
142
            }
143
144 7
            return true;
145
        } else {
146 8
            return !is_object($args);
147
        }
148
    }
149
150
    /**
151
     * @return string
152
     */
153 7
    public function getMethod()
154
    {
155 7
        return $this->method;
156
    }
157
158
    /**
159
     * @param string $method
160
     */
161 7
    public function setMethod($method)
162
    {
163 7
        $this->method = $method;
164
165 7
        return $this;
166
    }
167
168
    /**
169
     * @return int
170
     */
171 7
    public function getPriority()
172
    {
173 7
        return $this->priority;
174
    }
175
176
    /**
177
     * @param int $priority
178
     */
179 3
    public function setPriority($priority)
180
    {
181 3
        $this->priority = $priority;
182
183 3
        return $this;
184
    }
185
186
    /**
187
     * @param string $workerName
188
     */
189 6
    public function setWorkerName($workerName)
190
    {
191 6
        $this->workerName = $workerName;
192
193 6
        return $this;
194
    }
195
196
    /**
197
     * @param string $className
198
     */
199 2
    public function setClassName($className)
200
    {
201 2
        $this->className = $className;
202
203 2
        return $this;
204
    }
205
206
    /**
207
     * @return string
208
     */
209 7
    public function getWorkerName()
210
    {
211 7
        return $this->workerName;
212
    }
213
214
    /**
215
     * @return string
216
     */
217 2
    public function getClassName()
218
    {
219 2
        return $this->className;
220
    }
221
222
    /**
223
     * @return JobManagerInterface
224
     */
225 1
    public function getJobManager()
226
    {
227 1
        return $this->jobManager;
228
    }
229
}
230