1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the API Platform project. |
||
5 | * |
||
6 | * (c) Kévin Dunglas <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace ApiPlatform\Core\Identifier\Normalizer; |
||
15 | |||
16 | use Symfony\Component\PropertyInfo\Type; |
||
17 | use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; |
||
18 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
||
19 | |||
20 | final class IntegerDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | public function denormalize($data, $class, $format = null, array $context = []): int |
||
26 | { |
||
27 | return (int) $data; |
||
0 ignored issues
–
show
|
|||
28 | } |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | public function supportsDenormalization($data, $type, $format = null): bool |
||
34 | { |
||
35 | return Type::BUILTIN_TYPE_INT === $type && \is_string($data); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function hasCacheableSupportsMethod(): bool |
||
42 | { |
||
43 | return true; |
||
44 | } |
||
45 | } |
||
46 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: