ExtinfTag::read()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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 ExtinfTag extends AbstractTag
15
{
16
    private $duration;
17
18
    private $title;
19
20
    private $m3u8Version;
21
22
    const TAG_IDENTIFIER = '#EXTINF';
23
24 2
    public function __construct($m3u8Version = 3)
25
    {
26 2
        $this->m3u8Version = $m3u8Version;
27 2
    }
28
29 1
    public function setDuration($duration)
30
    {
31 1
        $this->duration = $duration;
32
33 1
        return $this;
34
    }
35
36 1
    public function getDuration()
37
    {
38 1
        return $this->duration;
39
    }
40
41 1
    public function setTitle($title)
42
    {
43 1
        $this->title = $title;
44
45 1
        return $this;
46
    }
47
48 1
    public function getTitle()
49
    {
50 1
        return $this->title;
51
    }
52
53 1
    public function dump()
54
    {
55 1
        if (null === $this->duration) {
56 1
            return;
57
        }
58
59 1
        if (3 > $this->m3u8Version) {
60
            return sprintf('%s:%d,%s', self::TAG_IDENTIFIER, round($this->duration), $this->title);
61
        }
62
63 1
        return sprintf('%s:%.3f,%s', self::TAG_IDENTIFIER, round($this->duration, 3), $this->title);
64
    }
65
66 1
    protected function read($line)
67
    {
68 1
        list($this->duration, $this->title) = sscanf($line, self::TAG_IDENTIFIER.':%f,%[^$]');
69 1
    }
70
}
71