Feed   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 498
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 66.29%

Importance

Changes 0
Metric Value
wmc 35
lcom 2
cbo 2
dl 0
loc 498
ccs 59
cts 89
cp 0.6629
rs 9.6
c 0
b 0
f 0

35 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __toString() 0 4 1
A getId() 0 4 1
A setFrequency() 0 6 1
A getFrequency() 0 4 1
A setPartial() 0 6 1
A isPartial() 0 4 1
A setSyndication() 0 6 1
A getSyndication() 0 4 1
A setType() 0 6 1
A getType() 0 4 1
A setReaderType() 0 6 1
A getReaderType() 0 4 1
A setImporterType() 0 6 1
A getImporterType() 0 4 1
A setOptions() 0 6 1
A getOptions() 0 4 1
A setReaderOptions() 0 6 1
A getReaderOptions() 0 4 1
A setImporterOptions() 0 6 1
A getImporterOptions() 0 4 1
A setTransportConfig() 0 6 1
A getTransportConfig() 0 4 1
A setDefaultValues() 0 6 1
A getDefaultValues() 0 4 1
A setOrigin() 0 6 1
A getOrigin() 0 4 1
A setSupplier() 0 6 1
A getSupplier() 0 4 1
A addImport() 0 6 1
A removeImport() 0 4 1
A getImports() 0 4 1
A addSource() 0 6 1
A removeSource() 0 4 1
A getSources() 0 4 1
1
<?php
2
3
namespace TreeHouse\IoBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use TreeHouse\IoBundle\Model\OriginInterface;
8
use TreeHouse\IoBundle\Model\SourceInterface;
9
10
/**
11
 * @ORM\Entity(repositoryClass="FeedRepository")
12
 * @ORM\Table
13
 */
