Passed
Pull Request — master (#18)
by Ruben
03:40
created

Video::isPublished()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace MovingImage\Client\VMPro\Entity;
4
5
use JMS\Serializer\Annotation\Type;
6
use JMS\Serializer\Annotation\SerializedName;
7
use MovingImage\Meta\Interfaces\VideoInterface;
8
9
/**
10
 * Class Video.
11
 *
12
 * @author Omid Rad <[email protected]>
13
 */
14
class Video implements VideoInterface
15
{
16
    /**
17
     * @Type("string")
18
     */
19
    private $id;
20
21
    /**
22
     * @Type("string")
23
     */
24
    private $title;
25
26
    /**
27
     * @Type("string")
28
     */
29
    private $description;
30
31
    /**
32
     * @Type("string")
33
     */
34
    private $thumbnail;
35
36
    /**
37
     * @Type("integer")
38
     */
39
    private $length;
40
41
    /**
42
     * @Type("integer")
43
     * @SerializedName("createdDate")
44
     */
45
    private $createdDate;
46
47
    /**
48
     * @Type("integer")
49
     * @SerializedName("modifiedDate")
50
     */
51
    private $modifiedDate;
52
53
    /**
54
     * @Type("integer")
55
     * @SerializedName("uploadDate")
56
     */
57
    private $uploadDate;
58
59
    /**
60
     * @Type("integer")
61
     */
62
    private $generation;
63
64
    /**
65
     * @Type("integer")
66
     */
67
    private $plays;
68
69
    /**
70
     * @Type("integer")
71
     */
72
    private $views;
73
74
    /**
75
     * @Type("boolean")
76
     * @SerializedName("allFormatsAvailable")
77
     */
78
    private $allFormatsAvailable;
79
80
    /**
81
     * @TODO replace it with array collection
82
     *
83
     * @Type("array")
84
     * @SerializedName("customMetadata")
85
     */
86
    private $customMetadata;
87
88
    /**
89
     * @TODO replace it with array collection
90
     *
91
     * @Type("array")
92
     */
93
    private $keywords;
94
95
    /**
96
     * @TODO replace it with array collection
97
     *
98
     * @Type("array")
99
     */
100
    private $stills;
101
102
    /**
103
     * @Type("boolean")
104
     */
105
    private $published;
106
107
    /**
108
     * @Type("array")
109
     */
110
    private $channels;
111
112
    /**
113
     * @param string $id
114
     *
115
     * @return Video
116
     */
117
    public function setId($id)
118
    {
119
        $this->id = $id;
120
121
        return $this;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getId()
128
    {
129
        return $this->id;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getTitle()
136
    {
137
        return $this->title;
138
    }
139
140
    /**
141
     * @param string $title
142
     *
143
     * @return Video
144
     */
145
    public function setTitle($title)
146
    {
147
        $this->title = $title;
148
149
        return $this;
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getDescription()
156
    {
157
        return $this->description;
158
    }
159
160
    /**
161
     * @param string $description
162
     *
163
     * @return Video
164
     */
165
    public function setDescription($description)
166
    {
167
        $this->description = $description;
168
169
        return $this;
170
    }
171
172
    /**
173
     * @return string
174
     */
175
    public function getThumbnail()
176
    {
177
        return $this->thumbnail;
178
    }
179
180
    /**
181
     * @param string $thumbnail
182
     *
183
     * @return Video
184
     */
185
    public function setThumbnail($thumbnail)
186
    {
187
        $this->thumbnail = $thumbnail;
188
189
        return $this;
190
    }
191
192
    /**
193
     * @return int
194
     */
195
    public function getLength()
196
    {
197
        return $this->length;
198
    }
199
200
    /**
201
     * @param int $length
202
     *
203
     * @return Video
204
     */
205
    public function setLength($length)
206
    {
207
        $this->length = $length;
208
209
        return $this;
210
    }
211
212
    /**
213
     * @return \DateTime
214
     */
215
    public function getCreatedDate()
216
    {
217
        return new \DateTime($this->createdDate);
218
    }
219
220
    /**
221
     * @param int $createdDate
222
     *
223
     * @return Video
224
     */
225
    public function setCreatedDate($createdDate)
226
    {
227
        $this->createdDate = $createdDate;
228
229
        return $this;
230
    }
231
232
    /**
233
     * @return int
234
     */
235
    public function getModifiedDate()
236
    {
237
        return $this->modifiedDate;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->modifiedDate; (integer) is incompatible with the return type declared by the interface MovingImage\Meta\Interfa...erface::getModifiedDate of type 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...
238
    }
239
240
    /**
241
     * @param int $modifiedDate
242
     *
243
     * @return Video
244
     */
245
    public function setModifiedDate($modifiedDate)
246
    {
247
        $this->modifiedDate = $modifiedDate;
248
249
        return $this;
250
    }
251
252
    /**
253
     * @return int
254
     */
255
    public function getUploadDate()
256
    {
257
        return $this->uploadDate;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->uploadDate; (integer) is incompatible with the return type declared by the interface MovingImage\Meta\Interfa...nterface::getUploadDate of type 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...
258
    }
259
260
    /**
261
     * @param int $uploadDate
262
     *
263
     * @return Video
264
     */
265
    public function setUploadDate($uploadDate)
266
    {
267
        $this->uploadDate = $uploadDate;
268
269
        return $this;
270
    }
271
272
    /**
273
     * @return int
274
     */
275
    public function getGeneration()
276
    {
277
        return $this->generation;
278
    }
279
280
    /**
281
     * @param int $generation
282
     *
283
     * @return Video
284
     */
285
    public function setGeneration($generation)
286
    {
287
        $this->generation = $generation;
288
289
        return $this;
290
    }
291
292
    /**
293
     * @return int
294
     */
295
    public function getPlays()
296
    {
297
        return $this->plays;
298
    }
299
300
    /**
301
     * @param int $plays
302
     *
303
     * @return Video
304
     */
305
    public function setPlays($plays)
306
    {
307
        $this->plays = $plays;
308
309
        return $this;
310
    }
311
312
    /**
313
     * @return int
314
     */
315
    public function getViews()
316
    {
317
        return $this->views;
318
    }
319
320
    /**
321
     * @param int $views
322
     *
323
     * @return Video
324
     */
325
    public function setViews($views)
326
    {
327
        $this->views = $views;
328
329
        return $this;
330
    }
331
332
    /**
333
     * @return bool
334
     */
335
    public function getAllFormatsAvailable()
336
    {
337
        return $this->allFormatsAvailable;
338
    }
339
340
    /**
341
     * @param bool $allFormatsAvailable
342
     *
343
     * @return Video
344
     */
345
    public function setAllFormatsAvailable($allFormatsAvailable)
346
    {
347
        $this->allFormatsAvailable = $allFormatsAvailable;
348
349
        return $this;
350
    }
351
352
    /**
353
     * @return array
354
     */
355
    public function getCustomMetadata()
356
    {
357
        return $this->customMetadata;
358
    }
359
360
    /**
361
     * @param array $customMetadata
362
     *
363
     * @return Video
364
     */
365
    public function setCustomMetadata($customMetadata)
366
    {
367
        $this->customMetadata = $customMetadata;
368
369
        return $this;
370
    }
371
372
    /**
373
     * @return array
374
     */
375
    public function getKeywords()
376
    {
377
        return $this->keywords;
378
    }
379
380
    /**
381
     * @param array $keywords
382
     *
383
     * @return Video
384
     */
385
    public function setKeywords($keywords)
386
    {
387
        $this->keywords = $keywords;
388
389
        return $this;
390
    }
391
392
    /**
393
     * @return array
394
     */
395
    public function getStills()
396
    {
397
        return $this->stills;
398
    }
399
400
    /**
401
     * @param array $stills
402
     *
403
     * @return Video
404
     */
405
    public function setStills($stills)
406
    {
407
        $this->stills = $stills;
408
409
        return $this;
410
    }
411
412
    /**
413
     * @return mixed
414
     */
415
    public function getPublished()
416
    {
417
        return $this->published;
418
    }
419
420
    /**
421
     * @param mixed $published
422
     *
423
     * @return Video
424
     */
425
    public function setPublished($published)
426
    {
427
        $this->published = $published;
428
429
        return $this;
430
    }
431
432
    /**
433
     * {@inheritdoc}
434
     */
435
    public function isPublished()
436
    {
437
        return $this->getPublished();
438
    }
439
440
    /**
441
     * {@inheritdoc}
442
     */
443
    public function getStatus()
444
    {
445
        return $this->isPublished()
446
            ? VideoInterface::STATUS_PUBLISHED
447
            : VideoInterface::STATUS_NOT_PUBLISHED;
448
    }
449
450
    /**
451
     * @return mixed
452
     */
453
    public function getChannels()
454
    {
455
        return $this->channels;
456
    }
457
458
    /**
459
     * @param mixed $channels
460
     */
461
    public function setChannels($channels)
462
    {
463
        $this->channels = $channels;
464
    }
465
}
466