Total Complexity | 6 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
10 | final class NormalizerObjectMappingRegistry implements NormalizerObjectMappingRegistryInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var NormalizationObjectMappingInterface[] |
||
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 SerializerLogicException |
|
27 | */ |
||
28 | public function getObjectMapping(string $class): NormalizationObjectMappingInterface |
||
29 | { |
||
30 | $reflectionClass = new \ReflectionClass($class); |
||
31 | |||
32 | if (in_array('Doctrine\Common\Persistence\Proxy', $reflectionClass->getInterfaceNames(), true)) { |
||
33 | /** @var \ReflectionClass $reflectionParentClass */ |
||
34 | $reflectionParentClass = $reflectionClass->getParentClass(); |
||
35 | 3 | $class = $reflectionParentClass->getName(); |
|
36 | } |
||
37 | 3 | ||
38 | if (isset($this->objectMappings[$class])) { |
||
39 | 3 | return $this->objectMappings[$class]; |
|
40 | 1 | } |
|
41 | |||
42 | throw SerializerLogicException::createMissingMapping($class); |
||
43 | 3 | } |
|
44 | 2 | ||
45 | private function addObjectMapping(NormalizationObjectMappingInterface $objectMapping): void |
||
48 | } |
||
49 | } |
||
50 |