14
class Feed
15
{
16
    /**
17
     * Items from this feed come directly from the source.
18
     */
19
    const SYNDICATION_DIRECT = 1;
20
21
    /**
22
     * Feed contains items from multiple sources, in an aggregated way.
23
     */
24
    const SYNDICATION_AGGREGATE = 2;
25
26
    /**
27
     * @var int
28
     *
29
     * @ORM\Column(type="integer")
30
     * @ORM\Id
31
     * @ORM\GeneratedValue(strategy="AUTO")
32
     */
33
    protected $id;
34
35
    /**
36
     * The frequency to import the feed with, in hours.
37
     *
38
     * @var int
39
     *
40
     * @ORM\Column(type="integer")
41
     */
42
    protected $frequency;
43
44
    /**
45
     * Whether the feed contains all items or only updates.
46
     *
47
     * @var bool
48
     *
49
     * @ORM\Column(type="boolean")
50
     */
51
    protected $partial;
52
53
    /**
54
     * Specifies where the feed's items come from.
55
     * Default options are 'direct' and 'aggregate', but these can be extended.
56
     *
57
     * @var int
58
     *
59
     * @ORM\Column(type="smallint")
60
     */
61
    protected $syndication = self::SYNDICATION_DIRECT;
62
63
    /**
64
     * One of the configured feed types.
65
     *
66
     * @var string
67
     *
68
     * @ORM\Column(type="string")
69
     */
70
    protected $type;
71
72
    /**
73
     * One of the configured reader types.
74
     *
75
     * @var string
76
     *
77
     * @ORM\Column(type="string")
78
     */
79
    protected $readerType;
80
81
    /**
82
     * One of the configured importer types.
83
     *
84
     * @var string
85
     *
86
     * @ORM\Column(type="string")
87
     */
88
    protected $importerType;
89
90
    /**
91
     * Options to be passed to the feed type.
92
     *
93
     * @var array
94
     *
95
     * @ORM\Column(type="json_array", nullable=true)
96
     */
97
    protected $options;
98
99
    /**
100
     * Options to be passed to the feed reader.
101
     *
102
     * @var array
103
     *
104
     * @ORM\Column(type="json_array", nullable=true)
105
     */
106
    protected $readerOptions;
107
108
    /**
109
     * Options to be passed to the feed importer.
110
     *
111
     * @var array
112
     *
113
     * @ORM\Column(type="json_array", nullable=true)
114
     */
115
    protected $importerOptions;
116
117
    /**
118
     * Configuration to use for downloading the feed.
119
     *
120
     * @var array
121
     *
122
     * @ORM\Column(type="json_array")
123
     */
124
    protected $transportConfig;
125
126
    /**
127
     * Can contain key/value pairs to be used as defaults if the feed doesn't supply them.
128
     *
129
     * @var array
130
     *
131
     * @ORM\Column(type="json_array", nullable=true)
132
     */
133
    protected $defaultValues;
134
135
    /**
136
     * The feed's origin.
137
     *
138
     * @var OriginInterface
139
     *
140
     * @ORM\ManyToOne(targetEntity="TreeHouse\IoBundle\Model\OriginInterface", inversedBy="feeds", cascade={"persist"})
141
     */
142
    protected $origin;
143
144
    /**
145
     * Sources that were imported using this feed.
146
     *
147
     * @var SourceInterface
148
     *
149
     * @ORM\OneToMany(targetEntity="TreeHouse\IoBundle\Model\SourceInterface", mappedBy="feed", cascade={"persist", "remove"})
150
     */
151
    protected $sources;
152
153
    /**
154
     * A specific supplier (a company, software package, etc.) that's providing this feed.
155
     *
156
     * @var FeedSupplier
157
     *
158
     * @ORM\ManyToOne(targetEntity="FeedSupplier", inversedBy="feeds", cascade={"persist"})
159
     */
160
    protected $supplier;
161
162
    /**
163
     * Imports for this feed.
164
     *
165
     * @var ArrayCollection|Import[]
166
     *
167
     * @ORM\OneToMany(targetEntity="Import", mappedBy="feed", cascade={"persist","remove"})
168
     */
169
    protected $imports;
170
171
    /**
172
     * Constructor.
173
     */
174 4
    public function __construct()
175
    {
176 4
        $this->imports = new ArrayCollection();
177 4
        $this->sources = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<TreeHouse\IoBundle\Model\SourceInterface> of property $sources.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
178 4
    }
179
180
    /**
181
     * @return string
182
     */
183
    public function __toString()
184
    {
185
        return sprintf('%s feed %d', $this->getOrigin()->getName(), $this->getId());
186
    }
187
188
    /**
189
     * @return int
190
     */
191 4
    public function getId()
192
    {
193 4
        return $this->id;
194
    }
195
196
    /**
197
     * @param int $frequency
198
     *
199
     * @return $this
200
     */
201 4
    public function setFrequency($frequency)
202
    {
203 4
        $this->frequency = $frequency;
204
205 4
        return $this;
206
    }
207
208
    /**
209
     * @return int
210
     */
211
    public function getFrequency()
212
    {
213
        return $this->frequency;
214
    }
215
216
    /**
217
     * @param bool $partial
218
     *
219
     * @return $this
220
     */
221 4
    public function setPartial($partial)
222
    {
223 4
        $this->partial = $partial;
224
225 4
        return $this;
226
    }
227
228
    /**
229
     * @return bool
230
     */
231 4
    public function isPartial()
232
    {
233 4
        return $this->partial;
234
    }
235
236
    /**
237
     * @param int $syndication
238
     *
239
     * @return $this
240
     */
241
    public function setSyndication($syndication)
242
    {
243
        $this->syndication = $syndication;
244
245
        return $this;
246
    }
247
248
    /**
249
     * @return int
250
     */
251
    public function getSyndication()
252
    {
253
        return $this->syndication;
254
    }
255
256
    /**
257
     * @param string $type
258
     *
259
     * @return $this
260
     */
261 4
    public function setType($type)
262
    {
263 4
        $this->type = $type;
264
265 4
        return $this;
266
    }
267
268
    /**
269
     * @return string
270
     */
271 4
    public function getType()
272
    {
273 4
        return $this->type;
274
    }
275
276
    /**
277
     * @param string $readerType
278
     *
279
     * @return $this
280
     */
281 4
    public function setReaderType($readerType)
282
    {
283 4
        $this->readerType = $readerType;
284
285 4
        return $this;
286
    }
287
288
    /**
289
     * @return string
290
     */
291 4
    public function getReaderType()
292
    {
293 4
        return $this->readerType;
294
    }
295
296
    /**
297
     * @param string $importerType
298
     *
299
     * @return $this
300
     */
301 4
    public function setImporterType($importerType)
302
    {
303 4
        $this->importerType = $importerType;
304
305 4
        return $this;
306
    }
307
308
    /**
309
     * @return string
310
     */
311 4
    public function getImporterType()
312
    {
313 4
        return $this->importerType;
314
    }
315
316
    /**
317
     * @param array $options
318
     *
319
     * @return $this
320
     */
321 4
    public function setOptions(array $options = null)
322
    {
323 4
        $this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options can be null. However, the property $options is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
324
325 4
        return $this;
326
    }
327
328
    /**
329
     * @return array
330
     */
331 4
    public function getOptions()
332
    {
333 4
        return $this->options;
334
    }
335
336
    /**
337
     * @param array $readerOptions
338
     *
339
     * @return $this
340
     */
341 4
    public function setReaderOptions(array $readerOptions = null)
342
    {
343 4
        $this->readerOptions = $readerOptions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $readerOptions can be null. However, the property $readerOptions is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
344
345 4
        return $this;
346
    }
347
348
    /**
349
     * @return array
350
     */
351 4
    public function getReaderOptions()
352
    {
353 4
        return $this->readerOptions;
354
    }
355
356
    /**
357
     * @param array $importerOptions
358
     *
359
     * @return $this
360
     */
361 4
    public function setImporterOptions(array $importerOptions = null)
362
    {
363 4
        $this->importerOptions = $importerOptions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $importerOptions can be null. However, the property $importerOptions is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
364
365 4
        return $this;
366
    }
367
368
    /**
369
     * @return array
370
     */
371 4
    public function getImporterOptions()
372
    {
373 4
        return $this->importerOptions;
374
    }
375
376
    /**
377
     * @param array $transportConfig
378
     *
379
     * @return $this
380
     */
381 4
    public function setTransportConfig(array $transportConfig)
382
    {
383 4
        $this->transportConfig = $transportConfig;
384
385 4
        return $this;
386
    }
387
388
    /**
389
     * @return array
390
     */
391 4
    public function getTransportConfig()
392
    {
393 4
        return $this->transportConfig;
394
    }
395
396
    /**
397
     * @param array $defaultValues
398
     *
399
     * @return $this
400
     */
401 4
    public function setDefaultValues(array $defaultValues = null)
402
    {
403 4
        $this->defaultValues = $defaultValues;
0 ignored issues
show
Documentation Bug introduced by
It seems like $defaultValues can be null. However, the property $defaultValues is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
404
405 4
        return $this;
406
    }
407
408
    /**
409
     * @return array
410
     */
411 4
    public function getDefaultValues()
412
    {
413 4
        return $this->defaultValues;
414
    }
415
416
    /**
417
     * @param OriginInterface $origin
418
     *
419
     * @return $this
420
     */
421 4
    public function setOrigin(OriginInterface $origin = null)
422
    {
423 4
        $this->origin = $origin;
424
425 4
        return $this;
426
    }
427
428
    /**
429
     * @return OriginInterface
430
     */
431 4
    public function getOrigin()
432
    {
433 4
        return $this->origin;
434
    }
435
436
    /**
437
     * @param FeedSupplier $supplier
438
     *
439
     * @return $this
440
     */
441
    public function setSupplier(FeedSupplier $supplier = null)
442
    {
443
        $this->supplier = $supplier;
444
445
        return $this;
446
    }
447
448
    /**
449
     * @return FeedSupplier
450
     */
451
    public function getSupplier()
452
    {
453
        return $this->supplier;
454
    }
455
456
    /**
457
     * @param Import $imports
458
     *
459
     * @return $this
460
     */
461
    public function addImport(Import $imports)
462
    {
463
        $this->imports[] = $imports;
464
465
        return $this;
466
    }
467
468
    /**
469
     * @param Import $import
470
     */
471
    public function removeImport(Import $import)
472
    {
473
        $this->imports->removeElement($import);
474
    }
475
476
    /**
477
     * @return ArrayCollection|Import[]
478
     */
479
    public function getImports()
480
    {
481
        return $this->imports;
482
    }
483
484
    /**
485
     * @param SourceInterface $source
486
     *
487
     * @return $this
488
     */
489
    public function addSource(SourceInterface $source)
490
    {
491
        $this->sources[] = $source;
492
493
        return $this;
494
    }
495
496
    /**
497
     * @param SourceInterface $source
498
     */
499
    public function removeSource(SourceInterface $source)
500
    {
501
        $this->sources->removeElement($source);
0 ignored issues
show
Bug introduced by
The method removeElement() does not seem to exist on object<TreeHouse\IoBundle\Model\SourceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
502
    }
503
504
    /**
505
     * @return SourceInterface[]|ArrayCollection
506
     */
507
    public function getSources()
508
    {
509
        return $this->sources;
510
    }
511
}
512