Completed
Branch v1.x-dev (59bcf7)
by Benjamin
05:08
created

KeyToCollectionMapper::reverseTransform()   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 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Obblm\Core\DataTransformer;
4
5
use Obblm\Core\Contracts\PositionInterface;
6
use Symfony\Component\Form\DataTransformerInterface;
7
8
class KeyToCollectionMapper implements DataTransformerInterface
9
{
10
    private $collection;
11
12
    public function __construct($collection)
13
    {
14
        $this->collection = $collection;
15
    }
16
17
    /**
18
     * @param string|null $value
19
     * @return PositionInterface|void
20
     */
21
    public function transform($value)
22
    {
23
        if ($value === null) {
24
            return;
25
        }
26
27
        if (!isset($this->collection[$value])) {
28
            return;
29
        }
30
31
        return $this->collection[$value];
32
    }
33
34
    public function reverseTransform($viewData)
35
    {
36
        if ($viewData === null) {
37
            return;
38
        }
39
40
        return $viewData->getKey();
41
    }
42
}
43