StreamInfTag::getResolution()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <http://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Chrisyue\PhpM3u8\Tag;
13
14
class StreamInfTag extends AbstractTag
15
{
16
    use AttributesValueTagTrait;
17
18
    const TAG_IDENTIFIER = '#EXT-X-STREAM-INF';
19
20
    /**
21
     * @var string
22
     */
23
    private $programId;
24
25
    /**
26
     * @var string
27
     */
28
    private $bandwidth;
29
30
    /**
31
     * @var string
32
     */
33
    private $resolution;
34
35
    /**
36
     * @var string
37
     */
38
    private $codecs;
39
40
    /**
41
     * @param string
42
     *
43
     * @return self
44
     */
45 1
    public function setProgramId($programId)
46
    {
47 1
        $this->programId = $programId;
48
49 1
        return $this;
50
    }
51
52
    /**
53
     * @return string
54
     */
55 1
    public function getProgramId()
56
    {
57 1
        return $this->programId;
58
    }
59
60
    /**
61
     * @param string
62
     *
63
     * @return self
64
     */
65 1
    public function setBandwidth($bandwidth)
66
    {
67 1
        $this->bandwidth = $bandwidth;
68
69 1
        return $this;
70
    }
71
72
    /**
73
     * @return string
74
     */
75 1
    public function getBandwidth()
76
    {
77 1
        return $this->bandwidth;
78
    }
79
80
    /**
81
     * @param string
82
     *
83
     * @return self
84
     */
85 1
    public function setResolution($resolution)
86
    {
87 1
        $this->resolution = $resolution;
88
89 1
        return $this;
90
    }
91
92
    /**
93
     * @return string
94
     */
95 1
    public function getResolution()
96
    {
97 1
        return $this->resolution;
98
    }
99
100
    /**
101
     * @param string
102
     *
103
     * @return self
104
     */
105 1
    public function setCodecs($codecs)
106
    {
107 1
        $this->codecs = $codecs;
108
109 1
        return $this;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 1
    public function getCodecs()
116
    {
117 1
        return $this->codecs;
118
    }
119
120 1 View Code Duplication
    public function dump()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122 1
        $attrs = [];
123 1
        foreach (get_object_vars($this) as $prop => $value) {
124 1
            if (empty($value)) {
125 1
                continue;
126
            }
127
128 1
            if ('codecs' === $prop) {
129 1
                $attrs[] = sprintf('%s="%s"', strtoupper($prop), implode(',', $value));
130
131 1
                continue;
132
            }
133
134 1
            if ('programId' === $prop) {
135 1
                $attrs[] = sprintf('%s=%s', 'PROGRAM-ID', $value);
136
137 1
                continue;
138
            }
139
140 1
            $attrs[] = sprintf('%s=%s', strtoupper($prop), $value);
141 1
        }
142
143 1
        if (empty($attrs)) {
144 1
            return;
145
        }
146
147 1
        return sprintf('%s:%s', self::TAG_IDENTIFIER, implode(',', $attrs));
148
    }
149
150 1
    protected function read($line)
151
    {
152 1
        $attributes = self::extractAttributes($line);
153
154 1
        foreach (get_object_vars($this) as $prop => $value) {
155 1
            $key = strtoupper($prop);
156 1
            if (isset($attributes[$key])) {
157 1
                if ('codecs' === $prop) {
158 1
                    $this->codecs = explode(',', trim($attributes[$key], '"'));
0 ignored issues
show
Documentation Bug introduced by
It seems like explode(',', trim($attributes[$key], '"')) of type array is incompatible with the declared type string of property $codecs.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
159
160 1
                    continue;
161
                }
162
163 1
                $this->$prop = $attributes[$key];
164 1
            }
165 1
        }
166
167 1
        if (isset($attributes['PROGRAM-ID'])) {
168 1
            $this->programId = $attributes['PROGRAM-ID'];
169 1
        }
170 1
    }
171
}
172