MediaGroupNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A normalize() 0 6 1
A __construct() 0 4 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\SendMediaGroupMethod;
11
12
/**
13
 * Class MediaGroupNormalizer.
14
 */
15
class MediaGroupNormalizer 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
     * @param InputMediaNormalizer $inputMediaNormalizer
30
     * @param NormalizerInterface  $objectNormalizer
31
     */
32 120
    public function __construct(InputMediaNormalizer $inputMediaNormalizer, NormalizerInterface $objectNormalizer)
33
    {
34 120
        $this->inputMediaNormalizer = $inputMediaNormalizer;
35 120
        $this->objectNormalizer = $objectNormalizer;
36 120
    }
37
38
    /**
39
     * @param mixed $topic
40
     * @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...
41
     * @param array $context
42
     *
43
     * @throws ExceptionInterface
44
     *
45
     * @return array|bool|float|int|mixed|string
46
     */
47 1
    public function normalize($topic, $format = null, array $context = [])
48
    {
49 1
        $serializer = new Serializer([$this->inputMediaNormalizer, $this->objectNormalizer]);
50 1
        $topic->media = \json_encode($serializer->normalize($topic->media, null, ['skip_null_values' => true]));
51
52 1
        return $serializer->normalize($topic, null, ['skip_null_values' => true]);
53
    }
54
55
    /**
56
     * @param mixed $data
57
     * @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...
58
     *
59
     * @return bool
60
     */
61 117
    public function supportsNormalization($data, $format = null): bool
62
    {
63 117
        return $data instanceof SendMediaGroupMethod;
64
    }
65
}
66