Passed
Push — master ( 1fcfe0...134786 )
by Sébastien
02:28
created

VideoStream   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Test Coverage

Coverage 96.55%

Importance

Changes 0
Metric Value
wmc 28
eloc 33
dl 0
loc 149
c 0
b 0
f 0
ccs 56
cts 58
cp 0.9655
rs 10

27 Methods

Rating   Name   Duplication   Size   Complexity  
A getCodecName() 0 3 1
A getCodecTimeBase() 0 3 1
A getCodedWidth() 0 3 1
A getDisplayAspectRatio() 0 3 1
A __construct() 0 4 1
A getIndex() 0 3 1
A getWidth() 0 3 1
A getRFrameRate() 0 3 1
A getHeight() 0 3 1
A getCodecLongName() 0 3 1
A getDurationTs() 0 3 1
A getCodedHeight() 0 3 1
A getCodecTagString() 0 3 1
A getDuration() 0 3 1
A getPixFmt() 0 3 1
A getAvgFrameRate() 0 3 1
A getSampleAspectRatio() 0 3 1
A getTimeBase() 0 3 1
A getBitRate() 0 3 1
A getColorTransfer() 0 3 1
A getProfile() 0 3 1
A getLevel() 0 3 1
A isAvc() 0 7 2
A getNbFrames() 0 3 1
A getTags() 0 3 1
A getColorSpace() 0 3 1
A getColorRange() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Video\Info;
6
7
use Soluble\MediaTools\Video\Info\Util\MetadataTypeSafeReader;
8
9
class VideoStream
10
{
11
    /** @var array<string, mixed> */
12
    private $streamMetadata;
13
14
    /** @var MetadataTypeSafeReader */
15
    private $tsReader;
16
17 8
    public function __construct(array $streamMetadata)
18
    {
19 8
        $this->streamMetadata = $streamMetadata;
20 8
        $this->tsReader       = new MetadataTypeSafeReader($streamMetadata);
21 8
    }
22
23 2
    public function getIndex(): int
24
    {
25 2
        return $this->tsReader->getKeyIntValue('index');
26
    }
27
28 1
    public function getCodecName(): string
29
    {
30 1
        return $this->streamMetadata['codec_name'];
31
    }
32
33 1
    public function getCodecLongName(): ?string
34
    {
35 1
        return $this->tsReader->getKeyStringOrNullValue('codec_long_name');
36
    }
37
38 1
    public function getCodecTimeBase(): ?string
39
    {
40 1
        return $this->tsReader->getKeyStringOrNullValue('codec_time_base');
41
    }
42
43 1
    public function getCodecTagString(): ?string
44
    {
45 1
        return $this->tsReader->getKeyStringOrNullValue('codec_tag_string');
46
    }
47
48 3
    public function getWidth(): int
49
    {
50 3
        return $this->tsReader->getKeyIntValue('width');
51
    }
52
53 3
    public function getHeight(): int
54
    {
55 3
        return $this->tsReader->getKeyIntValue('height');
56
    }
57
58 1
    public function getCodedWidth(): ?int
59
    {
60 1
        return $this->tsReader->getKeyIntOrNullValue('coded_width');
61
    }
62
63 1
    public function getCodedHeight(): ?int
64
    {
65 1
        return $this->tsReader->getKeyIntOrNullValue('coded_height');
66
    }
67
68 1
    public function getSampleAspectRatio(): ?string
69
    {
70 1
        return $this->tsReader->getKeyStringOrNullValue('sample_aspect_ratio');
71
    }
72
73 1
    public function getDisplayAspectRatio(): string
74
    {
75 1
        return $this->streamMetadata['display_aspect_ratio'];
76
    }
77
78 3
    public function getPixFmt(): ?string
79
    {
80 3
        return $this->tsReader->getKeyStringOrNullValue('pix_fmt');
81
    }
82
83 1
    public function getAvgFrameRate(): string
84
    {
85 1
        return $this->streamMetadata['avg_frame_rate'];
86
    }
87
88 1
    public function getRFrameRate(): ?string
89
    {
90 1
        return $this->tsReader->getKeyStringOrNullValue('r_frame_rate');
91
    }
92
93 1
    public function getTimeBase(): ?string
94
    {
95 1
        return $this->tsReader->getKeyStringOrNullValue('time_base');
96
    }
97
98 1
    public function getDurationTs(): ?int
99
    {
100 1
        return $this->tsReader->getKeyIntOrNullValue('duration_ts');
101
    }
102
103 1
    public function getDuration(): float
104
    {
105 1
        return $this->tsReader->getKeyFloatValue('duration');
106
    }
107
108
    public function getProfile(): ?string
109
    {
110
        return $this->tsReader->getKeyStringOrNullValue('profile');
111
    }
112
113 3
    public function getBitRate(): ?int
114
    {
115 3
        return $this->tsReader->getKeyIntOrNullValue('bit_rate');
116
    }
117
118 1
    public function getNbFrames(): int
119
    {
120 1
        return $this->tsReader->getKeyIntValue('nb_frames');
121
    }
122
123 2
    public function isAvc(): ?bool
124
    {
125 2
        if (!isset($this->streamMetadata['is_avc'])) {
126 1
            return null;
127
        }
128
129 1
        return $this->streamMetadata['is_avc'] === 'true';
130
    }
131
132 1
    public function getLevel(): ?int
133
    {
134 1
        return $this->tsReader->getKeyIntOrNullValue('level');
135
    }
136
137 1
    public function getColorRange(): ?string
138
    {
139 1
        return $this->tsReader->getKeyStringOrNullValue('color_range');
140
    }
141
142 1
    public function getColorSpace(): ?string
143
    {
144 1
        return $this->tsReader->getKeyStringOrNullValue('color_space');
145
    }
146
147 1
    public function getColorTransfer(): ?string
148
    {
149 1
        return $this->tsReader->getKeyStringOrNullValue('color_transfer');
150
    }
151
152
    /**
153
     * @return array<string, string>
154
     */
155 1
    public function getTags(): array
156
    {
157 1
        return $this->streamMetadata['tags'] ?? [];
158
    }
159
}
160