Completed
Push — master ( d60737...066901 )
by Nikolay
19s queued 12s
created

SetChatMenuButtonNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 9
c 1
b 0
f 1
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A __construct() 0 3 1
A normalize() 0 10 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\NormalizerInterface;
9
use Symfony\Component\Serializer\Serializer;
10
use TgBotApi\BotApiBase\Method\SetChatMenuButtonMethod;
11
12
/**
13
 * Class SetChatMenuButtonNormalizer.
14
 */
15
class SetChatMenuButtonNormalizer implements NormalizerInterface
16
{
17
    /**
18
     * @var NormalizerInterface
19
     */
20
    private $objectNormalizer;
21
22
    /**
23
     * JsonSerializableNormalizer constructor.
24
     */
25
    public function __construct(NormalizerInterface $objectNormalizer)
26
    {
27
        $this->objectNormalizer = $objectNormalizer;
28
    }
29
30
    /**
31
     * @param SetChatMenuButtonMethod $topic
32
     * @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...
33
     *
34
     * @throws ExceptionInterface
35
     *
36
     * @return array|bool|false|float|int|string
37
     */
38
    public function normalize($topic, $format = null, array $context = [])
39
    {
40
        $serializer = new Serializer([
41
            new JsonSerializableNormalizer($this->objectNormalizer),
42
            $this->objectNormalizer,
43
        ]);
44
45
        $topic->menuButton = \json_encode($serializer->normalize($topic->menuButton, null, ['skip_null_values' => true]));
0 ignored issues
show
Documentation Bug introduced by
It seems like json_encode($serializer-...null_values' => true))) of type string is incompatible with the declared type TgBotApi\BotApiBase\Type\MenuButtonType|null of property $menuButton.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
47
        return $serializer->normalize($topic, null, ['skip_null_values' => true]);
48
    }
49
50
    /**
51
     * @param mixed $data
52
     * @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...
53
     */
54
    public function supportsNormalization($data, $format = null): bool
55
    {
56
        return $data instanceof SetChatMenuButtonMethod;
57
    }
58
}
59