AnswerInlineQueryNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 50
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A normalize() 0 14 1
A supportsNormalization() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Normalizer;
6
7
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
8
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
9
use Symfony\Component\Serializer\Serializer;
10
use TgBotApi\BotApiBase\Method\AnswerInlineQueryMethod;
11
12
/**
13
 * Class AnswerInlineQueryNormalizer.
14
 */
15
class AnswerInlineQueryNormalizer implements NormalizerInterface
16
{
17
    /**
18
     * @var NormalizerInterface
19
     */
20
    private $objectNormalizer;
21
22
    /**
23
     * AnswerInlineQueryNormalizer constructor.
24
     *
25
     * @param NormalizerInterface $objectNormalizer
26
     */
27 120
    public function __construct(NormalizerInterface $objectNormalizer)
28
    {
29 120
        $this->objectNormalizer = $objectNormalizer;
30 120
    }
31
32
    /**
33
     * @param mixed $topic
34
     * @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...
35
     * @param array $context
36
     *
37
     * @return array|bool|float|int|mixed|string
38
     */
39 2
    public function normalize($topic, $format = null, array $context = [])
40
    {
41 2
        $serializer = new Serializer([new DateTimeNormalizer(), $this->objectNormalizer]);
42
43 2
        $topic->results = \json_encode($serializer->normalize(
44 2
            $topic->results,
45 2
            null,
46 2
            ['skip_null_values' => true, DateTimeNormalizer::FORMAT_KEY => 'U']
47
        ));
48
49 2
        return $serializer->normalize(
50 2
            $topic,
51 2
            null,
52 2
            ['skip_null_values' => true, DateTimeNormalizer::FORMAT_KEY => 'U']
53
        );
54
    }
55
56
    /**
57
     * @param mixed $data
58
     * @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...
59
     *
60
     * @return bool
61
     */
62 112
    public function supportsNormalization($data, $format = null): bool
63
    {
64 112
        return $data instanceof AnswerInlineQueryMethod;
65
    }
66
}
67