Completed
Push — master ( 7edba9...54f17b )
by Maxime
01:54
created

MediaInfoContainer::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Mhor\MediaInfo\Container;
4
5
use Mhor\MediaInfo\Type\AbstractType;
6
use Mhor\MediaInfo\Type\Audio;
7
use Mhor\MediaInfo\Type\General;
8
use Mhor\MediaInfo\Type\Image;
9
use Mhor\MediaInfo\Type\Menu;
10
use Mhor\MediaInfo\Type\Other;
11
use Mhor\MediaInfo\Type\Subtitle;
12
use Mhor\MediaInfo\Type\Video;
13
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()
68
    {
69
        return $this->general;
70
    }
71
72
    /**
73
     * @return Audio[]
74
     */
75
    public function getAudios()
76
    {
77
        return $this->audios;
78
    }
79
80
    /**
81
     * @return Image[]
82
     */
83
    public function getImages()
84
    {
85
        return $this->images;
86
    }
87
88
    /**
89
     * @return Menu[]
90
     */
91
    public function getMenus()
92
    {
93
        return $this->menus;
94
    }
95
96
    /**
97
     * @return Other[]
98
     */
99
    public function getOthers()
100
    {
101
        return $this->others;
102
    }
103
104
    /**
105
     * @param string $version
106
     */
107
    public function setVersion($version)
108
    {
109
        $this->version = $version;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getVersion()
116
    {
117
        return $this->version;
118
    }
119
120
    /**
121
     * @return Video[]
122
     */
123
    public function getVideos()
124
    {
125
        return $this->videos;
126
    }
127
128
    /**
129
     * @return Subtitle[]
130
     */
131
    public function getSubtitles()
132
    {
133
        return $this->subtitles;
134
    }
135
136
    /**
137
     * @param General $general
138
     */
139
    public function setGeneral($general)
140
    {
141
        $this->general = $general;
142
    }
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);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\Audio>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
154
                break;
155
            case self::VIDEO_CLASS:
156
                $this->addVideo($trackType);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\Video>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
157
                break;
158
            case self::IMAGE_CLASS:
159
                $this->addImage($trackType);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\Image>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
160
                break;
161
            case self::GENERAL_CLASS:
162
                $this->setGeneral($trackType);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\General>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
163
                break;
164
            case self::SUBTITLE_CLASS:
165
                $this->addSubtitle($trackType);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\Subtitle>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
166
                break;
167
            case self::MENU_CLASS:
168
                $this->addMenu($trackType);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\Menu>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
169
                break;
170
            case self::OTHER_CLASS:
171
                $this->addOther($trackType);
0 ignored issues
show
Compatibility introduced by
$trackType of type object<Mhor\MediaInfo\Type\AbstractType> is not a sub-type of object<Mhor\MediaInfo\Type\Other>. It seems like you assume a child class of the class Mhor\MediaInfo\Type\AbstractType to be always present.

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.

Loading history...
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)
182
    {
183
        $this->audios[] = $audio;
184
    }
185
186
    /**
187
     * @param Video $video
188
     */
189
    private function addVideo(Video $video)
190
    {
191
        $this->videos[] = $video;
192
    }
193
194
    /**
195
     * @param Image $image
196
     */
197
    private function addImage(Image $image)
198
    {
199
        $this->images[] = $image;
200
    }
201
202
    /**
203
     * @param Subtitle $subtitle
204
     */
205
    private function addSubtitle(Subtitle $subtitle)
206
    {
207
        $this->subtitles[] = $subtitle;
208
    }
209
210
    /**
211
     * @param Menu $menu
212
     */
213
    private function addMenu(Menu $menu)
214
    {
215
        $this->menus[] = $menu;
216
    }
217
218
    /**
219
     * @param Other $other
220
     */
221
    private function addOther(Other $other)
222
    {
223
        $this->others[] = $other;
224
    }
225
    
226
    /**
227
     * Convert the object into array
228
     *
229
     * @return array
230
     */
231
    public function jsonSerialize()
232
    {
233
        return get_object_vars($this);
234
    }
235
    
236
    /**
237
     * Dump object to array
238
     *
239
     * @return array
240
     */
241
    public function __toArray()
242
    {
243
        return $this->jsonSerialize();
244
    }
245
}
246