Completed
Pull Request — develop (#27)
by Chris
02:45
created

Lines::key()   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
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <https://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Chrisyue\PhpM3u8\Line;
13
14
use Chrisyue\PhpM3u8\Stream\StreamInterface;
15
16
class Lines implements \Iterator
17
{
18
    private $stream;
19
20
    public function __construct(StreamInterface $stream)
21
    {
22
        $this->stream = $stream;
23
    }
24
25
    public function current()
26
    {
27
        static $text, $line;
28
        if ($this->stream->current() !== $text) {
29
            $text = $this->stream->current();
30
            $line = Line::fromString($text);
31
        }
32
33
        return $line;
34
    }
35
36
    public function add(Line $line)
37
    {
38
        $this->stream->add((string) $line);
39
    }
40
41
    public function next()
42
    {
43
        $this->stream->next();
44
        if (!$this->stream->valid()) {
45
            return;
46
        }
47
48
        $line = trim($this->stream->current());
49
        if (empty($line)) {
50
            $this->next();
51
        }
52
    }
53
54
    public function valid()
55
    {
56
        return $this->stream->valid();
57
    }
58
59
    public function rewind()
60
    {
61
        $this->stream->rewind();
62
    }
63
64
    public function key()
65
    {
66
        return $this->stream->key();
67
    }
68
}
69