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

AttrTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A transform() 0 8 2
A supports() 0 4 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Transformer;
4
5
class AttrTransformer implements AttrTransformerInterface
6
{
7
    private $attrName;
8
9
    private $valueTransformer;
10
11
    public function __construct($attrName, TransformerInterface $valueTransformer = null)
12
    {
13
        $this->attrName = $attrName;
14
        $this->valueTransformer = $valueTransformer;
15
    }
16
17
    public function transform($origin)
18
    {
19
        if (null === $this->valueTransformer) {
20
            return $origin;
21
        }
22
23
        return $this->valueTransformer->transform($origin);
24
    }
25
26
    public function supports($attrName)
27
    {
28
        return $this->attrName === $attrName;
29
    }
30
}
31