Completed
Pull Request — develop (#29)
by
unknown
08:36
created

M3u8::getTargetDurationTag()   A

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;
13
14
class M3u8 extends AbstractContainer
15
{
16
    private $m3uTag;
17
    private $versionTag;
18
    private $playlistTypeTag;
19
    private $targetDurationTag;
20
    private $mediaSequenceTag;
21
    private $discontinuitySequenceTag;
22
    private $segments;
23
    private $endlistTag;
24
25 2
    public function __construct()
26
    {
27 2
        $this->m3uTag = new Tag\M3uTag();
28 2
        $this->versionTag = new Tag\VersionTag();
29 2
        $this->playlistTypeTag = new Tag\PlaylistTypeTag();
30 2
        $this->targetDurationTag = new Tag\TargetDurationTag();
31 2
        $this->mediaSequenceTag = new Tag\MediaSequenceTag();
32 2
        $this->discontinuitySequenceTag = new Tag\DiscontinuitySequenceTag();
33 2
        $this->segments = new Segments($this);
34 2
        $this->endlistTag = new Tag\EndlistTag();
35 2
    }
36
37 1
    public function read($string)
38
    {
39 1
        $lines = self::split($string);
40
41 1
        $this->readLines($lines);
42 1
    }
43
44 1
    public function getVersionTag()
45
    {
46 1
        return $this->versionTag;
47
    }
48
49 1
    public function getVersion()
50
    {
51 1
        return $this->versionTag->getVersion();
52
    }
53
54
    public function getPlaylistTypeTag()
55
    {
56
        return $this->playlistTypeTag;
57
    }
58
59
    public function getPlaylistType()
60
    {
61
        return $this->playlistTypeTag->getPlaylistType();
62
    }
63
64 1
    public function getTargetDurationTag()
65
    {
66 1
        return $this->targetDurationTag;
67
    }
68
69 1
    public function getTargetDuration()
70
    {
71 1
        return $this->targetDurationTag->getTargetDuration();
72
    }
73
74 1
    public function getMediaSequenceTag()
75
    {
76 1
        return $this->mediaSequenceTag;
77
    }
78
79 1
    public function getMediaSequence()
80
    {
81 1
        return $this->mediaSequenceTag->getMediaSequence();
82
    }
83
84 1
    public function getDiscontinuitySequenceTag()
85
    {
86 1
        return $this->discontinuitySequenceTag;
87
    }
88
89 1
    public function getDiscontinuitySequence()
90
    {
91 1
        return $this->discontinuitySequenceTag->getDiscontinuitySequence();
92
    }
93
94
    /**
95
     * @return Chrisyue\PhpM3u8\Segments
96
     */
97 2
    public function getSegments()
98
    {
99 2
        return $this->segments;
100
    }
101
102 1
    public function getEndlistTag()
103
    {
104 1
        return $this->endlistTag;
105
    }
106
107
    public function isEndless()
108
    {
109
        return $this->endlistTag->isEndless();
110
    }
111
112 1
    public function getDuration()
113
    {
114 1
        return $this->segments->getDuration();
115
    }
116
117 2
    protected function getComponents()
118
    {
119
        return [
120 2
            $this->m3uTag,
121 2
            $this->versionTag,
122 2
            $this->playlistTypeTag,
123 2
            $this->targetDurationTag,
124 2
            $this->mediaSequenceTag,
125 2
            $this->discontinuitySequenceTag,
126 2
            $this->segments,
127 2
            $this->endlistTag,
128 2
        ];
129
    }
130
131 1
    private static function split($string)
132
    {
133 1
        $lines = explode("\n", $string);
134 1
        $lines = array_map('trim', $lines);
135
136 1
        return array_filter($lines);
137
    }
138
}
139