Passed
Push — master ( b03250...d3ef14 )
by Nikolay
55s queued 15s
created

PollNormalizer::supportsNormalization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
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\SendPollMethod;
11
12
class PollNormalizer implements NormalizerInterface
13
{
14
    /**
15
     * @var NormalizerInterface
16
     */
17
    private $objectNormalizer;
18
19
    /**
20
     * JsonSerializableNormalizer constructor.
21
     */
22 285
    public function __construct(NormalizerInterface $objectNormalizer)
23
    {
24 285
        $this->objectNormalizer = $objectNormalizer;
25 285
    }
26
27
    /**
28
     * @param mixed $topic
29
     * @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...
30
     *
31
     * @throws ExceptionInterface
32
     *
33
     * @return array|bool|false|float|int|string
34
     */
35 3
    public function normalize($topic, $format = null, array $context = [])
36
    {
37 3
        $serializer = new Serializer([
38 3
            new JsonSerializableNormalizer($this->objectNormalizer),
39 3
            $this->objectNormalizer,
40
        ]);
41
42 3
        $topic->options = \json_encode($topic->options);
43
44 3
        return $serializer->normalize($topic, null, ['skip_null_values' => true]);
45
    }
46
47
    /**
48
     * @param mixed $data
49
     * @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...
50
     */
51 285
    public function supportsNormalization($data, $format = null): bool
52
    {
53 285
        return $data instanceof SendPollMethod;
54
    }
55
}
56