Completed
Pull Request — develop (#161)
by Wachter
22:54 queued 09:56
created

ArticleDocument::setExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
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 Sulu\Bundle\ArticleBundle\Document\Behavior\DateShardingBehavior;
15
use Sulu\Bundle\ArticleBundle\Document\Behavior\RoutableBehavior;
16
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
17
use Sulu\Component\Content\Document\Behavior\AuthorBehavior;
18
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior;
19
use Sulu\Component\Content\Document\Behavior\LocalizedAuditableBehavior;
20
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior;
21
use Sulu\Component\Content\Document\Behavior\StructureBehavior;
22
use Sulu\Component\Content\Document\Behavior\WorkflowStageBehavior;
23
use Sulu\Component\Content\Document\Extension\ExtensionContainer;
24
use Sulu\Component\Content\Document\Structure\Structure;
25
use Sulu\Component\Content\Document\Structure\StructureInterface;
26
use Sulu\Component\DocumentManager\Behavior\Mapping\ChildrenBehavior;
27
use Sulu\Component\DocumentManager\Behavior\Mapping\LocalizedTitleBehavior;
28
use Sulu\Component\DocumentManager\Behavior\Mapping\NodeNameBehavior;
29
use Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior;
30
use Sulu\Component\DocumentManager\Behavior\Mapping\UuidBehavior;
31
use Sulu\Component\DocumentManager\Behavior\Path\AutoNameBehavior;
32
use Sulu\Component\DocumentManager\Behavior\VersionBehavior;
33
use Sulu\Component\DocumentManager\Collection\ChildrenCollection;
34
use Sulu\Component\DocumentManager\Version;
35
36
/**
37
 * Represents an article in phpcr.
38
 */
39
class ArticleDocument implements
40
    UuidBehavior,
41
    NodeNameBehavior,
42
    AutoNameBehavior,
43
    PathBehavior,
44
    LocalizedTitleBehavior,
45
    StructureBehavior,
46
    LocalizedStructureBehavior,
47
    LocalizedAuditableBehavior,
48
    DateShardingBehavior,
49
    RoutableBehavior,
50
    ExtensionBehavior,
51
    WorkflowStageBehavior,
52
    VersionBehavior,
53
    AuthorBehavior,
54
    ChildrenBehavior,
55
    ArticleInterface
56
{
57
    /**
58
     * @var string
59
     */
60
    private $uuid;
61
62
    /**
63
     * @var string
64
     */
65
    private $nodeName;
66
67
    /**
68
     * @var string
69
     */
70
    private $path;
71
72
    /**
73
     * @var object
74
     */
75
    private $parent;
76
77
    /**
78
     * @var string
79
     */
80
    private $title;
81
82
    /**
83
     * @var string
84
     */
85
    private $pageTitle;
86
87
    /**
88
     * @var array
89
     */
90
    private $pages;
91
92
    /**
93
     * @var RouteInterface
94
     */
95
    private $route;
96
97
    /**
98
     * @var string
99
     */
100
    private $routePath;
101
102
    /**
103
     * @var string
104
     */
105
    private $locale;
106
107
    /**
108
     * @var string
109
     */
110
    private $originalLocale;
111
112
    /**
113
     * @var string
114
     */
115
    private $structureType;
116
117
    /**
118
     * @var StructureInterface
119
     */
120
    private $structure;
121
122
    /**
123
     * @var int
124
     */
125
    private $creator;
126
127
    /**
128
     * @var int
129
     */
130
    private $changer;
131
132
    /**
133
     * @var \DateTime
134
     */
135
    private $created;
136
137
    /**
138
     * @var \DateTime
139
     */
140
    private $changed;
141
142
    /**
143
     * @var int
144
     */
145
    private $author;
146
147
    /**
148
     * @var \DateTime
149
     */
150
    private $authored;
151
152
    /**
153
     * Document's extensions ie seo, ...
154
     *
155
     * @var ExtensionContainer
156
     */
157
    protected $extensions;
158
159
    /**
160
     * Workflow Stage currently Test or Published.
161
     *
162
     * @var int
163
     */
164
    protected $workflowStage;
165
166
    /**
167
     * Is Document is published.
168
     *
169
     * @var bool
170
     */
171
    protected $published;
172
173
    /**
174
     * List of versions.
175
     *
176
     * @var Version[]
177
     */
178
    protected $versions = [];
179
180
    /**
181
     * @var ChildrenCollection
182
     */
183
    protected $children;
184
185 44
    public function __construct()
186
    {
187 44
        $this->structure = new Structure();
188 44
        $this->extensions = new ExtensionContainer();
189 44
        $this->children = new \ArrayIterator();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \ArrayIterator() of type object<ArrayIterator> is incompatible with the declared type object<Sulu\Component\Do...ion\ChildrenCollection> of property $children.

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...
190 44
    }
191
192
    /**
193
     * {@inheritdoc}
194
     */
195 44
    public function getUuid()
196
    {
197 44
        return $this->uuid;
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203 44
    public function setUuid($uuid)
204
    {
205 44
        $this->uuid = $uuid;
206 44
    }
207
208
    /**
209
     * {@inheritdoc}
210
     */
211
    public function getNodeName()
212
    {
213
        return $this->nodeName;
214
    }
215
216
    /**
217
     * {@inheritdoc}
218
     */
219 29
    public function getPath()
220
    {
221 29
        return $this->path;
222
    }
223
224
    /**
225
     * {@inheritdoc}
226
     */
227 44
    public function getParent()
228
    {
229 44
        return $this->parent;
230
    }
231
232
    /**
233
     * {@inheritdoc}
234
     */
235 44
    public function setParent($document)
236
    {
237 44
        $this->parent = $document;
238 44
    }
239
240
    /**
241
     * {@inheritdoc}
242
     */
243 44
    public function getTitle()
244
    {
245 44
        return $this->title;
246
    }
247
248
    /**
249
     * {@inheritdoc}
250
     */
251 44
    public function setTitle($title)
252
    {
253 44
        $this->title = $title;
254 44
    }
255
256
    /**
257
     * Returns route.
258
     *
259
     * @return RouteInterface
260
     */
261 11
    public function getRoute()
262
    {
263 11
        return $this->route;
264
    }
265
266
    /**
267
     * {@inheritdoc}
268
     */
269 11
    public function setRoute(RouteInterface $route)
270
    {
271 11
        $this->route = $route;
272 11
    }
273
274
    /**
275
     * {@inheritdoc}
276
     */
277
    public function removeRoute()
278
    {
279
        $this->route = null;
280
        $this->routePath = null;
281
    }
282
283
    /**
284
     * {@inheritdoc}
285
     */
286 44
    public function getRoutePath()
287
    {
288 44
        return $this->routePath;
289
    }
290
291
    /**
292
     * {@inheritdoc}
293
     */
294 44
    public function setRoutePath($routePath)
295
    {
296 44
        $this->routePath = $routePath;
297 44
    }
298
299
    /**
300
     * {@inheritdoc}
301
     */
302 44
    public function getClass()
303
    {
304 44
        return self::class;
305
    }
306
307
    /**
308
     * {@inheritdoc}
309
     */
310 44
    public function getLocale()
311
    {
312 44
        return $this->locale;
313
    }
314
315
    /**
316
     * {@inheritdoc}
317
     */
318 44
    public function setLocale($locale)
319
    {
320 44
        $this->locale = $locale;
321 44
    }
322
323
    /**
324
     * {@inheritdoc}
325
     */
326 44
    public function getOriginalLocale()
327
    {
328 44
        return $this->originalLocale;
329
    }
330
331
    /**
332
     * {@inheritdoc}
333
     */
334 44
    public function setOriginalLocale($locale)
335
    {
336 44
        $this->originalLocale = $locale;
337 44
    }
338
339
    /**
340
     * {@inheritdoc}
341
     */
342 44
    public function getStructureType()
343
    {
344 44
        return $this->structureType;
345
    }
346
347
    /**
348
     * {@inheritdoc}
349
     */
350 44
    public function setStructureType($structureType)
351
    {
352 44
        $this->structureType = $structureType;
353 44
    }
354
355
    /**
356
     * {@inheritdoc}
357
     */
358 44
    public function getStructure()
359
    {
360 44
        return $this->structure;
361
    }
362
363
    /**
364
     * {@inheritdoc}
365
     */
366 44
    public function getCreator()
367
    {
368 44
        return $this->creator;
369
    }
370
371
    /**
372
     * {@inheritdoc}
373
     */
374 44
    public function getChanger()
375
    {
376 44
        return $this->changer;
377
    }
378
379
    /**
380
     * {@inheritdoc}
381
     */
382 44
    public function getCreated()
383
    {
384 44
        return $this->created;
385
    }
386
387
    /**
388
     * {@inheritdoc}
389
     */
390 44
    public function getChanged()
391
    {
392 44
        return $this->changed;
393
    }
394
395
    /**
396
     * Returns identifier.
397
     *
398
     * @return mixed
399
     */
400 44
    public function getId()
401
    {
402 44
        return $this->getUuid();
403
    }
404
405
    /**
406
     * {@inheritdoc}
407
     */
408 44
    public function getExtensionsData()
409
    {
410 44
        return $this->extensions;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->extensions; (Sulu\Component\Content\D...sion\ExtensionContainer) is incompatible with the return type declared by the interface Sulu\Component\Content\D...vior::getExtensionsData of type array.

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...
411
    }
412
413
    /**
414
     * {@inheritdoc}
415
     */
416 44
    public function setExtensionsData($extensions)
417
    {
418 44
        $this->extensions = $extensions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $extensions of type array is incompatible with the declared type object<Sulu\Component\Co...ion\ExtensionContainer> of property $extensions.

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...
419 44
    }
420
421
    /**
422
     * {@inheritdoc}
423
     */
424
    public function setExtension($name, $data)
425
    {
426
        $this->extensions[$name] = $data;
427
    }
428
429
    /**
430
     * {@inheritdoc}
431
     */
432 46
    public function getWorkflowStage()
433
    {
434 46
        return $this->workflowStage;
435
    }
436
437
    /**
438
     * {@inheritdoc}
439
     */
440 44
    public function setWorkflowStage($workflowStage)
441
    {
442 44
        $this->workflowStage = $workflowStage;
443 44
    }
444
445
    /**
446
     * {@inheritdoc}
447
     */
448 44
    public function getPublished()
449
    {
450 44
        return $this->published;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->published; (boolean) is incompatible with the return type declared by the interface Sulu\Component\Content\D...eBehavior::getPublished of type null|DateTime.

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...
451
    }
452
453
    /**
454
     * {@inheritdoc}
455
     */
456 44
    public function getAuthored()
457
    {
458 44
        return $this->authored;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->authored; (DateTime) is incompatible with the return type declared by the interface Sulu\Component\Content\D...orBehavior::getAuthored of type string.

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...
459
    }
460
461
    /**
462
     * {@inheritdoc}
463
     */
464 44
    public function setAuthored($authored)
465
    {
466 44
        $this->authored = $authored;
0 ignored issues
show
Documentation Bug introduced by
It seems like $authored of type string is incompatible with the declared type object<DateTime> of property $authored.

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...
467 44
    }
468
469
    /**
470
     * {@inheritdoc}
471
     */
472 44
    public function getAuthor()
473
    {
474 44
        return $this->author;
475
    }
476
477
    /**
478
     * {@inheritdoc}
479
     */
480 44
    public function setAuthor($author)
481
    {
482 44
        $this->author = $author;
483 44
    }
484
485
    /**
486
     * {@inheritdoc}
487
     */
488
    public function getVersions()
489
    {
490
        return $this->versions;
491
    }
492
493
    /**
494
     * {@inheritdoc}
495
     */
496
    public function setVersions($versions)
497
    {
498
        $this->versions = $versions;
499
    }
500
501
    /**
502
     * {@inheritdoc}
503
     */
504 44
    public function getChildren()
505
    {
506 44
        return $this->children;
507
    }
508
509
    /**
510
     * {@inheritdoc}
511
     */
512
    public function getArticleUuid()
513
    {
514
        return $this->getUuid();
515
    }
516
517
    /**
518
     * {@inheritdoc}
519
     */
520
    public function getPageUuid()
521
    {
522
        return $this->getUuid();
523
    }
524
525
    /**
526
     * {@inheritdoc}
527
     */
528 44
    public function getPageNumber()
529
    {
530 44
        return 1;
531
    }
532
533
    /**
534
     * {@inheritdoc}
535
     */
536 44
    public function getPageTitle()
537
    {
538 44
        return $this->pageTitle;
539
    }
540
541
    /**
542
     * Set pageTitle.
543
     *
544
     * @param string $pageTitle
545
     *
546
     * @return $this
547
     */
548 44
    public function setPageTitle($pageTitle)
549
    {
550 44
        $this->pageTitle = $pageTitle;
551
552 44
        return $this;
553
    }
554
555
    /**
556
     * Returns pages.
557
     *
558
     * @return array
559
     */
560
    public function getPages()
561
    {
562
        return $this->pages;
563
    }
564
565
    /**
566
     * Set pages.
567
     *
568
     * @param array $pages
569
     *
570
     * @return $this
571
     */
572 44
    public function setPages($pages)
573
    {
574 44
        $this->pages = $pages;
575
576 44
        return $this;
577
    }
578
}
579