Completed
Pull Request — develop (#27)
by Chris
05:29
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
namespace Chrisyue\PhpM3u8\Stream;
4
5
class TextStream implements StreamInterface
6
{
7
    private $lines;
8
9
    public function __construct($text = '')
10
    {
11
        $this->lines = explode("\n", $text);
12
    }
13
14
    public function next()
15
    {
16
        next($this->lines);
17
    }
18
19
    public function valid()
20
    {
21
        return false !== current($this->lines);
22
    }
23
24
    public function current()
25
    {
26
        return current($this->lines);
27
    }
28
29
    public function key()
30
    {
31
        return key($this->lines);
32
    }
33
34
    public function rewind()
35
    {
36
        reset($this->lines);
37
    }
38
39
    public function add($line)
40
    {
41
        $this->lines[] = $line;
42
    }
43
44
    public function __toString()
45
    {
46
        return implode("\n", $this->lines)."\n";
47
    }
48
}
49