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

M3u8   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 88.46%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 8
dl 0
loc 122
ccs 46
cts 52
cp 0.8846
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A read() 0 6 1
A getVersionTag() 0 4 1
A getVersion() 0 4 1
A getTargetDurationTag() 0 4 1
A getTargetDuration() 0 4 1
A getMediaSequenceTag() 0 4 1
A getMediaSequence() 0 4 1
A getDiscontinuitySequenceTag() 0 4 1
A getDiscontinuitySequence() 0 4 1
A getSegments() 0 4 1
A getEndlistTag() 0 4 1
A isEndless() 0 4 1
A getDuration() 0 4 1
A getAge() 0 4 1
A getComponents() 0 12 1
A split() 0 7 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 $targetDurationTag;
19
    private $mediaSequenceTag;
20
    private $discontinuitySequenceTag;
21
    private $segments;
22
    private $endlistTag;
23
24 2
    public function __construct()
25
    {
26 2
        $this->m3uTag = new Tag\M3uTag();
27 2
        $this->versionTag = new Tag\VersionTag();
28 2
        $this->targetDurationTag = new Tag\TargetDurationTag();
29 2
        $this->mediaSequenceTag = new Tag\MediaSequenceTag();
30 2
        $this->discontinuitySequenceTag = new Tag\DiscontinuitySequenceTag();
31 2
        $this->segments = new Segments($this);
32 2
        $this->endlistTag = new Tag\EndlistTag();
33 2
    }
34
35 1
    public function read($string)
36
    {
37 1
        $lines = $this->split($string);
38
39 1
        $this->readLines($lines);
40 1
    }
41
42 1
    public function getVersionTag()
43
    {
44 1
        return $this->versionTag;
45
    }
46
47 1
    public function getVersion()
48
    {
49 1
        return $this->versionTag->getVersion();
50
    }
51
52 1
    public function getTargetDurationTag()
53
    {
54 1
        return $this->targetDurationTag;
55
    }
56
57 1
    public function getTargetDuration()
58
    {
59 1
        return $this->targetDurationTag->getTargetDuration();
60
    }
61
62 1
    public function getMediaSequenceTag()
63
    {
64 1
        return $this->mediaSequenceTag;
65
    }
66
67 1
    public function getMediaSequence()
68
    {
69 1
        return $this->mediaSequenceTag->getMediaSequence();
70
    }
71
72 1
    public function getDiscontinuitySequenceTag()
73
    {
74 1
        return $this->discontinuitySequenceTag;
75
    }
76
77 1
    public function getDiscontinuitySequence()
78
    {
79 1
        return $this->discontinuitySequenceTag->getDiscontinuitySequence();
80
    }
81
82
    /**
83
     * @return Chrisyue\PhpM3u8\Segments
84
     */
85 2
    public function getSegments()
86
    {
87 2
        return $this->segments;
88
    }
89
90 1
    public function getEndlistTag()
91
    {
92 1
        return $this->endlistTag;
93
    }
94
95
    public function isEndless()
96
    {
97
        return $this->endlistTag->isEndless();
98
    }
99
100
    public function getDuration()
101
    {
102
        return $this->segments->getDuration();
103
    }
104
105
    /**
106
     * This method is used when you want to create a live playlist.
107
     *
108
     * @return int
109
     */
110
    public function getAge()
111
    {
112
        return $this->segments->getAge();
113
    }
114
115 2
    protected function getComponents()
116
    {
117
        return array(
118 2
            $this->m3uTag,
119 2
            $this->versionTag,
120 2
            $this->targetDurationTag,
121 2
            $this->mediaSequenceTag,
122 2
            $this->discontinuitySequenceTag,
123 2
            $this->segments,
124 2
            $this->endlistTag,
125 2
        );
126
    }
127
128 1
    private function split($string)
129
    {
130 1
        $lines = explode("\n", $string);
131 1
        $lines = array_map('trim', $lines);
132
133 1
        return array_filter($lines);
134
    }
135
}
136