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

Lines::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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