1 | <?php |
||
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) |
||
123 | |||
124 | /** |
||
125 | * @return string |
||
126 | */ |
||
127 | public function getId() |
||
131 | |||
132 | /** |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getTitle() |
||
139 | |||
140 | /** |
||
141 | * @param string $title |
||
142 | * |
||
143 | * @return Video |
||
144 | */ |
||
145 | public function setTitle($title) |
||
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getDescription() |
||
159 | |||
160 | /** |
||
161 | * @param string $description |
||
162 | * |
||
163 | * @return Video |
||
164 | */ |
||
165 | public function setDescription($description) |
||
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getThumbnail() |
||
179 | |||
180 | /** |
||
181 | * @param string $thumbnail |
||
182 | * |
||
183 | * @return Video |
||
184 | */ |
||
185 | public function setThumbnail($thumbnail) |
||
191 | |||
192 | /** |
||
193 | * @return int |
||
194 | */ |
||
195 | public function getLength() |
||
199 | |||
200 | /** |
||
201 | * @param int $length |
||
202 | * |
||
203 | * @return Video |
||
204 | */ |
||
205 | public function setLength($length) |
||
211 | |||
212 | /** |
||
213 | * @return \DateTime |
||
214 | */ |
||
215 | public function getCreatedDate() |
||
219 | |||
220 | /** |
||
221 | * @param int $createdDate |
||
222 | * |
||
223 | * @return Video |
||
224 | */ |
||
225 | public function setCreatedDate($createdDate) |
||
231 | |||
232 | /** |
||
233 | * @return int |
||
234 | */ |
||
235 | public function getModifiedDate() |
||
239 | |||
240 | /** |
||
241 | * @param int $modifiedDate |
||
242 | * |
||
243 | * @return Video |
||
244 | */ |
||
245 | public function setModifiedDate($modifiedDate) |
||
251 | |||
252 | /** |
||
253 | * @return int |
||
254 | */ |
||
255 | public function getUploadDate() |
||
259 | |||
260 | /** |
||
261 | * @param int $uploadDate |
||
262 | * |
||
263 | * @return Video |
||
264 | */ |
||
265 | public function setUploadDate($uploadDate) |
||
271 | |||
272 | /** |
||
273 | * @return int |
||
274 | */ |
||
275 | public function getGeneration() |
||
279 | |||
280 | /** |
||
281 | * @param int $generation |
||
282 | * |
||
283 | * @return Video |
||
284 | */ |
||
285 | public function setGeneration($generation) |
||
291 | |||
292 | /** |
||
293 | * @return int |
||
294 | */ |
||
295 | public function getPlays() |
||
299 | |||
300 | /** |
||
301 | * @param int $plays |
||
302 | * |
||
303 | * @return Video |
||
304 | */ |
||
305 | public function setPlays($plays) |
||
311 | |||
312 | /** |
||
313 | * @return int |
||
314 | */ |
||
315 | public function getViews() |
||
319 | |||
320 | /** |
||
321 | * @param int $views |
||
322 | * |
||
323 | * @return Video |
||
324 | */ |
||
325 | public function setViews($views) |
||
331 | |||
332 | /** |
||
333 | * @return bool |
||
334 | */ |
||
335 | public function getAllFormatsAvailable() |
||
339 | |||
340 | /** |
||
341 | * @param bool $allFormatsAvailable |
||
342 | * |
||
343 | * @return Video |
||
344 | */ |
||
345 | public function setAllFormatsAvailable($allFormatsAvailable) |
||
351 | |||
352 | /** |
||
353 | * @return array |
||
354 | */ |
||
355 | public function getCustomMetadata() |
||
359 | |||
360 | /** |
||
361 | * @param array $customMetadata |
||
362 | * |
||
363 | * @return Video |
||
364 | */ |
||
365 | public function setCustomMetadata($customMetadata) |
||
371 | |||
372 | /** |
||
373 | * @return array |
||
374 | */ |
||
375 | public function getKeywords() |
||
379 | |||
380 | /** |
||
381 | * @param array $keywords |
||
382 | * |
||
383 | * @return Video |
||
384 | */ |
||
385 | public function setKeywords($keywords) |
||
391 | |||
392 | /** |
||
393 | * @return array |
||
394 | */ |
||
395 | public function getStills() |
||
399 | |||
400 | /** |
||
401 | * @param array $stills |
||
402 | * |
||
403 | * @return Video |
||
404 | */ |
||
405 | public function setStills($stills) |
||
411 | |||
412 | /** |
||
413 | * @return mixed |
||
414 | */ |
||
415 | public function getPublished() |
||
419 | |||
420 | /** |
||
421 | * @param mixed $published |
||
422 | * |
||
423 | * @return Video |
||
424 | */ |
||
425 | public function setPublished($published) |
||
431 | |||
432 | /** |
||
433 | * {@inheritdoc} |
||
434 | */ |
||
435 | public function isPublished() |
||
439 | |||
440 | /** |
||
441 | * {@inheritdoc} |
||
442 | */ |
||
443 | public function getStatus() |
||
449 | |||
450 | /** |
||
451 | * @return mixed |
||
452 | */ |
||
453 | public function getChannels() |
||
457 | |||
458 | /** |
||
459 | * @param mixed $channels |
||
460 | */ |
||
461 | public function setChannels($channels) |
||
465 | } |
||
466 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.