Completed
Push — master ( 1ac3df...932ebe )
by
unknown
15s
created

Video::getUploadFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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