Completed
Push — master ( c9acbc...0a01e1 )
by Ruben
05:13
created

Video::getStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
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
        $date = new \DateTime();
218
        $date->setTimestamp($this->createdDate);
219
220
        return $date;
221
    }
222
223
    /**
224
     * @param int $createdDate
225
     *
226
     * @return Video
227
     */
228
    public function setCreatedDate($createdDate)
229
    {
230
        $this->createdDate = $createdDate;
231
232
        return $this;
233
    }
234
235
    /**
236
     * @return int
237
     */
238
    public function getModifiedDate()
239
    {
240
        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...
241
    }
242
243
    /**
244
     * @param int $modifiedDate
245
     *
246
     * @return Video
247
     */
248
    public function setModifiedDate($modifiedDate)
249
    {
250
        $this->modifiedDate = $modifiedDate;
251
252
        return $this;
253
    }
254
255
    /**
256
     * @return int
257
     */
258
    public function getUploadDate()
259
    {
260
        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...
261
    }
262
263
    /**
264
     * @param int $uploadDate
265
     *
266
     * @return Video
267
     */
268
    public function setUploadDate($uploadDate)
269
    {
270
        $this->uploadDate = $uploadDate;
271
272
        return $this;
273
    }
274
275
    /**
276
     * @return int
277
     */
278
    public function getGeneration()
279
    {
280
        return $this->generation;
281
    }
282
283
    /**
284
     * @param int $generation
285
     *
286
     * @return Video
287
     */
288
    public function setGeneration($generation)
289
    {
290
        $this->generation = $generation;
291
292
        return $this;
293
    }
294
295
    /**
296
     * @return int
297
     */
298
    public function getPlays()
299
    {
300
        return $this->plays;
301
    }
302
303
    /**
304
     * @param int $plays
305
     *
306
     * @return Video
307
     */
308
    public function setPlays($plays)
309
    {
310
        $this->plays = $plays;
311
312
        return $this;
313
    }
314
315
    /**
316
     * @return int
317
     */
318
    public function getViews()
319
    {
320
        return $this->views;
321
    }
322
323
    /**
324
     * @param int $views
325
     *
326
     * @return Video
327
     */
328
    public function setViews($views)
329
    {
330
        $this->views = $views;
331
332
        return $this;
333
    }
334
335
    /**
336
     * @return bool
337
     */
338
    public function getAllFormatsAvailable()
339
    {
340
        return $this->allFormatsAvailable;
341
    }
342
343
    /**
344
     * @param bool $allFormatsAvailable
345
     *
346
     * @return Video
347
     */
348
    public function setAllFormatsAvailable($allFormatsAvailable)
349
    {
350
        $this->allFormatsAvailable = $allFormatsAvailable;
351
352
        return $this;
353
    }
354
355
    /**
356
     * @return array
357
     */
358
    public function getCustomMetadata()
359
    {
360
        return $this->customMetadata;
361
    }
362
363
    /**
364
     * @param array $customMetadata
365
     *
366
     * @return Video
367
     */
368
    public function setCustomMetadata($customMetadata)
369
    {
370
        $this->customMetadata = $customMetadata;
371
372
        return $this;
373
    }
374
375
    /**
376
     * @return array
377
     */
378
    public function getKeywords()
379
    {
380
        return $this->keywords;
381
    }
382
383
    /**
384
     * @param array $keywords
385
     *
386
     * @return Video
387
     */
388
    public function setKeywords($keywords)
389
    {
390
        $this->keywords = $keywords;
391
392
        return $this;
393
    }
394
395
    /**
396
     * @return array
397
     */
398
    public function getStills()
399
    {
400
        return $this->stills;
401
    }
402
403
    /**
404
     * @param array $stills
405
     *
406
     * @return Video
407
     */
408
    public function setStills($stills)
409
    {
410
        $this->stills = $stills;
411
412
        return $this;
413
    }
414
415
    /**
416
     * @return mixed
417
     */
418
    public function getPublished()
419
    {
420
        return $this->published;
421
    }
422
423
    /**
424
     * @param mixed $published
425
     *
426
     * @return Video
427
     */
428
    public function setPublished($published)
429
    {
430
        $this->published = $published;
431
432
        return $this;
433
    }
434
435
    /**
436
     * {@inheritdoc}
437
     */
438
    public function isPublished()
439
    {
440
        return $this->getPublished();
441
    }
442
443
    /**
444
     * {@inheritdoc}
445
     */
446
    public function getStatus()
447
    {
448
        return $this->isPublished()
449
            ? VideoInterface::STATUS_PUBLISHED
450
            : VideoInterface::STATUS_NOT_PUBLISHED;
451
    }
452
453
    /**
454
     * @return mixed
455
     */
456
    public function getChannels()
457
    {
458
        return $this->channels;
459
    }
460
461
    /**
462
     * @param mixed $channels
463
     */
464
    public function setChannels($channels)
465
    {
466
        $this->channels = $channels;
467
    }
468
}
469