Completed
Push — master ( a6c8f9...b97be3 )
by Vladimir
03:52 queued 19s
created

DataTransformerManager::addDataTransformer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 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 7
    public function addDataTransformer(DataTransformer $transformer)
22
    {
23 7
        foreach ($transformer->getExtensions() as $extension)
24
        {
25 7
            $this->transformers[$extension] = $transformer;
26 7
        }
27 7
    }
28
29 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...
30
    {
31 7
        if (isset($this->transformers[$extension]))
32 7
        {
33 6
            return $this->transformers[$extension];
34
        }
35
36 1
        throw new UnsupportedDataTypeException($extension, 'There is no support to handle this file extension.');
37
    }
38
}
39