Completed
Push — master ( 05bb5a...5289b8 )
by Rafał
34:32 queued 04:15
created

BaseContent::getSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Bridge Component.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\Bridge\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
19
class BaseContent implements ContentInterface
20
{
21
    use AuthorsAwareTrait;
22
23
    /**
24
     * @var mixed
25
     */
26
    protected $id;
27
28
    /**
29
     * @var string
30
     */
31
    protected $guid;
32
33
    /**
34
     * @var string
35
     */
36
    protected $headline;
37
38
    /**
39
     * @var string
40
     */
41
    protected $byline;
42
43
    /**
44
     * @var string
45
     */
46
    protected $slugline;
47
48
    /**
49
     * @var string
50
     */
51
    protected $language;
52
53
    /**
54
     * @var array
55
     */
56
    protected $subjects = [];
57
58
    /**
59
     * @var string
60
     */
61
    protected $type;
62
63
    /**
64
     * @var array
65
     */
66
    protected $places = [];
67
68
    /**
69
     * @var array
70
     */
71
    protected $services = [];
72
73
    /**
74
     * @var string
75
     */
76
    protected $located;
77
78
    /**
79
     * @var int
80
     */
81
    protected $urgency = 0;
82
83
    /**
84
     * @var int
85
     */
86
    protected $priority;
87
88
    /**
89
     * @var int
90
     */
91
    protected $version;
92
93
    /**
94
     * @var string
95
     */
96
    protected $genre;
97
98
    /**
99
     * @var string
100
     */
101
    protected $edNote;
102
103
    /**
104
     * @var string
105
     */
106
    protected $description;
107
108
    /**
109
     * @var array
110
     */
111
    protected $keywords = [];
112
113
    /**
114
     * @var string
115
     */
116
    protected $pubStatus = ContentInterface::STATUS_USABLE;
117
118
    /**
119
     * @var string|null
120
     */
121
    protected $evolvedFrom;
122
123
    /**
124
     * @var string|null
125
     */
126
    protected $source;
127
128 12
    /**
129
     * @var array
130 12
     */
131
    protected $extra = [];
132
133
    /**
134
     * @var \DateTimeInterface|null
135
     */
136
    protected $firstPublishedAt;
137
138
    public function __construct()
139
    {
140
        $this->authors = new ArrayCollection();
141
    }
142
143
    /**
144 12
     * @return mixed
145
     */
146 12
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154
    public function setId($id)
155
    {
156
        $this->id = $id;
157
    }
158
159
    /**
160 12
     * {@inheritdoc}
161
     */
162 12
    public function getByline()
163
    {
164
        return $this->byline;
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function setByline($byline)
171
    {
172
        $this->byline = $byline;
173
    }
174
175
    /**
176 12
     * {@inheritdoc}
177
     */
178 12
    public function getSlugline()
179
    {
180
        return $this->slugline;
181
    }
182
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function setSlugline($slugline)
187
    {
188
        $this->slugline = $slugline;
189
    }
190
191
    /**
192 12
     * {@inheritdoc}
193
     */
194 12
    public function getLanguage()
195
    {
196
        return $this->language;
197
    }
198
199
    /**
200
     * {@inheritdoc}
201
     */
202
    public function setLanguage($language)
203
    {
204
        $this->language = $language;
205
    }
206
207
    /**
208 12
     * {@inheritdoc}
209
     */
210 12
    public function getSubjects()
211
    {
212
        return $this->subjects;
213
    }
214
215
    /**
216
     * {@inheritdoc}
217
     */
218
    public function setSubjects(array $subjects = [])
219
    {
220
        $this->subjects = $subjects;
221
    }
222
223
    /**
224 12
     * {@inheritdoc}
225
     */
226 12
    public function getType()
227
    {
228
        return $this->type;
229
    }
230
231
    /**
232
     * {@inheritdoc}
233
     */
234
    public function setType($type)
235
    {
236
        $this->type = $type;
237
    }
238
239
    /**
240 12
     * {@inheritdoc}
241
     */
242 12
    public function getPlaces()
243
    {
244
        return $this->places;
245
    }
246
247
    /**
248
     * {@inheritdoc}
249
     */
250
    public function setPlaces($places)
251
    {
252
        $this->places = $places;
253
    }
254
255
    /**
256 12
     * {@inheritdoc}
257
     */
258 12
    public function getLocated()
259
    {
260
        return $this->located;
261
    }
262
263
    /**
264
     * {@inheritdoc}
265
     */
266
    public function setLocated($located)
267
    {
268
        $this->located = $located;
269
    }
270
271
    /**
272
     * {@inheritdoc}
273
     */
274
    public function getUrgency()
275
    {
276
        return $this->urgency;
277
    }
278
279
    /**
280
     * {@inheritdoc}
281
     */
282
    public function setUrgency($urgency)
283
    {
284
        $this->urgency = $urgency;
285
    }
286
287
    /**
288 12
     * {@inheritdoc}
289
     */
290 12
    public function getPriority()
291
    {
292
        return $this->priority;
293
    }
294
295
    /**
296
     * {@inheritdoc}
297
     */
298
    public function setPriority($priority)
299
    {
300
        $this->priority = $priority;
301
    }
302
303
    /**
304 12
     * {@inheritdoc}
305
     */
306 12
    public function getVersion()
307
    {
308
        return $this->version;
309
    }
310
311
    /**
312
     * {@inheritdoc}
313
     */
314
    public function setVersion($version)
315
    {
316
        $this->version = $version;
317
    }
318
319
    /**
320 12
     * {@inheritdoc}
321
     */
322 12
    public function getHeadline()
323
    {
324
        return $this->headline;
325
    }
326
327
    /**
328
     * {@inheritdoc}
329
     */
330
    public function setHeadline($headline)
331
    {
332
        $this->headline = $headline;
333
    }
334
335
    /**
336 12
     * {@inheritdoc}
337
     */
338 12
    public function getGuid()
339
    {
340
        return $this->guid;
341
    }
342
343
    /**
344
     * {@inheritdoc}
345
     */
346
    public function setGuid($guid)
347
    {
348
        $this->guid = $guid;
349
    }
350
351
    /**
352 12
     * {@inheritdoc}
353
     */
354 12
    public function getServices()
355
    {
356
        return $this->services;
357
    }
358
359
    /**
360
     * {@inheritdoc}
361
     */
362
    public function getServicesNames(): array
363
    {
364
        return $this->mapNames($this->services);
365
    }
366
367
    /**
368 12
     * {@inheritdoc}
369
     */
370 12
    public function getServicesCodes(): array
371
    {
372
        return $this->mapCodes($this->services);
373
    }
374
375
    public function getSubjectsSchemes(): array
376
    {
377
        return $this->mapSchemes($this->subjects);
378
    }
379
380
    public function getSubjectsNames(): array
381
    {
382
        return $this->mapNames($this->subjects);
383
    }
384 12
385
    private function mapNames(array $values): array
386
    {
387 12
        return array_map(function ($subject) {
388 12
            if (\is_array($subject) && \array_key_exists('name', $subject)) {
389 12
                return $subject['name'];
390 12
            }
391 12
392 12
            return $subject;
393 12
        }, $values);
394 12
    }
395 12
396 12
    private function mapCodes(array $values): array
397 12
    {
398 12
        return array_map(function ($subject) {
399
            if (\is_array($subject) && \array_key_exists('code', $subject)) {
400
                return $subject['code'];
401
            }
402
403
            return $subject;
404
        }, $values);
405 12
    }
406
407 12
    private function mapSchemes(array $values): array
408
    {
409
        return array_map(function ($subject) {
410
            if (\is_array($subject) && \array_key_exists('scheme', $subject)) {
411
                return $subject['scheme'];
412
            }
413
414
            return $subject;
415
        }, $values);
416
    }
417
418
    /**
419
     * {@inheritdoc}
420
     */
421
    public function setServices(array $services = [])
422
    {
423
        $this->services = $services;
424
    }
425
426
    /**
427
     * {@inheritdoc}
428
     */
429
    public function getEdNote()
430
    {
431
        return $this->edNote;
432
    }
433
434
    /**
435
     * {@inheritdoc}
436
     */
437
    public function setEdNote($edNote)
438
    {
439
        $this->edNote = $edNote;
440
    }
441
442
    /**
443
     * {@inheritdoc}
444
     */
445
    public function getGenre()
446
    {
447
        return $this->genre;
448
    }
449
450
    /**
451
     * {@inheritdoc}
452
     */
453
    public function setGenre($genre)
454
    {
455
        $this->genre = $genre;
456
    }
457
458
    /**
459
     * @return string
460
     */
461
    public function getDescription()
462
    {
463
        return $this->description;
464
    }
465
466
    /**
467
     * @param string $description
468
     */
469
    public function setDescription($description)
470
    {
471
        $this->description = $description;
472
    }
473
474
    /**
475
     * {@inheritdoc}
476
     */
477
    public function getMetadata()
478
    {
479
        return [
480
            'subject' => $this->getSubjects(),
481
            'urgency' => $this->getUrgency(),
482
            'priority' => $this->getPriority(),
483
            'located' => $this->getLocated(),
484
            'place' => $this->getPlaces(),
485
            'service' => $this->getServices(),
486
            'type' => $this->getType(),
487
            'byline' => $this->getByline(),
488
            'guid' => $this->getGuid(),
489
            'edNote' => $this->getEdNote(),
490
            'genre' => $this->getGenre(),
491
            'language' => $this->getLanguage(),
492
        ];
493
    }
494
495
    /**
496
     * {@inheritdoc}
497
     */
498
    public function getKeywords()
499
    {
500
        return $this->keywords;
501
    }
502
503
    /**
504
     * {@inheritdoc}
505
     */
506
    public function setKeywords(array $keywords)
507
    {
508
        $this->keywords = $keywords;
509
    }
510
511
    /**
512
     * {@inheritdoc}
513
     */
514
    public function getPubStatus()
515
    {
516
        return $this->pubStatus;
517
    }
518
519
    /**
520
     * {@inheritdoc}
521
     */
522
    public function setPubStatus(string $pubStatus)
523
    {
524
        $this->pubStatus = $pubStatus;
525
    }
526
527
    /**
528
     * {@inheritdoc}
529
     */
530
    public function getEvolvedFrom()
531
    {
532
        return $this->evolvedFrom;
533
    }
534
535
    /**
536
     * {@inheritdoc}
537
     */
538
    public function setEvolvedFrom(string $evolvedFrom)
539
    {
540
        $this->evolvedFrom = $evolvedFrom;
541
    }
542
543
    /**
544
     * {@inheritdoc}
545
     */
546
    public function getSource()
547
    {
548
        return $this->source;
549
    }
550
551
    /**
552
     * {@inheritdoc}
553
     */
554
    public function setSource($source)
555
    {
556
        $this->source = $source;
557
    }
558
559
    /**
560
     * {@inheritdoc}
561
     */
562
    public function getExtra(): array
563
    {
564
        if (null === $this->extra) {
565
            return [];
566
        }
567
568
        return $this->extra;
569
    }
570
571
    /**
572
     * {@inheritdoc}
573
     */
574
    public function setExtra(?array $extra): void
575
    {
576
        $this->extra = $extra;
0 ignored issues
show
Documentation Bug introduced by
It seems like $extra can be null. However, the property $extra 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...
577
    }
578
579
    public function getFirstPublishedAt(): ?\DateTimeInterface
580
    {
581
        return $this->firstPublishedAt;
582
    }
583
584
    public function setFirstPublishedAt(?\DateTimeInterface $firstPublishedAt): void
585
    {
586
        $this->firstPublishedAt = $firstPublishedAt;
587
    }
588
}
589