Completed
Push — master ( 62cb7b...4b7fdd )
by Nikolay
02:34
created

MediaGroupNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 22
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 __construct() 0 4 1
A normalize() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Normalizer;
6
7
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
8
use Symfony\Component\Serializer\Serializer;
9
use TgBotApi\BotApiBase\Method\SendMediaGroupMethod;
10
11
class MediaGroupNormalizer implements NormalizerInterface
12
{
13
    private $inputMediaNormalizer;
14
    private $objectNormalizer;
15
16 39
    public function __construct(InputMediaNormalizer $inputMediaNormalizer, NormalizerInterface $objectNormalizer)
17
    {
18 39
        $this->inputMediaNormalizer = $inputMediaNormalizer;
19 39
        $this->objectNormalizer = $objectNormalizer;
20 39
    }
21
22 1
    public function normalize($topic, $format = null, array $context = [])
23
    {
24 1
        $serializer = new Serializer([$this->inputMediaNormalizer, $this->objectNormalizer]);
25 1
        $topic->media = \json_encode($serializer->normalize($topic->media, null, ['skip_null_values' => true]));
26
27 1
        return $serializer->normalize($topic, null, ['skip_null_values' => true]);
28
    }
29
30 39
    public function supportsNormalization($data, $format = null)
31
    {
32 39
        return $data instanceof SendMediaGroupMethod;
33
    }
34
}
35