Completed
Pull Request — develop (#27)
by Chris
20:10 queued 05:10
created

AbstractTag::dump()   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
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace Chrisyue\PhpM3u8\M3u8;
4
5
use Chrisyue\PhpM3u8\Stream\StreamInterface;
6
7
abstract class AbstractTag extends AbstractM3u8 implements SequenceAwareInterface
8
{
9
    public function parse()
10
    {
11
        $lineInfo = $this->getStream()->read();
12
        if (!isset($lineInfo['tag']) || $lineInfo['tag'] !== $this->getName()) {
13
            return $this;
14
        }
15
16
        foreach ($this->getTransformers() as $transformer) {
17
            $lineInfo['value'] = $transformer->transform($lineInfo['value']);
18
        }
19
20
        return $this->setResult($lineInfo['value']);
21
    }
22
23
    public function dump()
24
    {
25
        $value = $this->getResult();
26
        foreach (array_reverse($this->getTransformers()) as $transformer) {
27
            $value = $transformer->reverse($value);
28
        }
29
30
        $this->getStream()->write(['tag' => $this->getName(), 'value' => $value]);
31
32
        return $this;
33
    }
34
35
    abstract protected function getName();
36
37
    abstract protected function getTransformers();
38
}
39