Completed
Push — master ( 40b87c...f82b1c )
by Matthew
04:37
created

BaseJob::setBatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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