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

Attr   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 37
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A createTransformer() 0 4 1
A createReverser() 0 4 1
A create() 0 12 2
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