Completed
Pull Request — develop (#27)
by Chris
02:45
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
/*
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