Total Complexity | 6 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | class TraversableNormalizer implements NormalizerInterface |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | 4 | public function normalize($data, NormalizationContext $context) |
|
22 | { |
||
23 | 4 | $normalized = []; |
|
24 | |||
25 | 4 | foreach ($data as $key => $value) { |
|
26 | 4 | $normalized[$key] = $context->root()->normalize($value, $context); |
|
27 | } |
||
28 | |||
29 | 4 | return $normalized; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 6 | public function denormalize($data, Type $type, DenormalizationContext $context) |
|
36 | { |
||
37 | 6 | $className = $type->name(); |
|
38 | /** @var \ArrayAccess&Traversable $denormalized */ |
||
39 | 6 | $denormalized = new $className(); |
|
40 | |||
41 | 6 | foreach ((array)$data as $key => $value) { |
|
42 | 6 | $denormalized[$key] = $context->root()->denormalize( |
|
43 | 6 | $value, |
|
44 | 6 | $type->isParametrized() ? $type->subType() : TypeFactory::mixedType(), |
|
45 | 6 | $context |
|
46 | 6 | ); |
|
47 | } |
||
48 | |||
49 | 6 | return $denormalized; |
|
|
|||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 164 | public function supports(string $className): bool |
|
58 | } |
||
59 | } |
||
60 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: