Passed
Push — master ( b6ddb2...6e9ccf )
by Kévin
18:24 queued 13:31
created

src/Identifier/Normalizer/IntegerDenormalizer.php (1 issue)

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
Bug Best Practice introduced by
The expression return (int)$data returns the type integer which is incompatible with the return type mandated by Symfony\Component\Serial...nterface::denormalize() of object.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
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