Test Failed
Pull Request — master (#89)
by
unknown
03:32
created

MediaInfoContainer   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 214
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 89.55%

Importance

Changes 0
Metric Value
wmc 24
lcom 1
cbo 1
dl 0
loc 214
ccs 60
cts 67
cp 0.8955
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getGeneral() 0 4 1
A getAudios() 0 4 1
A getImages() 0 4 1
A getOthers() 0 4 1
A setVersion() 0 4 1
A getVersion() 0 4 1
A getVideos() 0 4 1
A getSubtitles() 0 4 1
A setGeneral() 0 4 1
A addAudio() 0 4 1
A addVideo() 0 4 1
A addImage() 0 4 1
A addSubtitle() 0 4 1
A addOther() 0 4 1
A getMenus() 0 4 1
B add() 0 28 8
A addMenu() 0 4 1
1
<?php
2
3
namespace Mhor\MediaInfo\Container;
4
5
use Mhor\MediaInfo\DumpTrait;
6
use Mhor\MediaInfo\Type\AbstractType;
7
use Mhor\MediaInfo\Type\Audio;
8
use Mhor\MediaInfo\Type\General;
9
use Mhor\MediaInfo\Type\Image;
10
use Mhor\MediaInfo\Type\Menu;
11
use Mhor\MediaInfo\Type\Other;
12
use Mhor\MediaInfo\Type\Subtitle;
13
use Mhor\MediaInfo\Type\Video;
14
15
class MediaInfoContainer implements \JsonSerializable
16
{
17
    use DumpTrait;
18
19
    const GENERAL_CLASS = 'Mhor\MediaInfo\Type\General';
20
    const AUDIO_CLASS = 'Mhor\MediaInfo\Type\Audio';
21
    const IMAGE_CLASS = 'Mhor\MediaInfo\Type\Image';
22
    const VIDEO_CLASS = 'Mhor\MediaInfo\Type\Video';
23
    const SUBTITLE_CLASS = 'Mhor\MediaInfo\Type\Subtitle';
24
    const MENU_CLASS = 'Mhor\MediaInfo\Type\Menu';
25
    const OTHER_CLASS = 'Mhor\MediaInfo\Type\Other';
26
27
    /**
28
     * @var string
29
     */
30
    private $version;
31
32
    /**
33
     * @var General
34
     */
35
    private $general;
36
37
    /**
38
     * @var Audio[]
39
     */
40
    private $audios = [];
41
42
    /**
43
     * @var Video[]
44
     */
45
    private $videos = [];
46
47
    /**
48
     * @var Subtitle[]
49
     */
50
    private $subtitles = [];
51
52
    /**
53
     * @var Image[]
54
     */
55
    private $images = [];
56
57
    /**
58
     * @var Menu[]
59
     */
60
    private $menus = [];
61
62
    /**
63
     * @var Other[]
64
     */
65
    private $others = [];
66
67
    /**
68
     * @return General
69
     */
70 4
    public function getGeneral()
71
    {
72 4
        return $this->general;
73
    }
74
75
    /**
76
     * @return Audio[]
77
     */
78 5
    public function getAudios()
79
    {
80 5
        return $this->audios;
81
    }
82
83
    /**
84
     * @return Image[]
85
     */
86 1
    public function getImages()
87
    {
88 1
        return $this->images;
89
    }
90
91
    /**
92
     * @return Menu[]
93
     */
94
    public function getMenus()
95
    {
96
        return $this->menus;
97
    }
98
99
    /**
100
     * @return Other[]
101
     */
102 1
    public function getOthers()
103
    {
104 1
        return $this->others;
105
    }
106
107
    /**
108
     * @param string $version
109
     */
110 5
    public function setVersion($version)
111
    {
112 5
        $this->version = $version;
113 5
    }
114
115
    /**
116
     * @return string
117
     */
118 1
    public function getVersion()
119
    {
120 1
        return $this->version;
121
    }
122
123
    /**
124
     * @return Video[]
125
     */
126 1
    public function getVideos()
127
    {
128 1
        return $this->videos;
129
    }
130
131
    /**
132
     * @return Subtitle[]
133
     */
134 1
    public function getSubtitles()
135
    {
136 1
        return $this->subtitles;
137
    }
138
139
    /**
140
     * @param General $general
141
     */
142 7
    public function setGeneral($general)
143
    {
144 7
        $this->general = $general;
145 7
    }
146
147
    /**
148
     * @param AbstractType $trackType
149
     *
150
     * @throws \Exception
151
     */
152 11
    public function add(AbstractType $trackType)
153
    {
154 11
        switch (get_class($trackType)) {
155 11
            case self::AUDIO_CLASS:
156 10
                $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...
157 10
                break;
158 8
            case self::VIDEO_CLASS:
159 1
                $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...
160 1
                break;
161 8
            case self::IMAGE_CLASS:
162 1
                $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...
163 1
                break;
164 8
            case self::GENERAL_CLASS:
165 7
                $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...
166 7
                break;
167 2
            case self::SUBTITLE_CLASS:
168 1
                $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...
169 1
                break;
170 2
            case self::MENU_CLASS:
171
                $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...
172
                break;
173 2
            case self::OTHER_CLASS:
174 1
                $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...
175 1
                break;
176 1
            default:
177 1
                throw new \Exception('Unknown type');
178 11
        }
179 10
    }
180
181
    /**
182
     * @param Audio $audio
183
     */
184 10
    private function addAudio(Audio $audio)
185
    {
186 10
        $this->audios[] = $audio;
187 10
    }
188
189
    /**
190
     * @param Video $video
191
     */
192 1
    private function addVideo(Video $video)
193
    {
194 1
        $this->videos[] = $video;
195 1
    }
196
197
    /**
198
     * @param Image $image
199
     */
200 1
    private function addImage(Image $image)
201
    {
202 1
        $this->images[] = $image;
203 1
    }
204
205
    /**
206
     * @param Subtitle $subtitle
207
     */
208 1
    private function addSubtitle(Subtitle $subtitle)
209
    {
210 1
        $this->subtitles[] = $subtitle;
211 1
    }
212
213
    /**
214
     * @param Menu $menu
215
     */
216
    private function addMenu(Menu $menu)
217
    {
218
        $this->menus[] = $menu;
219
    }
220
221
    /**
222
     * @param Other $other
223
     */
224 1
    private function addOther(Other $other)
225
    {
226 1
        $this->others[] = $other;
227 1
    }
228
}
229