MappingValueConverter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Ddeboer\DataImport\ValueConverter;
4
5
use Ddeboer\DataImport\Exception\UnexpectedValueException;
6
7
/**
8
 * @author Grégoire Paris
9
 */
10
class MappingValueConverter
11
{
12
    /**
13
     * @var array
14
     */
15
    private $mapping = [];
16
17
    /**
18
     * @param array $mapping
19
     */
20 1
    public function __construct(array $mapping)
21
    {
22 1
        $this->mapping = $mapping;
23 1
    }
24
25 1
    public function __invoke($input)
26
    {
27 1
        if (!isset($this->mapping[$input])) {
28 1
            throw new UnexpectedValueException(sprintf(
29 1
                'Cannot find mapping for value "%s"',
30
                $input
31 1
            ));
32
        }
33
34 1
        return $this->mapping[$input];
35
    }
36
}
37