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

DataTransformerManager::addDataTransformers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
ccs 0
cts 4
cp 0
cc 2
eloc 3
nc 2
nop 1
crap 6
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