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

Attr::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Transformer\Factory\Annotation;
4
5
use Chrisyue\PhpM3u8\Transformer\Factory\FactoryInterface;
6
use Chrisyue\PhpM3u8\Transformer\AttrTransformer;
7
8
/**
9
 * @Annotation
10
 */
11
class Attr implements FactoryInterface
12
{
13
    private $attrName;
14
15
    private $trFactory;
16
17
    public function __construct(array $options)
18
    {
19
        $this->attrName = $options['name'];
20
        if (isset($options['type'])) {
21
            $this->trFactory = $options['type'];
22
        }
23
    }
24
25
    public function createTransformer()
26
    {
27
        return $this->create('Transformer');
28
    }
29
30
    public function createReverser()
31
    {
32
        return $this->create('Reverser');
33
    }
34
35
    private function create($type)
36
    {
37
        $tr = null;
38
        if (null !== $this->trFactory) {
39
            $method = sprintf('create%s', $type);
40
            $tr = $this->trFactory->$method();
41
        }
42
43
        $class = sprintf('Chrisyue\PhpM3u8\Transformer\Attr%s', $type);
44
45
        return new $class($this->attrName, $tr);
46
    }
47
}
48