PropertyMarker2Mapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 35
c 0
b 0
f 0
rs 10
ccs 11
cts 11
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createMapper() 0 11 2
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