Completed
Push — develop ( f101a1...f94113 )
by Chris
12s
created

ByteRangeTag   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 62
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setLength() 0 6 1
A getLength() 0 4 1
A setOffset() 0 6 1
A getOffset() 0 4 1
A dump() 0 14 3
A read() 0 9 2
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 AbstractSegmentTag
15
{
16
    private $length;
17
    private $offset;
18
19
    const TAG_IDENTIFIER = '#EXT-X-BYTERANGE';
20
21
    /**
22
     * @return self
23
     */
24 1
    public function setLength($length)
25
    {
26 1
        $this->length = $length;
27
28 1
        return $this;
29
    }
30
31
    /**
32
     * @return self
33
     */
34 1
    public function getLength()
35
    {
36 1
        return $this->length;
37
    }
38
39 1
    public function setOffset($offset)
40
    {
41 1
        $this->offset = $offset;
42
43 1
        return $this;
44
    }
45
46 1
    public function getOffset()
47
    {
48 1
        return $this->offset;
49
    }
50
51 1
    public function dump()
52
    {
53 1
        if (empty($this->length)) {
54 1
            return;
55
        }
56
57 1
        $text = sprintf('%s:%d', self::TAG_IDENTIFIER, $this->length);
58
59 1
        if (!empty($this->offset)) {
60 1
            $text = sprintf('%s@%d', $text, $this->offset);
61 1
        }
62
63 1
        return $text;
64
    }
65
66 1
    protected function read($line)
67
    {
68 1
        preg_match('/^#EXT-X-BYTERANGE:(\d+)(@(\d+))?$/', $line, $matches);
69 1
        $this->length = (int) $matches[1];
70
71 1
        if (!empty($matches[3])) {
72 1
            $this->offset = (int) $matches[3];
73 1
        }
74 1
    }
75
}
76