AudioStream::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Video\Info;
6
7
use Psr\Log\LoggerInterface;
8
use Soluble\MediaTools\Video\Info\Util\MetadataTypeSafeReader;
9
10
final class AudioStream implements AudioStreamInterface
11
{
12
    /** @var array<string, mixed> */
13
    private $streamMetadata;
14
15
    /** @var MetadataTypeSafeReader */
16
    private $tsReader;
17
18
    /**
19
     * @param array<string, mixed> $streamMetadata
20
     */
21 4
    public function __construct(array $streamMetadata, ?LoggerInterface $logger = null)
22
    {
23 4
        $this->streamMetadata = $streamMetadata;
24 4
        $this->tsReader       = new MetadataTypeSafeReader($streamMetadata, $logger);
25 4
    }
26
27 1
    public function getIndex(): int
28
    {
29 1
        return $this->tsReader->getKeyIntValue('index');
30
    }
31
32 1
    public function getCodecType(): string
33
    {
34 1
        return $this->tsReader->getKeyStringValue('codec_type');
35
    }
36
37 2
    public function getCodecName(): string
38
    {
39 2
        return $this->tsReader->getKeyStringValue('codec_name');
40
    }
41
42 1
    public function getCodecLongName(): ?string
43
    {
44 1
        return $this->tsReader->getKeyStringOrNullValue('codec_long_name');
45
    }
46
47 1
    public function getCodecTimeBase(): ?string
48
    {
49 1
        return $this->tsReader->getKeyStringOrNullValue('codec_time_base');
50
    }
51
52 1
    public function getCodecTagString(): ?string
53
    {
54 1
        return $this->tsReader->getKeyStringOrNullValue('codec_tag_string');
55
    }
56
57 1
    public function getStartTime(): ?float
58
    {
59 1
        return $this->tsReader->getKeyFloatOrNullValue('start_time');
60
    }
61
62 1
    public function getTimeBase(): ?string
63
    {
64 1
        return $this->tsReader->getKeyStringOrNullValue('time_base');
65
    }
66
67 1
    public function getDurationTs(): ?int
68
    {
69 1
        return $this->tsReader->getKeyIntOrNullValue('duration_ts');
70
    }
71
72 1
    public function getDuration(): float
73
    {
74 1
        return $this->tsReader->getKeyFloatValue('duration');
75
    }
76
77 1
    public function getProfile(): ?string
78
    {
79 1
        return $this->tsReader->getKeyStringOrNullValue('profile');
80
    }
81
82 1
    public function getBitRate(): ?int
83
    {
84 1
        return $this->tsReader->getKeyIntOrNullValue('bit_rate');
85
    }
86
87
    /**
88
     * @return array<string, string>
89
     */
90 1
    public function getTags(): array
91
    {
92 1
        return $this->streamMetadata['tags'] ?? [];
93
    }
94
95
    /**
96
     * Return underlying ffprobe json metadata.
97
     *
98
     * @return array<string, mixed>
99
     */
100 1
    public function getStreamMetadata(): array
101
    {
102 1
        return $this->streamMetadata;
103
    }
104
}
105