Completed
Push — master ( d8a1ad...d0379b )
by Dominik
02:06
created

Deserializer::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 4
crap 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
    /**
24
     * @param DecoderInterface      $decoder
25
     * @param DenormalizerInterface $denormalizer
26
     */
27 4
    public function __construct(DecoderInterface $decoder, DenormalizerInterface $denormalizer)
28
    {
29 4
        $this->decoder = $decoder;
30 4
        $this->denormalizer = $denormalizer;
31 4
    }
32
33
    /**
34
     * @param object|string                $object
35
     * @param string                       $data
36
     * @param string                       $contentType
37
     * @param DenormalizerContextInterface $context
38
     *
39
     * @return object
40
     */
41 4
    public function deserialize(
42
        $object,
43
        string $data,
44
        string $contentType,
45
        DenormalizerContextInterface $context = null
46
    ) {
47 4
        return $this->denormalizer->denormalize($object, $this->decoder->decode($data, $contentType), $context);
48
    }
49
}
50