Completed
Pull Request — develop (#27)
by Chris
05:29
created

Lines   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A current() 0 10 2
A add() 0 4 1
A next() 0 12 3
A valid() 0 4 1
A rewind() 0 4 1
A key() 0 4 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Line;
4
5
use Chrisyue\PhpM3u8\Stream\StreamInterface;
6
7
class Lines implements \Iterator
8
{
9
    private $stream;
10
11
    public function __construct(StreamInterface $stream)
12
    {
13
        $this->stream = $stream;
14
    }
15
16
    public function current()
17
    {
18
        static $text, $line;
19
        if ($this->stream->current() !== $text) {
20
            $text = $this->stream->current();
21
            $line = Line::fromString($text);
22
        }
23
24
        return $line;
25
    }
26
27
    public function add(Line $line)
28
    {
29
        $this->stream->add((string) $line);
30
    }
31
32
    public function next()
33
    {
34
        $this->stream->next();
35
        if (!$this->stream->valid()) {
36
            return;
37
        }
38
39
        $line = trim($this->stream->current());
40
        if (empty($line)) {
41
            $this->next();
42
        }
43
    }
44
45
    public function valid()
46
    {
47
        return $this->stream->valid();
48
    }
49
50
    public function rewind()
51
    {
52
        $this->stream->rewind();
53
    }
54
55
    public function key()
56
    {
57
        return $this->stream->key();
58
    }
59
}
60