UserProfilePhotosNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
eloc 9
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A denormalize() 0 6 1
A __construct() 0 4 1
A supportsDenormalization() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Normalizer;
6
7
use Symfony\Component\Serializer\Exception\ExceptionInterface;
8
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
9
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
10
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
11
use Symfony\Component\Serializer\Serializer;
12
use TgBotApi\BotApiBase\Type\PhotoSizeType;
13
use TgBotApi\BotApiBase\Type\UserProfilePhotosType;
14
15
/**
16
 * Class UserProfilePhotosNormalizer.
17
 */
18
class UserProfilePhotosNormalizer implements DenormalizerInterface
19
{
20
    /**
21
     * @var NormalizerInterface
22
     */
23
    private $objectNormalizer;
24
    /**
25
     * @var ArrayDenormalizer
26
     */
27
    private $arrayDenormalizer;
28
29
    /**
30
     * UserProfilePhotosNormalizer constructor.
31
     */
32 61
    public function __construct(NormalizerInterface $objectNormalizer, ArrayDenormalizer $arrayDenormalizer)
33
    {
34 61
        $this->objectNormalizer = $objectNormalizer;
35 61
        $this->arrayDenormalizer = $arrayDenormalizer;
36 61
    }
37
38
    /**
39
     * @param mixed  $data
40
     * @param string $class
41
     * @param null   $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
42
     *
43
     * @throws ExceptionInterface
44
     */
45 2
    public function denormalize($data, $class, $format = null, array $context = []): UserProfilePhotosType
46
    {
47 2
        $serializer = new Serializer([$this->objectNormalizer, $this->arrayDenormalizer]);
48 2
        $data->photos = $serializer->denormalize($data->photos, PhotoSizeType::class . '[][]');
49
50 2
        return $serializer->denormalize($data, UserProfilePhotosType::class);
51
    }
52
53
    /**
54
     * @param mixed  $data
55
     * @param string $type
56
     * @param null   $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
57
     */
58 61
    public function supportsDenormalization($data, $type, $format = null): bool
59
    {
60 61
        return UserProfilePhotosType::class === $type;
61
    }
62
}
63