Completed
Push — 2.1 ( 9f5244...4da803 )
by Rafał
23s queued 12s
created

BaseContent::setGuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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