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

TagParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Parser;
4
5
use Chrisyue\PhpM3u8\Line\LineInterface;
6
use Chrisyue\PhpM3u8\Transformer\TransformerInterface;
7
use Chrisyue\PhpM3u8\Line\LinesInterface;
8
9
class TagParser implements ChildParserInterface
10
{
11
    private $line;
12
13
    private $transformer;
14
15
    private $repeatable;
16
17
    public function __construct(LineInterface $line, TransformerInterface $transformer = null, $repeatable = false)
18
    {
19
        $this->line = $line;
20
        $this->transformer = $transformer;
21
        $this->repeatable = $repeatable;
22
    }
23
24
    public function parse(LinesInterface $lines)
25
    {
26
        $line = $lines->read();
27
        $value = $line->getValue();
28
29
        if (null === $this->transformer) {
30
            return $value;
31
        }
32
33
        return $this->transformer->transform($value);
34
    }
35
36
    public function supports(LineInterface $line)
37
    {
38
        return $this->line->isSameType($line);
39
    }
40
41
    public function isRepeatable()
42
    {
43
        return $this->repeatable;
44
    }
45
}
46