PropertyMarker2Mapper::__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
c 0
b 0
f 0
rs 10
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Created by gerk on 30.09.16 15:11
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Core\LookUp;
7
8
use PeekAndPoke\Component\Slumber\Annotation\PropertyMappingMarker;
9
10
/**
11
 * @author Karsten J. Gerber <[email protected]>
12
 */
13
class PropertyMarker2Mapper
14
{
15
    /** @var string */
16
    private $default;
17
    /** @var string[] */
18
    private $mappings;
19
20
    /**
21
     * Annotation2Mapper constructor.
22
     *
23
     * @param string   $default  Class name of the default mapper
24
     * @param string[] $mappings Mapping from annotation to mapper class
25
     */
26 394
    public function __construct($default, $mappings)
27
    {
28 394
        $this->default  = $default;    // TODO: get rid of the default... either we can or cannot map
29 394
        $this->mappings = $mappings;
30 394
    }
31
32
    /**
33
     * @param PropertyMappingMarker $marker
34
     *
35
     * @return mixed
36
     */
37 36
    public function createMapper(PropertyMappingMarker $marker)
38
    {
39 36
        $markerClass = \get_class($marker);
40 36
        $mapperClass = $this->mappings[$markerClass] ?? $this->default;
41
42
        // descend the children
43 36
        $child = $marker->getValue() instanceof PropertyMappingMarker
44 10
            ? $this->createMapper($marker->getValue())
45 36
            : null;
46
47 36
        return new $mapperClass($marker, $child);
48
    }
49
}
50