Passed
Push — master ( 4c0514...b17a5f )
by Nikolay
03:40 queued 10s
created

EditMessageResponseNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 63
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A supportsDenormalization() 0 3 1
A denormalize() 0 8 2
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\DateTimeNormalizer;
10
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
11
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
12
use Symfony\Component\Serializer\Serializer;
13
use TgBotApi\BotApiBase\Type\MessageType;
14
15
/**
16
 * Class UserProfilePhotosNormalizer.
17
 */
18
class EditMessageResponseNormalizer implements DenormalizerInterface
19
{
20
    /**
21
     * @var NormalizerInterface
22
     */
23
    private $objectNormalizer;
24
    /**
25
     * @var ArrayDenormalizer
26
     */
27
    private $arrayDenormalizer;
28
29
    /**
30
     * @var DateTimeNormalizer
31
     */
32
    private $dateNormalizer;
33
34
    /**
35
     * UserProfilePhotosNormalizer constructor.
36
     *
37
     * @param NormalizerInterface $objectNormalizer
38
     * @param ArrayDenormalizer   $arrayDenormalizer
39
     * @param DateTimeNormalizer  $dateNormalizer
40
     */
41 48
    public function __construct(
42
        NormalizerInterface $objectNormalizer,
43
        ArrayDenormalizer $arrayDenormalizer,
44
        DateTimeNormalizer $dateNormalizer
45
    ) {
46 48
        $this->objectNormalizer = $objectNormalizer;
47 48
        $this->arrayDenormalizer = $arrayDenormalizer;
48 48
        $this->dateNormalizer = $dateNormalizer;
49 48
    }
50
51
    /**
52
     * @param mixed  $data
53
     * @param string $class
54
     * @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...
55
     * @param array  $context
56
     *
57
     * @throws ExceptionInterface
58
     *
59
     * @return MessageType | bool
60
     */
61 14
    public function denormalize($data, $class, $format = null, array $context = [])
62
    {
63 14
        if (\is_bool($data)) {
64 11
            return $data;
65
        }
66 3
        $serializer = new Serializer([$this->dateNormalizer, $this->objectNormalizer, $this->arrayDenormalizer]);
67
68 3
        return $serializer->denormalize($data, MessageType::class, $format, $context);
69
    }
70
71
    /**
72
     * @param mixed  $data
73
     * @param string $type
74
     * @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...
75
     *
76
     * @return bool
77
     */
78 46
    public function supportsDenormalization($data, $type, $format = null): bool
79
    {
80 46
        return MessageType::class . '|bool' === $type;
81
    }
82
}
83