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

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