Passed
Push — master ( 5f26bc...fdb2cd )
by Dominik
01:56
created

DenormalizerObjectMappingRegistry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A addObjectMapping() 0 4 1
A getObjectMapping() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Denormalizer;
6
7
use Chubbyphp\Deserialization\DeserializerLogicException;
8
use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface;
9
10
final class DenormalizerObjectMappingRegistry implements DenormalizerObjectMappingRegistryInterface
11
{
12
    /**
13
     * @var DenormalizationObjectMappingInterface[]
14
     */
15
    private $objectMappings;
16
17
    /**
18
     * @param array $objectMappings
19
     */
20 2
    public function __construct(array $objectMappings)
21
    {
22 2
        $this->objectMappings = [];
23 2
        foreach ($objectMappings as $objectMapping) {
24 1
            $this->addObjectMapping($objectMapping);
25
        }
26 2
    }
27
28
    /**
29
     * @param DenormalizationObjectMappingInterface $objectMapping
30
     */
31 1
    private function addObjectMapping(DenormalizationObjectMappingInterface $objectMapping)
32
    {
33 1
        $this->objectMappings[$objectMapping->getClass()] = $objectMapping;
34 1
    }
35
36
    /**
37
     * @param string $class
38
     *
39
     * @return DenormalizationObjectMappingInterface
40
     *
41
     * @throws DeserializerLogicException
42
     */
43 2
    public function getObjectMapping(string $class): DenormalizationObjectMappingInterface
44
    {
45 2
        if (isset($this->objectMappings[$class])) {
46 1
            return $this->objectMappings[$class];
47
        }
48
49 1
        throw DeserializerLogicException::createMissingMapping($class);
50
    }
51
}
52