Total Complexity | 7 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | final class DenormalizerObjectMappingRegistry implements DenormalizerObjectMappingRegistryInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var DenormalizationObjectMappingInterface[] |
||
14 | */ |
||
15 | private $objectMappings; |
||
16 | |||
17 | public function __construct(array $objectMappings) |
||
18 | { |
||
19 | $this->objectMappings = []; |
||
20 | 3 | foreach ($objectMappings as $objectMapping) { |
|
21 | $this->addObjectMapping($objectMapping); |
||
22 | 3 | } |
|
23 | 3 | } |
|
24 | 2 | ||
25 | /** |
||
26 | 3 | * @throws DeserializerLogicException |
|
27 | */ |
||
28 | public function getObjectMapping(string $class): DenormalizationObjectMappingInterface |
||
29 | { |
||
30 | $reflectionClass = new \ReflectionClass($class); |
||
31 | |||
32 | if (in_array('Doctrine\Common\Persistence\Proxy', $reflectionClass->getInterfaceNames(), true)) { |
||
33 | $reflectionParentClass = (new \ReflectionClass($class))->getParentClass(); |
||
34 | if ($reflectionParentClass instanceof \ReflectionClass) { |
||
35 | 3 | $class = $reflectionParentClass->getName(); |
|
36 | } |
||
37 | 3 | } |
|
38 | |||
39 | 3 | if (isset($this->objectMappings[$class])) { |
|
40 | 1 | return $this->objectMappings[$class]; |
|
41 | 1 | } |
|
42 | 1 | ||
43 | throw DeserializerLogicException::createMissingMapping($class); |
||
44 | } |
||
45 | |||
46 | 3 | private function addObjectMapping(DenormalizationObjectMappingInterface $objectMapping): void |
|
49 | } |
||
50 | } |
||
51 |