Completed
Push — master ( 6ca798...857129 )
by Rafał
09:18 queued 10s
created

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