Passed
Push — master ( fdd4b3...1c867d )
by Nikolay
01:45 queued 40s
created

EditMessageMediaNormalizer::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 7
c 1
b 1
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
cc 1
nc 1
nop 3
crap 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\EditMessageMediaMethod;
11
12
/**
13
 * Class MediaGroupNormalizer.
14
 */
15
class EditMessageMediaNormalizer implements NormalizerInterface
16
{
17
    /**
18
     * @var InputMediaNormalizer
19
     */
20
    private $inputMediaNormalizer;
21
    /**
22
     * @var NormalizerInterface
23
     */
24
    private $objectNormalizer;
25
26
    /**
27
     * MediaGroupNormalizer constructor.
28
     */
29 309
    public function __construct(
30
        InputMediaNormalizer $inputMediaNormalizer,
31
        NormalizerInterface $objectNormalizer
32
    ) {
33 309
        $this->inputMediaNormalizer = $inputMediaNormalizer;
34 309
        $this->objectNormalizer = $objectNormalizer;
35 309
    }
36
37
    /**
38
     * @param EditMessageMediaMethod $topic
39
     * @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...
40
     *
41
     * @throws ExceptionInterface
42
     *
43
     * @return array|bool|float|int|mixed|string
44
     */
45 12
    public function normalize($topic, $format = null, array $context = [])
46
    {
47 12
        $serializer = new Serializer([
48 12
            $this->inputMediaNormalizer,
49 12
            new JsonSerializableNormalizer($this->objectNormalizer),
50 12
            $this->objectNormalizer,
51
        ]);
52 12
        $topic->media = \json_encode($serializer->normalize($topic->media, 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\InputMedia\InputMediaType of property $media.

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...
53
54 12
        $topic->replyMarkup = $serializer->normalize($topic->replyMarkup, null, ['skip_null_values' => true]);
55
56 12
        return $serializer->normalize($topic, null, ['skip_null_values' => true]);
57
    }
58
59
    /**
60
     * @param mixed $data
61
     * @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...
62
     */
63 297
    public function supportsNormalization($data, $format = null): bool
64
    {
65 297
        return $data instanceof EditMessageMediaMethod;
66
    }
67
}
68