Completed
Push — master ( f27021...2319eb )
by Vladimir
03:02
created

DataTransformerManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 35
rs 10
ccs 11
cts 15
cp 0.7332

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addDataTransformers() 0 7 2
A addDataTransformer() 0 7 2
A getTransformer() 0 9 2
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\DataTransformer;
9
10
use allejo\stakx\Exception\UnsupportedDataTypeException;
11
12
class DataTransformerManager
13
{
14
    private $transformers;
15
16 7
    public function __construct()
17
    {
18 7
        $this->transformers = [];
19 7
    }
20
21
    public function addDataTransformers(/*iterable*/ $dataTransformers)
22
    {
23
        foreach ($dataTransformers as $dataTransformer)
24
        {
25
            $this->addDataTransformer($dataTransformer);
26
        }
27
    }
28
29 7
    public function addDataTransformer(DataTransformer $transformer)
30
    {
31 7
        foreach ($transformer->getExtensions() as $extension)
32
        {
33 7
            $this->transformers[$extension] = $transformer;
34
        }
35 7
    }
36
37 7
    public function getTransformer($extension)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
38
    {
39 7
        if (isset($this->transformers[$extension]))
40
        {
41 6
            return $this->transformers[$extension];
42
        }
43
44 1
        throw new UnsupportedDataTypeException($extension, 'There is no support to handle this file extension.');
45
    }
46
}
47