Completed
Push — master ( d4cfd0...1c3910 )
by Antoine
18s queued 10s
created

IntegerDenormalizer::supportsDenormalization()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
eloc 1
nc 2
nop 3
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\DenormalizerInterface;
18
19
final class IntegerDenormalizer implements DenormalizerInterface
20
{
21
    public function denormalize($data, $class, $format = null, array $context = []): int
22
    {
23
        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...
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function supportsDenormalization($data, $type, $format = null): bool
30
    {
31
        return Type::BUILTIN_TYPE_INT === $type && \is_string($data);
32
    }
33
}
34