Completed
Pull Request — develop (#27)
by Chris
10:40
created

Attribute::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\M3u8\Attribute;
4
5
use Chrisyue\PhpM3u8\M3u8\OptionsTrait;
6
7
/**
8
 * @Annotation
9
 * @Target("PROPERTY")
10
 */
11
class Attribute implements AttributeInterface
12
{
13
    use OptionsTrait;
14
15
    public function parse($origin)
16
    {
17
        if (empty($this->options['transformers'])) {
18
            return $origin;
19
        }
20
21
        foreach ($this->options['transformers'] as $transformer) {
22
            $origin = $transformer->transform($origin);
23
        }
24
25
        return $origin;
26
    }
27
28
    public function dump($parsed)
29
    {
30
        if (empty($this->options['transformers'])) {
31
            return $parsed;
32
        }
33
34
        foreach (array_reverse($this->options['transformers']) as $transformer) {
35
            $parsed = $transformer->reverse($parsed);
36
        }
37
38
        return $parsed;
39
    }
40
41
    public function getName()
42
    {
43
        return $this->options['name'];
44
    }
45
}
46