Passed
Push — master ( 3bfee0...112fc6 )
by Nikolay
02:02
created

InputFileNormalizer::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
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\Normalizer\NormalizerInterface;
8
use TgBotApi\BotApiBase\Type\InputFileType;
9
10
class InputFileNormalizer implements NormalizerInterface
11
{
12
    private $files;
13
14 63
    public function __construct(&$files)
15
    {
16 63
        $this->files = &$files;
17 63
    }
18
19 3
    public function normalize($topic, $format = null, array $context = [])
20
    {
21 3
        $uniqid = \uniqid();
22 3
        $this->files[$uniqid] = $topic->file;
23
24 3
        return 'attach://' . $uniqid;
25
    }
26
27 63
    public function supportsNormalization($data, $format = null)
28
    {
29 63
        return $data instanceof InputFileType;
30
    }
31
}
32