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

TextStream   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A next() 0 4 1
A valid() 0 4 1
A current() 0 4 1
A key() 0 4 1
A rewind() 0 4 1
A add() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <https://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\Stream;
13
14
class TextStream implements StreamInterface
15
{
16
    private $lines;
17
18
    public function __construct($text = '')
19
    {
20
        $this->lines = explode("\n", $text);
21
    }
22
23
    public function next()
24
    {
25
        next($this->lines);
26
    }
27
28
    public function valid()
29
    {
30
        return false !== current($this->lines);
31
    }
32
33
    public function current()
34
    {
35
        return current($this->lines);
36
    }
37
38
    public function key()
39
    {
40
        return key($this->lines);
41
    }
42
43
    public function rewind()
44
    {
45
        reset($this->lines);
46
    }
47
48
    public function add($line)
49
    {
50
        $this->lines[] = $line;
51
    }
52
53
    public function __toString()
54
    {
55
        return implode("\n", $this->lines)."\n";
56
    }
57
}
58