Completed
Pull Request — master (#37)
by Peter
23:57
created

ImportPart   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 308
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 41.28%

Importance

Changes 0
Metric Value
wmc 25
lcom 2
cbo 0
dl 0
loc 308
ccs 45
cts 109
cp 0.4128
rs 10
c 0
b 0
f 0

23 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getId() 0 4 1
A setPosition() 0 6 1
A getPosition() 0 4 1
A setTransportConfig() 0 6 1
A getTransportConfig() 0 4 1
A setProcess() 0 6 1
A getProcess() 0 4 1
A setError() 0 6 1
A getError() 0 4 1
A setRetries() 0 6 1
A getRetries() 0 4 1
A setDatetimeScheduled() 0 6 1
A getDatetimeScheduled() 0 4 1
A setDatetimeStarted() 0 6 1
A getDatetimeStarted() 0 4 1
A setDatetimeEnded() 0 6 1
A getDatetimeEnded() 0 4 1
A setImport() 0 6 1
A getImport() 0 4 1
A isStarted() 0 4 1
A isFinished() 0 4 1
A isRunning() 0 16 3
1
<?php
2
3
namespace TreeHouse\IoBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * @ORM\Table
9
 * @ORM\Entity(repositoryClass="ImportPartRepository")
10
 */
11
class ImportPart
12
{
13
    /**
14
     * @var int
15
     *
16
     * @ORM\Id
17
     * @ORM\Column(type="integer")
18
     * @ORM\GeneratedValue(strategy="AUTO")
19
     */
20
    protected $id;
21
22
    /**
23
     * @var int
24
     *
25
     * @ORM\Column(type="integer")
26
     */
27
    protected $position;
28
29
    /**
30
     * @var array
31
     *
32
     * @ORM\Column(type="json_array")
33
     */
34
    protected $transportConfig;
35
36
    /**
37
     * @var int
38
     *
39
     * @ORM\Column(type="integer", nullable=true)
40
     */
41
    protected $process;
42
43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(type="string", nullable=true)
47
     */
48
    protected $error;
49
50
    /**
51
     * @var int
52
     *
53
     * @ORM\Column(type="integer")
54
     */
55
    protected $retries;
56
57
    /**
58
     * @var \DateTime
59
     *
60
     * @ORM\Column(type="datetime", nullable=true)
61
     */
62
    protected $datetimeScheduled;
63
64
    /**
65
     * @var \DateTime
66
     *
67
     * @ORM\Column(type="datetime", nullable=true)
68
     */
69
    protected $datetimeStarted;
70
71
    /**
72
     * @var \DateTime
73
     *
74
     * @ORM\Column(type="datetime", nullable=true)
75
     */
76
    protected $datetimeEnded;
77
78
    /**
79
     * @var Import
80
     *
81
     * @ORM\ManyToOne(targetEntity="Import", inversedBy="parts")
82
     */
83
    protected $import;
84
85
    /**
86
     * Constructor.
87
     */
88 2
    public function __construct()
89
    {
90 2
        $this->retries = 1;
91 2
    }
92
93
    /**
94
     * @return int
95
     */
96 2
    public function getId()
97
    {
98 2
        return $this->id;
99
    }
100
101
    /**
102
     * @param int $position
103
     *
104
     * @return $this
105
     */
106 2
    public function setPosition($position)
107
    {
108 2
        $this->position = $position;
109
110 2
        return $this;
111
    }
112
113
    /**
114
     * @return int
115
     */
116 2
    public function getPosition()
117
    {
118 2
        return $this->position;
119
    }
120
121
    /**
122
     * @param array $transportConfig
123
     *
124
     * @return $this
125
     */
126 2
    public function setTransportConfig($transportConfig)
127
    {
128 2
        $this->transportConfig = $transportConfig;
129
130 2
        return $this;
131
    }
132
133
    /**
134
     * @return array
135
     */
136 2
    public function getTransportConfig()
137
    {
138 2
        return $this->transportConfig;
139
    }
140
141
    /**
142
     * @param mixed $process
143
     *
144
     * @return $this
145
     */
146 2
    public function setProcess($process)
147
    {
148 2
        $this->process = $process;
149
150 2
        return $this;
151
    }
152
153
    /**
154
     * @return mixed
155
     */
156 2
    public function getProcess()
157
    {
158 2
        return $this->process;
159
    }
160
161
    /**
162
     * @param string $error
163
     *
164
     * @return $this
165
     */
166 2
    public function setError($error)
167
    {
168 2
        $this->error = $error;
169
170 2
        return $this;
171
    }
172
173
    /**
174
     * @return string
175
     */
176 2
    public function getError()
177
    {
178 2
        return $this->error;
179
    }
180
181
    /**
182
     * @param int $retries
183
     *
184
     * @return $this
185
     */
186
    public function setRetries($retries)
187
    {
188
        $this->retries = $retries;
189
190
        return $this;
191
    }
192
193
    /**
194
     * @return int
195
     */
196
    public function getRetries()
197
    {
198
        return $this->retries;
199
    }
200
201
    /**
202
     * @param \DateTime $datetimeScheduled
203
     *
204
     * @return $this
205
     */
206 2
    public function setDatetimeScheduled(\DateTime $datetimeScheduled = null)
207
    {
208 2
        $this->datetimeScheduled = $datetimeScheduled;
209
210 2
        return $this;
211
    }
212
213
    /**
214
     * @return \DateTime
215
     */
216
    public function getDatetimeScheduled()
217
    {
218
        return $this->datetimeScheduled;
219
    }
220
221
    /**
222
     * @param \DateTime $datetimeStarted
223
     *
224
     * @return $this
225
     */
226 2
    public function setDatetimeStarted(\DateTime $datetimeStarted = null)
227
    {
228 2
        $this->datetimeStarted = $datetimeStarted;
229
230 2
        return $this;
231
    }
232
233
    /**
234
     * @return \DateTime
235
     */
236
    public function getDatetimeStarted()
237
    {
238
        return $this->datetimeStarted;
239
    }
240
241
    /**
242
     * @param \DateTime $datetimeEnded
243
     *
244
     * @return $this
245
     */
246 2
    public function setDatetimeEnded(\DateTime $datetimeEnded = null)
247
    {
248 2
        $this->datetimeEnded = $datetimeEnded;
249
250 2
        return $this;
251
    }
252
253
    /**
254
     * @return \DateTime
255
     */
256 2
    public function getDatetimeEnded()
257
    {
258 2
        return $this->datetimeEnded;
259
    }
260
261
    /**
262
     * @param Import $import
263
     *
264
     * @return $this
265
     */
266 2
    public function setImport(Import $import = null)
267
    {
268 2
        $this->import = $import;
269
270 2
        return $this;
271
    }
272
273
    /**
274
     * @return Import
275
     */
276 2
    public function getImport()
277
    {
278 2
        return $this->import;
279
    }
280
281
    /**
282
     * @return bool
283
     */
284 2
    public function isStarted()
285
    {
286 2
        return !is_null($this->getProcess());
287
    }
288
289
    /**
290
     * @return bool
291
     */
292 2
    public function isFinished()
293
    {
294 2
        return !is_null($this->getDatetimeEnded());
295
    }
296
297
    /**
298
     * @throws \InvalidArgumentException When the part does not have a valid pid
299
     *
300
     * @return bool
301
     */
302
    public function isRunning()
303
    {
304
        if (null === $pid = $this->getProcess()) {
305
            return false;
306
        }
307
308
        if (!$pid) {
309
            throw new \InvalidArgumentException(
310
                sprintf('Import part does not have a valid pid: %s', json_encode($pid))
311
            );
312
        }
313
314
        // kill signal 0: check whether a process is running.
315
        // see http://www.php.net/manual/en/function.posix-kill.php#82560
316
        return posix_kill($pid, 0);
317
    }
318
}
319