1 | <?php |
||
14 | class MediaInfoContainer implements \JsonSerializable |
||
15 | { |
||
16 | const GENERAL_CLASS = 'Mhor\MediaInfo\Type\General'; |
||
17 | const AUDIO_CLASS = 'Mhor\MediaInfo\Type\Audio'; |
||
18 | const IMAGE_CLASS = 'Mhor\MediaInfo\Type\Image'; |
||
19 | const VIDEO_CLASS = 'Mhor\MediaInfo\Type\Video'; |
||
20 | const SUBTITLE_CLASS = 'Mhor\MediaInfo\Type\Subtitle'; |
||
21 | const MENU_CLASS = 'Mhor\MediaInfo\Type\Menu'; |
||
22 | const OTHER_CLASS = 'Mhor\MediaInfo\Type\Other'; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $version; |
||
28 | |||
29 | /** |
||
30 | * @var General |
||
31 | */ |
||
32 | private $general; |
||
33 | |||
34 | /** |
||
35 | * @var Audio[] |
||
36 | */ |
||
37 | private $audios = array(); |
||
38 | |||
39 | /** |
||
40 | * @var Video[] |
||
41 | */ |
||
42 | private $videos = array(); |
||
43 | |||
44 | /** |
||
45 | * @var Subtitle[] |
||
46 | */ |
||
47 | private $subtitles = array(); |
||
48 | |||
49 | /** |
||
50 | * @var Image[] |
||
51 | */ |
||
52 | private $images = array(); |
||
53 | |||
54 | /** |
||
55 | * @var Menu[] |
||
56 | */ |
||
57 | private $menus = array(); |
||
58 | |||
59 | /** |
||
60 | * @var Other[] |
||
61 | */ |
||
62 | private $others = array(); |
||
63 | |||
64 | /** |
||
65 | * @return General |
||
66 | */ |
||
67 | public function getGeneral() |
||
71 | |||
72 | /** |
||
73 | * @return Audio[] |
||
74 | */ |
||
75 | public function getAudios() |
||
79 | |||
80 | /** |
||
81 | * @return Image[] |
||
82 | */ |
||
83 | public function getImages() |
||
87 | |||
88 | /** |
||
89 | * @return Menu[] |
||
90 | */ |
||
91 | public function getMenus() |
||
95 | |||
96 | /** |
||
97 | * @return Other[] |
||
98 | */ |
||
99 | public function getOthers() |
||
103 | |||
104 | /** |
||
105 | * @param string $version |
||
106 | */ |
||
107 | public function setVersion($version) |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getVersion() |
||
119 | |||
120 | /** |
||
121 | * @return Video[] |
||
122 | */ |
||
123 | public function getVideos() |
||
127 | |||
128 | /** |
||
129 | * @return Subtitle[] |
||
130 | */ |
||
131 | public function getSubtitles() |
||
135 | |||
136 | /** |
||
137 | * @param General $general |
||
138 | */ |
||
139 | public function setGeneral($general) |
||
143 | |||
144 | /** |
||
145 | * @param AbstractType $trackType |
||
146 | * |
||
147 | * @throws \Exception |
||
148 | */ |
||
149 | public function add(AbstractType $trackType) |
||
150 | { |
||
151 | switch (get_class($trackType)) { |
||
152 | case self::AUDIO_CLASS: |
||
153 | $this->addAudio($trackType); |
||
|
|||
154 | break; |
||
155 | case self::VIDEO_CLASS: |
||
156 | $this->addVideo($trackType); |
||
157 | break; |
||
158 | case self::IMAGE_CLASS: |
||
159 | $this->addImage($trackType); |
||
160 | break; |
||
161 | case self::GENERAL_CLASS: |
||
162 | $this->setGeneral($trackType); |
||
163 | break; |
||
164 | case self::SUBTITLE_CLASS: |
||
165 | $this->addSubtitle($trackType); |
||
166 | break; |
||
167 | case self::MENU_CLASS: |
||
168 | $this->addMenu($trackType); |
||
169 | break; |
||
170 | case self::OTHER_CLASS: |
||
171 | $this->addOther($trackType); |
||
172 | break; |
||
173 | default: |
||
174 | throw new \Exception('Unknown type'); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * @param Audio $audio |
||
180 | */ |
||
181 | private function addAudio(Audio $audio) |
||
185 | |||
186 | /** |
||
187 | * @param Video $video |
||
188 | */ |
||
189 | private function addVideo(Video $video) |
||
193 | |||
194 | /** |
||
195 | * @param Image $image |
||
196 | */ |
||
197 | private function addImage(Image $image) |
||
201 | |||
202 | /** |
||
203 | * @param Subtitle $subtitle |
||
204 | */ |
||
205 | private function addSubtitle(Subtitle $subtitle) |
||
209 | |||
210 | /** |
||
211 | * @param Menu $menu |
||
212 | */ |
||
213 | private function addMenu(Menu $menu) |
||
217 | |||
218 | /** |
||
219 | * @param Other $other |
||
220 | */ |
||
221 | private function addOther(Other $other) |
||
225 | |||
226 | /** |
||
227 | * Convert the object into array |
||
228 | * |
||
229 | * @return array |
||
230 | */ |
||
231 | public function jsonSerialize() |
||
235 | |||
236 | /** |
||
237 | * Dump object to array |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | public function __toArray() |
||
245 | } |
||
246 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.