KeyTag::dump()   C
last analyzed

Complexity

Conditions 7
Paths 10

Size

Total Lines 29
Code Lines 15

Duplication

Lines 29
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 7.0119

Importance

Changes 0
Metric Value
dl 29
loc 29
ccs 15
cts 16
cp 0.9375
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 15
nc 10
nop 0
crap 7.0119
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 KeyTag extends AbstractTag
15
{
16
    use AttributesValueTagTrait;
17
18
    const TAG_IDENTIFIER = '#EXT-X-KEY';
19
20
    /**
21
     * @var string
22
     */
23
    private $method;
24
25
    /**
26
     * @var string
27
     */
28
    private $uri;
29
30
    /**
31
     * @var string
32
     */
33
    private $iv;
34
35
    /**
36
     * @var string
37
     */
38
    private $keyFormat;
39
40
    /**
41
     * @var array
42
     */
43
    private $keyFormatVersions;
44
45
    /**
46
     * @param string
47
     *
48
     * @return self
49
     */
50 1
    public function setMethod($method)
51
    {
52 1
        $this->method = $method;
53
54 1
        return $this;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 1
    public function getMethod()
61
    {
62 1
        return $this->method;
63
    }
64
65
    /**
66
     * @param string
67
     *
68
     * @return self
69
     */
70 1
    public function setUri($uri)
71
    {
72 1
        $this->uri = $uri;
73
74 1
        return $this;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getUri()
81
    {
82
        return $this->uri;
83
    }
84
85
    /**
86
     * @param string
87
     *
88
     * @return self
89
     */
90 1
    public function setIv($iv)
91
    {
92 1
        $this->iv = $iv;
93
94 1
        return $this;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getIv()
101
    {
102
        return $this->iv;
103
    }
104
105
    /**
106
     * @param string
107
     *
108
     * @return self
109
     */
110 1
    public function setKeyFormat($keyFormat)
111
    {
112 1
        $this->keyFormat = $keyFormat;
113
114 1
        return $this;
115
    }
116
117
    /**
118
     * @return string
119
     */
120 1
    public function getKeyFormat()
121
    {
122 1
        return $this->keyFormat;
123
    }
124
125
    /**
126
     * @param array
127
     *
128
     * @return self
129
     */
130 1
    public function setKeyFormatVersions(array $keyFormatVersions)
131
    {
132 1
        $this->keyFormatVersions = $keyFormatVersions;
133
134 1
        return $this;
135
    }
136
137
    /**
138
     * @return array
139
     */
140 1
    public function getKeyFormatVersions()
141
    {
142 1
        return $this->keyFormatVersions;
143
    }
144
145 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...
146
    {
147 1
        $attrs = [];
148 1
        foreach (get_object_vars($this) as $prop => $value) {
149 1
            if (empty($value)) {
150 1
                continue;
151
            }
152
153 1
            if ('uri' === $prop || 'keyFormat' === $prop) {
154 1
                $attrs[] = sprintf('%s="%s"', strtoupper($prop), $value);
155
156 1
                continue;
157
            }
158
159 1
            if ('keyFormatVersions' === $prop) {
160 1
                $attrs[] = sprintf('KEYFORMATVERSIONS="%s"', implode('/', $value));
161
162 1
                continue;
163
            }
164
165 1
            $attrs[] = sprintf('%s=%s', strtoupper($prop), $value);
166 1
        }
167
168 1
        if (empty($attrs)) {
169
            return;
170
        }
171
172 1
        return sprintf('%s:%s', self::TAG_IDENTIFIER, implode(',', $attrs));
173
    }
174
175 1
    protected function read($line)
176
    {
177 1
        $attributes = self::extractAttributes($line);
178
179 1
        foreach (get_object_vars($this) as $prop => $value) {
180 1
            $key = strtoupper($prop);
181 1
            if (isset($attributes[$key])) {
182 1
                if ('uri' === $prop || 'keyFormat' === $prop) {
183 1
                    $this->$prop = trim($attributes[$key], '"');
184
185 1
                    continue;
186
                }
187
188 1
                if ('keyFormatVersions' === $prop) {
189 1
                    $this->keyFormatVersions = explode('/', trim($attributes[$key], '"'));
190
191 1
                    continue;
192
                }
193
194 1
                $this->$prop = $attributes[$key];
195 1
            }
196 1
        }
197 1
    }
198
}
199