Deserializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
c 2
b 0
f 1
dl 0
loc 61
ccs 10
cts 10
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 3 1
A getContentTypes() 0 3 1
A deserialize() 0 8 1
A denormalize() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization;
6
7
use Chubbyphp\Deserialization\Decoder\DecoderInterface;
8
use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
9
use Chubbyphp\Deserialization\Denormalizer\DenormalizerInterface;
10
11
final class Deserializer implements DeserializerInterface
12
{
13
    /**
14
     * @var DecoderInterface
15
     */
16
    private $decoder;
17
18
    /**
19
     * @var DenormalizerInterface
20
     */
21
    private $denormalizer;
22
23
    public function __construct(DecoderInterface $decoder, DenormalizerInterface $denormalizer)
24
    {
25
        $this->decoder = $decoder;
26
        $this->denormalizer = $denormalizer;
27 4
    }
28
29 4
    /**
30 4
     * @param object|string $object
31 4
     *
32
     * @return object
33
     */
34
    public function deserialize(
35
        $object,
36
        string $data,
37
        string $contentType,
38
        DenormalizerContextInterface $context = null,
39
        string $path = ''
40
    ) {
41
        return $this->denormalizer->denormalize($object, $this->decoder->decode($data, $contentType), $context, $path);
42 1
    }
43
44
    /**
45
     * @return string[]
46
     */
47
    public function getContentTypes(): array
48
    {
49 1
        return $this->decoder->getContentTypes();
50
    }
51
52
    /**
53
     * @throws DeserializerLogicException
54
     * @throws DeserializerRuntimeException
55 1
     */
56
    public function decode(string $data, string $contentType): array
57 1
    {
58
        return $this->decoder->decode($data, $contentType);
59
    }
60
61
    /**
62
     * @param object|string $object
63
     *
64
     * @throws DeserializerLogicException
65
     * @throws DeserializerRuntimeException
66
     *
67
     * @return object
68
     */
69 1
    public function denormalize($object, array $data, DenormalizerContextInterface $context = null, string $path = '')
70
    {
71 1
        return $this->denormalizer->denormalize($object, $data, $context, $path);
72
    }
73
}
74