Completed
Pull Request — develop (#19)
by Chris
02:02
created

ExtinfTag   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 60
ccs 24
cts 26
cp 0.9231
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setDuration() 0 6 1
A getDuration() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
A dump() 0 12 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 ExtinfTag extends AbstractSegmentTag
15
{
16
    private $duration;
17
    private $title;
18
    private $m3u8Version;
19
20
    const TAG_IDENTIFIER = '#EXTINF';
21
22 2
    public function __construct($m3u8Version = 3)
23
    {
24 2
        $this->m3u8Version = $m3u8Version;
25 2
    }
26
27 1
    public function setDuration($duration)
28
    {
29 1
        $this->duration = $duration;
30
31 1
        return $this;
32
    }
33
34 1
    public function getDuration()
35
    {
36 1
        return $this->duration;
37
    }
38
39 1
    public function setTitle($title)
40
    {
41 1
        $this->title = $title;
42
43 1
        return $this;
44
    }
45
46 1
    public function getTitle()
47
    {
48 1
        return $this->title;
49
    }
50
51 1
    public function dump()
52
    {
53 1
        if (null === $this->duration) {
54
            return;
55
        }
56
57 1
        if (3 > $this->m3u8Version) {
58
            return sprintf('%s:%d,%s', self::TAG_IDENTIFIER, round($this->duration), $this->title);
59
        }
60
61 1
        return sprintf('%s:%.3f,%s', self::TAG_IDENTIFIER, round($this->duration, 3), $this->title);
62
    }
63
64 1
    protected function read($line)
65
    {
66 1
        preg_match('/^#EXTINF:(.+),(.*)$/', $line, $matches);
67 1
        $this->duration = $matches[1];
68
69 1
        if (isset($matches[2])) {
70 1
            $this->title = $matches[2];
71 1
        }
72 1
    }
73
}
74