Completed
Pull Request — develop (#27)
by Chris
01:52
created

Lines::goNext()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 0
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Line;
4
5
use Chrisyue\PhpM3u8\Stream\StreamInterface;
6
use Chrisyue\PhpM3u8\Line\LineInterface;
7
8
class Lines implements LinesInterface
9
{
10
    private $stream;
11
12
    public function __construct(StreamInterface $stream)
13
    {
14
        $this->stream = $stream;
15
    }
16
17
    public function read()
18
    {
19
        static $text, $line;
20
21
        if ($this->stream->getLine() !== $text) {
22
            $text = $this->stream->getLine();
23
            $line = Line::fromString($text);
24
        }
25
26
        return $line;
27
    }
28
29
    public function write(LineInterface $line)
30
    {
31
        $this->stream->putLine((string) $line);
32
    }
33
34
    public function goNext()
35
    {
36
        $this->stream->goNext();
37
38
        if (!$this->stream->isValid()) {
39
            return;
40
        }
41
42
        $line = trim($this->stream->getLine());
43
        if (empty($line)) {
44
            $this->goNext();
45
        }
46
    }
47
48
    public function isValid()
49
    {
50
        return $this->stream->isValid();
51
    }
52
}
53