ByteRangeTag::getLength()   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 ByteRangeTag extends AbstractTag
15
{
16
    private $length;
17
18
    private $offset;
19
20
    const TAG_IDENTIFIER = '#EXT-X-BYTERANGE';
21
22
    /**
23
     * @return self
24
     */
25 1
    public function setLength($length)
26
    {
27 1
        $this->length = $length;
28
29 1
        return $this;
30
    }
31
32
    /**
33
     * @return int
34
     */
35 1
    public function getLength()
36
    {
37 1
        return $this->length;
38
    }
39
40
    /**
41
     * @return self
42
     */
43 1
    public function setOffset($offset)
44
    {
45 1
        $this->offset = $offset;
46
47 1
        return $this;
48
    }
49
50
    /**
51
     * @return int
52
     */
53 1
    public function getOffset()
54
    {
55 1
        return $this->offset;
56
    }
57
58 1
    public function dump()
59
    {
60 1
        if (empty($this->length)) {
61 1
            return;
62
        }
63
64 1
        $text = sprintf('%s:%d', self::TAG_IDENTIFIER, $this->length);
65
66 1
        if (!empty($this->offset)) {
67 1
            $text = sprintf('%s@%d', $text, $this->offset);
68 1
        }
69
70 1
        return $text;
71
    }
72
73 1
    protected function read($line)
74
    {
75 1
        list($this->length, $this->offset) = sscanf($line, self::TAG_IDENTIFIER.':%d@%d');
76 1
    }
77
}
78