Passed
Push — master ( 6b3f0f...f4298f )
by
unknown
47s queued 10s
created

Video::setModifiedDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
     * @Type("string")
114
     * @SerializedName("uploadFileName")
115
     */
116
    private $uploadFileName;
117
118
    /**
119
     * @Type("boolean")
120
     */
121
    private $downloadable;
122
123
    /**
124
     * @param string $id
125
     *
126
     * @return Video
127
     */
128
    public function setId($id)
129
    {
130
        $this->id = $id;
131
132
        return $this;
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    public function getId()
139
    {
140
        return $this->id;
141
    }
142
143
    /**
144
     * @return string
145
     */
146
    public function getTitle()
147
    {
148
        return $this->title;
149
    }
150
151
    /**
152
     * @param string $title
153
     *
154
     * @return Video
155
     */
156
    public function setTitle($title)
157
    {
158
        $this->title = $title;
159
160
        return $this;
161
    }
162
163
    /**
164
     * @return string
165
     */
166
    public function getDescription()
167
    {
168
        return $this->description;
169
    }
170
171
    /**
172
     * @param string $description
173
     *
174
     * @return Video
175
     */
176
    public function setDescription($description)
177
    {
178
        $this->description = $description;
179
180
        return $this;
181
    }
182
183
    /**
184
     * @return string
185
     */
186
    public function getThumbnail()
187
    {
188
        return $this->thumbnail;
189
    }
190
191
    /**
192
     * @param string $thumbnail
193
     *
194
     * @return Video
195
     */
196
    public function setThumbnail($thumbnail)
197
    {
198
        $this->thumbnail = $thumbnail;
199
200
        return $this;
201
    }
202
203
    /**
204
     * @return int
205
     */
206
    public function getLength()
207
    {
208
        return $this->length;
209
    }
210
211
    /**
212
     * @param int $length
213
     *
214
     * @return Video
215
     */
216
    public function setLength($length)
217
    {
218
        $this->length = $length;
219
220
        return $this;
221
    }
222
223
    /**
224
     * @return \DateTime
225
     */
226
    public function getCreatedDate()
227
    {
228
        $date = new \DateTime();
229
        $date->setTimestamp(substr($this->createdDate, 0, 10));
230
231
        return $date;
232
    }
233
234
    /**
235
     * @param int $createdDate
236
     *
237
     * @return Video
238
     */
239
    public function setCreatedDate($createdDate)
240
    {
241
        $this->createdDate = $createdDate;
242
243
        return $this;
244
    }
245
246
    /**
247
     * @return int
248
     */
249
    public function getModifiedDate()
250
    {
251
        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...
252
    }
253
254
    /**
255
     * @param int $modifiedDate
256
     *
257
     * @return Video
258
     */
259
    public function setModifiedDate($modifiedDate)
260
    {
261
        $this->modifiedDate = $modifiedDate;
262
263
        return $this;
264
    }
265
266
    /**
267
     * @return int
268
     */
269
    public function getUploadDate()
270
    {
271
        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...
272
    }
273
274
    /**
275
     * @param int $uploadDate
276
     *
277
     * @return Video
278
     */
279
    public function setUploadDate($uploadDate)
280
    {
281
        $this->uploadDate = $uploadDate;
282
283
        return $this;
284
    }
285
286
    /**
287
     * @return int
288
     */
289
    public function getGeneration()
290
    {
291
        return $this->generation;
292
    }
293
294
    /**
295
     * @param int $generation
296
     *
297
     * @return Video
298
     */
299
    public function setGeneration($generation)
300
    {
301
        $this->generation = $generation;
302
303
        return $this;
304
    }
305
306
    /**
307
     * @return int
308
     */
309
    public function getPlays()
310
    {
311
        return $this->plays;
312
    }
313
314
    /**
315
     * @param int $plays
316
     *
317
     * @return Video
318
     */
319
    public function setPlays($plays)
320
    {
321
        $this->plays = $plays;
322
323
        return $this;
324
    }
325
326
    /**
327
     * @return int
328
     */
329
    public function getViews()
330
    {
331
        return $this->views;
332
    }
333
334
    /**
335
     * @param int $views
336
     *
337
     * @return Video
338
     */
339
    public function setViews($views)
340
    {
341
        $this->views = $views;
342
343
        return $this;
344
    }
345
346
    /**
347
     * @return bool
348
     */
349
    public function getAllFormatsAvailable()
350
    {
351
        return $this->allFormatsAvailable;
352
    }
353
354
    /**
355
     * @param bool $allFormatsAvailable
356
     *
357
     * @return Video
358
     */
359
    public function setAllFormatsAvailable($allFormatsAvailable)
360
    {
361
        $this->allFormatsAvailable = $allFormatsAvailable;
362
363
        return $this;
364
    }
365
366
    /**
367
     * @return array
368
     */
369
    public function getCustomMetadata()
370
    {
371
        return $this->customMetadata;
372
    }
373
374
    /**
375
     * @param array $customMetadata
376
     *
377
     * @return Video
378
     */
379
    public function setCustomMetadata($customMetadata)
380
    {
381
        $this->customMetadata = $customMetadata;
382
383
        return $this;
384
    }
385
386
    /**
387
     * @return array
388
     */
389
    public function getKeywords()
390
    {
391
        return $this->keywords;
392
    }
393
394
    /**
395
     * @param array $keywords
396
     *
397
     * @return Video
398
     */
399
    public function setKeywords($keywords)
400
    {
401
        $this->keywords = $keywords;
402
403
        return $this;
404
    }
405
406
    /**
407
     * @return array
408
     */
409
    public function getStills()
410
    {
411
        //sorting preview's images from smallest to biggest
412
        usort($this->stills, function (array $item1, array $item2) {
413
            if (isset($item1['dimension']['height'], $item2['dimension']['height']) && $item1['dimension']['height'] != $item2['dimension']['height']) {
414
                return ($item1['dimension']['height'] > $item2['dimension']['height']) ? 1 : -1;
415
            }
416
417
            return 0;
418
        });
419
420
        return $this->stills;
421
    }
422
423
    /**
424
     * @param array $stills
425
     *
426
     * @return Video
427
     */
428
    public function setStills($stills)
429
    {
430
        $this->stills = $stills;
431
432
        return $this;
433
    }
434
435
    /**
436
     * @return mixed
437
     */
438
    public function getPublished()
439
    {
440
        return $this->published;
441
    }
442
443
    /**
444
     * @param mixed $published
445
     *
446
     * @return Video
447
     */
448
    public function setPublished($published)
449
    {
450
        $this->published = $published;
451
452
        return $this;
453
    }
454
455
    /**
456
     * {@inheritdoc}
457
     */
458
    public function isPublished()
459
    {
460
        return $this->getPublished();
461
    }
462
463
    /**
464
     * @return mixed
465
     */
466
    public function getDownloadable()
467
    {
468
        return $this->downloadable;
469
    }
470
471
    /**
472
     * @param mixed $downloadable
473
     *
474
     * @return Video
475
     */
476
    public function setDownloadable($downloadable)
477
    {
478
        $this->downloadable = $downloadable;
479
480
        return $this;
481
    }
482
483
    /**
484
     * {@inheritdoc}
485
     */
486
    public function isDownloadable()
487
    {
488
        return $this->getDownloadable();
489
    }
490
491
    /**
492
     * {@inheritdoc}
493
     */
494
    public function getStatus()
495
    {
496
        return $this->isPublished()
497
            ? VideoInterface::STATUS_PUBLISHED
498
            : VideoInterface::STATUS_NOT_PUBLISHED;
499
    }
500
501
    /**
502
     * @return mixed
503
     */
504
    public function getChannels()
505
    {
506
        return $this->channels;
507
    }
508
509
    /**
510
     * @param mixed $channels
511
     */
512
    public function setChannels($channels)
513
    {
514
        $this->channels = $channels;
515
    }
516
517
    /**
518
     * @return string
519
     */
520
    public function getUploadFileName()
521
    {
522
        return $this->uploadFileName;
523
    }
524
525
    /**
526
     * @param mixed $uploadFileName
527
     *
528
     * @return Video
529
     */
530
    public function setUploadFileName($uploadFileName)
531
    {
532
        $this->uploadFileName = $uploadFileName;
533
534
        return $this;
535
    }
536
}
537