Completed
Push — develop ( b74491...9e8dd2 )
by
unknown
12:13
created

ArticleViewDocument::setTypeTranslation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ArticleBundle\Document;
13
14
use ONGR\ElasticsearchBundle\Annotation\Document;
15
use ONGR\ElasticsearchBundle\Annotation\Embedded;
16
use ONGR\ElasticsearchBundle\Annotation\Id;
17
use ONGR\ElasticsearchBundle\Annotation\Property;
18
use ONGR\ElasticsearchBundle\Collection\Collection;
19
20
/**
21
 * Indexable document for articles.
22
 *
23
 * @Document(type="article")
24
 */
25
class ArticleViewDocument implements ArticleViewDocumentInterface
26
{
27
    /**
28
     * @var string
29
     *
30
     * @Id
31
     */
32
    protected $id;
33
34
    /**
35
     * @var string
36
     *
37
     * @Property(type="string", options={"analyzer": "keyword"})
38
     */
39
    protected $uuid;
40
41
    /**
42
     * @var string
43
     *
44
     * @Property(type="string", options={"analyzer": "keyword"})
45
     */
46
    protected $locale;
47
48
    /**
49
     * @var string
50
     *
51
     * @Property(
52
     *     type="string",
53
     *     options={
54
     *         "fields":{
55
     *            "raw":{"type":"string", "index":"not_analyzed"},
56
     *            "value":{"type":"string"}
57
     *         }
58
     *     }
59
     * )
60
     */
61
    protected $title;
62
63
    /**
64
     * @var string
65
     *
66
     * @Property(
67
     *     type="string",
68
     *     options={
69
     *         "analyzer": "pathAnalyzer",
70
     *         "fields":{
71
     *            "raw":{"type":"string", "index":"not_analyzed"},
72
     *            "value":{"type":"string"}
73
     *         }
74
     *     }
75
     * )
76
     */
77
    protected $routePath;
78
79
    /**
80
     * @var string
81
     *
82
     * @Property(type="string", options={"analyzer": "keyword"})
83
     */
84
    protected $parentPageUuid;
85
86
    /**
87
     * @var string
88
     *
89
     * @Property(
90
     *     type="string",
91
     *     options={
92
     *         "analyzer":"keyword"
93
     *     }
94
     * )
95
     */
96
    protected $type;
97
98
    /**
99
     * @var string
100
     *
101
     * @Property(
102
     *     type="string",
103
     *     options={
104
     *         "analyzer":"keyword"
105
     *     }
106
     * )
107
     */
108
    protected $typeTranslation;
109
110
    /**
111
     * @var string
112
     *
113
     * @Property(
114
     *     type="string",
115
     *     options={
116
     *         "analyzer":"keyword"
117
     *     }
118
     * )
119
     */
120
    protected $structureType;
121
122
    /**
123
     * @var string
124
     *
125
     * @Property(
126
     *     type="string",
127
     *     options={
128
     *         "fields":{
129
     *            "raw":{"type":"string", "index":"not_analyzed"},
130
     *            "value":{"type":"string"}
131
     *         }
132
     *     }
133
     * )
134
     */
135
    protected $changerFullName;
136
137
    /**
138
     * @var string
139
     *
140
     * @Property(
141
     *     type="string",
142
     *     options={
143
     *         "fields":{
144
     *            "raw":{"type":"string", "index":"not_analyzed"},
145
     *            "value":{"type":"string"}
146
     *         }
147
     *     }
148
     * )
149
     */
150
    protected $creatorFullName;
151
152
    /**
153
     * @var \DateTime
154
     *
155
     * @Property(type="date")
156
     */
157
    protected $changed;
158
159
    /**
160
     * @var \DateTime
161
     *
162
     * @Property(type="date")
163
     */
164
    protected $created;
165
166
    /**
167
     * @var ExcerptViewObject
168
     *
169
     * @Embedded(class="SuluArticleBundle:ExcerptViewObject")
170
     */
171
    protected $excerpt;
172
173
    /**
174
     * @var SeoViewObject
175
     *
176
     * @Embedded(class="SuluArticleBundle:SeoViewObject")
177
     */
178
    protected $seo;
179
180
    /**
181
     * @var \DateTime
182
     *
183
     * @Property(type="date")
184
     */
185
    protected $authored;
186
187
    /**
188
     * @var string
189
     *
190
     * @Property(
191
     *     type="string",
192
     *     options={
193
     *         "fields":{
194
     *            "raw":{"type":"string", "index":"not_analyzed"},
195
     *            "value":{"type":"string"}
196
     *         }
197
     *     }
198
     * )
199
     */
200
    protected $authorFullName;
201
202
    /**
203
     * @var string
204
     *
205
     * @Property(type="string")
206
     */
207
    protected $teaserDescription = '';
208
209
    /**
210
     * @var int
211
     *
212
     * @Property(type="integer")
213
     */
214
    protected $teaserMediaId;
215
216
    /**
217
     * @var \DateTime
218
     *
219
     * @Property(type="date")
220
     */
221
    protected $published;
222
223
    /**
224
     * @var bool
225
     *
226
     * @Property(type="boolean")
227
     */
228
    protected $publishedState;
229
230
    /**
231
     * @var LocalizationStateViewObject
232
     *
233
     * @Embedded(class="SuluArticleBundle:LocalizationStateViewObject")
234
     */
235
    protected $localizationState;
236
237
    /**
238
     * @var string
239
     *
240
     * @Property(type="string")
241
     */
242
    protected $authorId;
243
244
    /**
245
     * @var string
246
     *
247
     * @Property(type="string")
248
     */
249
    protected $creatorContactId;
250
251
    /**
252
     * @var string
253
     *
254
     * @Property(type="string")
255
     */
256
    protected $changerContactId;
257
258
    /**
259
     * @var ArticlePageViewObject[]
260
     *
261
     * @Embedded(class="SuluArticleBundle:ArticlePageViewObject", multiple=true)
262
     */
263
    protected $pages = [];
264
265
    /**
266
     * @var string
267 56
     *
268
     * @Property(type="string", options={"index":"not_analyzed"})
269 56
     */
270 56
    protected $contentData;
271
272
    /**
273
     * @var \ArrayObject
274
     */
275 52
    protected $content;
276
277 52
    /**
278
     * @var \ArrayObject
279
     */
280
    protected $view;
281
282
    /**
283 52
     * @param string $uuid
284
     */
285 52
    public function __construct($uuid = null)
286
    {
287 52
        $this->uuid = $uuid;
288
    }
289
290
    /**
291
     * {@inheritdoc}
292
     */
293 56
    public function getId()
294
    {
295 56
        return $this->id;
296
    }
297
298
    /**
299
     * {@inheritdoc}
300
     */
301 52
    public function setId($id)
302
    {
303 52
        $this->id = $id;
304
305 52
        return $this;
306
    }
307
308
    /**
309
     * {@inheritdoc}
310
     */
311 53
    public function getUuid()
312
    {
313 53
        return $this->uuid;
314
    }
315
316
    /**
317
     * {@inheritdoc}
318
     */
319 55
    public function setUuid($uuid)
320
    {
321 55
        $this->uuid = $uuid;
322
323 55
        return $this;
324
    }
325
326
    /**
327
     * {@inheritdoc}
328
     */
329 52
    public function getLocale()
330
    {
331 52
        return $this->locale;
332
    }
333
334
    /**
335
     * {@inheritdoc}
336
     */
337 52
    public function setLocale($locale)
338
    {
339 52
        $this->locale = $locale;
340
341 52
        return $this;
342
    }
343
344
    /**
345
     * {@inheritdoc}
346
     */
347 52
    public function getTitle()
348
    {
349 52
        return $this->title;
350
    }
351
352
    /**
353
     * {@inheritdoc}
354
     */
355 52
    public function setTitle($title)
356
    {
357 52
        $this->title = $title;
358 52
359
        return $this;
360
    }
361
362
    /**
363 52
     * {@inheritdoc}
364
     */
365 52
    public function getRoutePath()
366
    {
367
        return $this->routePath;
368
    }
369
370
    /**
371 8
     * {@inheritdoc}
372
     */
373 8
    public function setRoutePath($routePath)
374
    {
375 8
        $this->routePath = $routePath;
376
    }
377
378
    /**
379
     * {@inheritdoc}
380
     */
381 52
    public function getParentPageUuid()
382
    {
383 52
        return $this->parentPageUuid;
384
    }
385
386
    /**
387
     * {@inheritdoc}
388
     */
389 52
    public function setParentPageUuid($parentPageUuid)
390
    {
391 52
        $this->parentPageUuid = $parentPageUuid;
392
393 52
        return $this;
394
    }
395
396
    /**
397
     * {@inheritdoc}
398
     */
399 52
    public function getType()
400
    {
401 52
        return $this->type;
402
    }
403
404
    /**
405
     * {@inheritdoc}
406
     */
407 52
    public function setType($type)
408
    {
409 52
        $this->type = $type;
410
411 52
        return $this;
412
    }
413
414
    /**
415
     * {@inheritdoc}
416
     */
417 52
    public function getTypeTranslation()
418
    {
419 52
        return $this->typeTranslation;
420
    }
421
422
    /**
423
     * {@inheritdoc}
424
     */
425 54
    public function setTypeTranslation($typeTranslation)
426
    {
427 54
        $this->typeTranslation = $typeTranslation;
428
429 54
        return $this;
430
    }
431
432
    /**
433
     * {@inheritdoc}
434
     */
435 52
    public function getStructureType()
436
    {
437 52
        return $this->structureType;
438
    }
439
440
    /**
441
     * {@inheritdoc}
442
     */
443 52
    public function setStructureType($structureType)
444
    {
445 52
        $this->structureType = $structureType;
446
447 52
        return $this;
448
    }
449
450
    /**
451
     * {@inheritdoc}
452
     */
453 52
    public function getChangerFullName()
454
    {
455 52
        return $this->changerFullName;
456
    }
457
458
    /**
459
     * {@inheritdoc}
460
     */
461 52
    public function setChangerFullName($changerFullName)
462
    {
463 52
        $this->changerFullName = $changerFullName;
464
465 52
        return $this;
466
    }
467
468
    /**
469
     * {@inheritdoc}
470
     */
471 52
    public function getCreatorFullName()
472
    {
473 52
        return $this->creatorFullName;
474
    }
475
476
    /**
477
     * {@inheritdoc}
478
     */
479 52
    public function setCreatorFullName($creatorFullName)
480
    {
481 52
        $this->creatorFullName = $creatorFullName;
482
483 52
        return $this;
484
    }
485
486
    /**
487
     * {@inheritdoc}
488
     */
489 52
    public function getChanged()
490
    {
491 52
        return $this->changed;
492
    }
493
494
    /**
495
     * {@inheritdoc}
496
     */
497 52
    public function setChanged($changed)
498
    {
499 52
        $this->changed = $changed;
500
501 52
        return $this;
502
    }
503
504
    /**
505
     * {@inheritdoc}
506
     */
507 52
    public function getCreated()
508
    {
509 52
        return $this->created;
510
    }
511
512
    /**
513
     * {@inheritdoc}
514
     */
515 52
    public function setCreated($created)
516
    {
517 52
        $this->created = $created;
518
519 52
        return $this;
520
    }
521
522
    /**
523
     * {@inheritdoc}
524
     */
525 52
    public function getExcerpt()
526
    {
527 52
        return $this->excerpt;
528
    }
529
530
    /**
531
     * {@inheritdoc}
532
     */
533 52
    public function setExcerpt(ExcerptViewObject $excerpt)
534
    {
535 52
        $this->excerpt = $excerpt;
536
537 52
        return $this;
538
    }
539
540
    /**
541
     * {@inheritdoc}
542
     */
543 52
    public function getSeo()
544
    {
545 52
        return $this->seo;
546
    }
547
548
    /**
549
     * {@inheritdoc}
550
     */
551 52
    public function setSeo(SeoViewObject $seo)
552
    {
553 52
        $this->seo = $seo;
554
555 52
        return $this;
556
    }
557
558
    /**
559
     * {@inheritdoc}
560
     */
561 52
    public function getAuthored()
562
    {
563 52
        return $this->authored;
564
    }
565
566
    /**
567
     * {@inheritdoc}
568
     */
569 52
    public function setAuthored(\DateTime $authored = null)
570
    {
571 52
        $this->authored = $authored;
572
573 52
        return $this;
574
    }
575
576
    /**
577
     * {@inheritdoc}
578
     */
579 52
    public function getAuthorFullName()
580
    {
581 52
        return $this->authorFullName;
582
    }
583
584
    /**
585
     * {@inheritdoc}
586
     */
587 46
    public function setAuthorFullName($authorFullName)
588
    {
589 46
        $this->authorFullName = $authorFullName;
590
591 46
        return $this;
592
    }
593
594
    /**
595
     * {@inheritdoc}
596
     */
597 52
    public function getTeaserDescription()
598
    {
599 52
        return $this->teaserDescription;
600
    }
601
602
    /**
603
     * {@inheritdoc}
604
     */
605 1
    public function setTeaserDescription($teaserDescription)
606
    {
607 1
        $this->teaserDescription = $teaserDescription;
608 1
609
        return $this;
610
    }
611
612
    /**
613 52
     * {@inheritdoc}
614
     */
615 52
    public function getTeaserMediaId()
616
    {
617
        return $this->teaserMediaId;
618
    }
619
620
    /**
621 52
     * {@inheritdoc}
622
     */
623 52
    public function setTeaserMediaId($teaserMediaId)
624
    {
625 52
        $this->teaserMediaId = $teaserMediaId;
626
    }
627
628
    /**
629
     * {@inheritdoc}
630
     */
631 52
    public function getPublished()
632
    {
633 52
        return $this->published;
634
    }
635
636
    /**
637
     * {@inheritdoc}
638
     */
639 52
    public function setPublished(\DateTime $published = null)
640
    {
641 52
        $this->published = $published;
642
643 52
        return $this;
644
    }
645
646
    /**
647
     * {@inheritdoc}
648
     */
649 52
    public function getPublishedState()
650
    {
651 52
        return $this->publishedState;
652
    }
653
654
    /**
655
     * {@inheritdoc}
656
     */
657 52
    public function setPublishedState($publishedState)
658
    {
659 52
        $this->publishedState = $publishedState;
660
661 52
        return $this;
662
    }
663
664
    /**
665
     * {@inheritdoc}
666
     */
667 52
    public function getLocalizationState()
668
    {
669 52
        return $this->localizationState;
670
    }
671 52
672
    /**
673
     * {@inheritdoc}
674
     */
675
    public function setLocalizationState(LocalizationStateViewObject $localizationState)
676
    {
677 52
        $this->localizationState = $localizationState;
678
679 52
        return $this;
680
    }
681
682
    /**
683
     * {@inheritdoc}
684
     */
685 52
    public function setAuthorId($authorId)
686
    {
687 52
        $this->authorId = $authorId;
688
689 52
        return $this;
690
    }
691
692
    /**
693
     * {@inheritdoc}
694
     */
695 52
    public function getAuthorId()
696
    {
697 52
        return $this->authorId;
698
    }
699
700
    /**
701
     * {@inheritdoc}
702
     */
703 52
    public function setCreatorContactId($creatorContactId)
704
    {
705 52
        $this->creatorContactId = $creatorContactId;
706
707 52
        return $this;
708
    }
709
710
    /**
711
     * {@inheritdoc}
712
     */
713 52
    public function getCreatorContactId()
714
    {
715 52
        return $this->creatorContactId;
716
    }
717
718
    /**
719
     * {@inheritdoc}
720
     */
721 52
    public function setChangerContactId($changerContactId)
722
    {
723 52
        $this->changerContactId = $changerContactId;
724
725
        return $this;
726
    }
727
728
    /**
729 52
     * {@inheritdoc}
730
     */
731 52
    public function getChangerContactId()
732
    {
733 52
        return $this->changerContactId;
734
    }
735
736
    /**
737
     * {@inheritdoc}
738
     */
739
    public function getPages()
740
    {
741
        return $this->pages;
742
    }
743
744
    /**
745
     * {@inheritdoc}
746
     */
747
    public function setPages(Collection $pages)
748
    {
749
        $this->pages = $pages;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pages of type object<ONGR\Elasticsearc...\Collection\Collection> is incompatible with the declared type array<integer,object<Sul...ArticlePageViewObject>> of property $pages.

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...
750
751
        return $this;
752
    }
753
754
    /**
755
     * {@inheritdoc}
756
     */
757
    public function getContentData()
758
    {
759
        return $this->contentData;
760
    }
761
762
    /**
763
     * {@inheritdoc}
764
     */
765
    public function setContentData($contentData)
766
    {
767
        $this->contentData = $contentData;
768
769
        return $this;
770
    }
771
772
    /**
773
     * {@inheritdoc}
774
     */
775
    public function getContent()
776
    {
777
        return $this->content;
778
    }
779
780
    /**
781
     * {@inheritdoc}
782
     */
783
    public function setContent(\ArrayObject $content)
784
    {
785
        $this->content = $content;
786
787
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\ArticleBundl...ent\ArticleViewDocument) is incompatible with the return type declared by the interface Sulu\Bundle\ArticleBundl...ntInterface::setContent of type ArrayObject.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
788
    }
789
790
    /**
791
     * {@inheritdoc}
792
     */
793
    public function getView()
794
    {
795
        return $this->view;
796
    }
797
798
    /**
799
     * {@inheritdoc}
800
     */
801
    public function setView(\ArrayObject $view)
802
    {
803
        $this->view = $view;
804
805
        return $this;
806
    }
807
}
808