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

Lines   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A read() 0 11 2
A write() 0 4 1
A goNext() 0 13 3
A isValid() 0 4 1
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