Import   A
last analyzed

Complexity

Total Complexity 31

Size/Duplication

Total Lines 379
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 31
lcom 4
cbo 1
dl 0
loc 379
ccs 55
cts 77
cp 0.7143
rs 9.92
c 0
b 0
f 0

30 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getId() 0 4 1
A setForced() 0 6 1
A isForced() 0 4 1
A setPartial() 0 6 1
A isPartial() 0 4 1
A getTotalNumberOfItems() 0 4 1
A getNumberOfProcessedItems() 0 4 1
A setSkipped() 0 6 1
A getSkipped() 0 4 1
A setSuccess() 0 6 1
A getSuccess() 0 4 1
A setFailed() 0 6 1
A getFailed() 0 4 1
A setErroredParts() 0 6 1
A getErroredParts() 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 setFeed() 0 6 1
A getFeed() 0 4 1
A addPart() 0 6 1
A removePart() 0 4 1
A getParts() 0 4 1
A isStarted() 0 4 1
A isFinished() 0 4 1
A hasErrors() 0 4 2
1
<?php
2
3
namespace TreeHouse\IoBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * @ORM\Entity(repositoryClass="ImportRepository")
10
 * @ORM\Table
11
 */
12
class Import
13
{
14
    /**
15
     * @var int
16
     *
17
     * @ORM\Id
18
     * @ORM\Column(type="integer")
19
     * @ORM\GeneratedValue(strategy="AUTO")
20
     */
21
    protected $id;
22
23
    /**
24
     * @var bool
25
     *
26
     * @ORM\Column(name="forced", type="boolean")
27
     */
28
    protected $forced;
29
30
    /**
31
     * @var bool
32
     *
33
     * @ORM\Column(type="boolean")
34
     */
35
    protected $partial;
36
37
    /**
38
     * @var int
39
     *
40
     * @ORM\Column(type="integer", nullable=true)
41
     */
42
    protected $skipped;
43
44
    /**
45
     * @var int
46
     *
47
     * @ORM\Column(type="integer", nullable=true)
48
     */
49
    protected $success;
50
51
    /**
52
     * @var int
53
     *
54
     * @ORM\Column(type="integer", nullable=true)
55
     */
56
    protected $failed;
57
58
    /**
59
     * @var int
60
     *
61
     * @ORM\Column(type="integer", nullable=true)
62
     */
63
    protected $erroredParts;
64
65
    /**
66
     * @var \DateTime
67
     *
68
     * @ORM\Column(type="datetime", nullable=true)
69
     */
70
    protected $datetimeScheduled;
71
72
    /**
73
     * @var \DateTime
74
     *
75
     * @ORM\Column(type="datetime", nullable=true)
76
     */
77
    protected $datetimeStarted;
78
79
    /**
80
     * @var \DateTime
81
     *
82
     * @ORM\Column(type="datetime", nullable=true)
83
     */
84
    protected $datetimeEnded;
85
86
    /**
87
     * @var ArrayCollection|ImportPart[]
88
     *
89
     * @ORM\OneToMany(targetEntity="ImportPart", mappedBy="import", cascade={"persist", "remove"})
90
     */
91
    protected $parts;
92
93
    /**
94
     * @var Feed
95
     *
96
     * @ORM\ManyToOne(targetEntity="Feed", inversedBy="imports")
97
     */
98
    protected $feed;
99
100
    /**
101
     * Constructor.
102
     */
103 8
    public function __construct()
104
    {
105 8
        $this->parts = new ArrayCollection();
106
107 8
        $this->skipped = 0;
108 8
        $this->success = 0;
109 8
        $this->failed = 0;
110 8
        $this->erroredParts = 0;
111 8
    }
112
113
    /**
114
     * @return int
115
     */
116 4
    public function getId()
117
    {
118 4
        return $this->id;
119
    }
120
121
    /**
122
     * @param bool $forced
123
     *
124
     * @return $this
125
     */
126 4
    public function setForced($forced)
127
    {
128 4
        $this->forced = $forced;
129
130 4
        return $this;
131
    }
132
133
    /**
134
     * @return bool
135
     */
136 4
    public function isForced()
137
    {
138 4
        return $this->forced;
139
    }
140
141
    /**
142
     * @param bool $partial
143
     *
144
     * @return $this
145
     */
146 4
    public function setPartial($partial)
147
    {
148 4
        $this->partial = $partial;
149
150 4
        return $this;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156 4
    public function isPartial()
157
    {
158 4
        return $this->partial;
159
    }
160
161
    /**
162
     * @return int
163
     */
164
    public function getTotalNumberOfItems()
165
    {
166
        return $this->getNumberOfProcessedItems() + $this->getSkipped();
167
    }
168
169
    /**
170
     * @return int
171
     */
172
    public function getNumberOfProcessedItems()
173
    {
174
        return $this->getSuccess() + $this->getFailed();
175
    }
176
177
    /**
178
     * @param int $skipped
179
     *
180
     * @return $this
181
     */
182
    public function setSkipped($skipped)
183
    {
184
        $this->skipped = $skipped;
185
186
        return $this;
187
    }
188
189
    /**
190
     * @return int
191
     */
192 4
    public function getSkipped()
193
    {
194 4
        return $this->skipped;
195
    }
196
197
    /**
198
     * @param int $success
199
     *
200
     * @return $this
201
     */
202
    public function setSuccess($success)
203
    {
204
        $this->success = $success;
205
206
        return $this;
207
    }
208
209
    /**
210
     * @return int
211
     */
212 4
    public function getSuccess()
213
    {
214 4
        return $this->success;
215
    }
216
217
    /**
218
     * @param int $failed
219
     *
220
     * @return $this
221
     */
222
    public function setFailed($failed)
223
    {
224
        $this->failed = $failed;
225
226
        return $this;
227
    }
228
229
    /**
230
     * @return int
231
     */
232 4
    public function getFailed()
233
    {
234 4
        return $this->failed;
235
    }
236
237
    /**
238
     * @param int $erroredParts
239
     *
240
     * @return $this
241
     */
242 4
    public function setErroredParts($erroredParts)
243
    {
244 4
        $this->erroredParts = $erroredParts;
245
246 4
        return $this;
247
    }
248
249
    /**
250
     * @return int
251
     */
252
    public function getErroredParts()
253
    {
254
        return $this->erroredParts;
255
    }
256
257
    /**
258
     * @param \DateTime $datetimeScheduled
259
     *
260
     * @return $this
261
     */
262 4
    public function setDatetimeScheduled(\DateTime $datetimeScheduled)
263
    {
264 4
        $this->datetimeScheduled = $datetimeScheduled;
265
266 4
        return $this;
267
    }
268
269
    /**
270
     * @return \DateTime
271
     */
272
    public function getDatetimeScheduled()
273
    {
274
        return $this->datetimeScheduled;
275
    }
276
277
    /**
278
     * @param \DateTime $datetimeStarted
279
     *
280
     * @return $this
281
     */
282 4
    public function setDatetimeStarted(\DateTime $datetimeStarted)
283
    {
284 4
        $this->datetimeStarted = $datetimeStarted;
285
286 4
        return $this;
287
    }
288
289
    /**
290
     * @return \DateTime
291
     */
292 4
    public function getDatetimeStarted()
293
    {
294 4
        return $this->datetimeStarted;
295
    }
296
297
    /**
298
     * @param \DateTime $datetimeEnded
299
     *
300
     * @return $this
301
     */
302 4
    public function setDatetimeEnded(\DateTime $datetimeEnded)
303
    {
304 4
        $this->datetimeEnded = $datetimeEnded;
305
306 4
        return $this;
307
    }
308
309
    /**
310
     * @return \DateTime
311
     */
312 4
    public function getDatetimeEnded()
313
    {
314 4
        return $this->datetimeEnded;
315
    }
316
317
    /**
318
     * @param Feed $feed
319
     *
320
     * @return $this
321
     */
322 4
    public function setFeed(Feed $feed = null)
323
    {
324 4
        $this->feed = $feed;
325
326 4
        return $this;
327
    }
328
329
    /**
330
     * @return Feed
331
     */
332 4
    public function getFeed()
333
    {
334 4
        return $this->feed;
335
    }
336
337
    /**
338
     * @param ImportPart $parts
339
     *
340
     * @return $this
341
     */
342 4
    public function addPart(ImportPart $parts)
343
    {
344 4
        $this->parts[] = $parts;
345
346 4
        return $this;
347
    }
348
349
    /**
350
     * @param ImportPart $parts
351
     */
352
    public function removePart(ImportPart $parts)
353
    {
354
        $this->parts->removeElement($parts);
355
    }
356
357
    /**
358
     * @return ArrayCollection|ImportPart[]
359
     */
360 4
    public function getParts()
361
    {
362 4
        return $this->parts;
363
    }
364
365
    /**
366
     * @return bool
367
     */
368 4
    public function isStarted()
369
    {
370 4
        return !is_null($this->getDatetimeStarted());
371
    }
372
373
    /**
374
     * @return bool
375
     */
376 4
    public function isFinished()
377
    {
378 4
        return !is_null($this->getDatetimeEnded());
379
    }
380
381
    /**
382
     * Checks if any of the parts of the given import has an error.
383
     *
384
     * @return bool
385
     */
386
    public function hasErrors()
387
    {
388
        return ($this->getErroredParts() > 0 || $this->getParts()->isEmpty());
389
    }
390
}
391