DefaultJsonDeserializationContext::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\Internal;
10
11
use Tebru\Gson\Context\ReaderContext;
12
use Tebru\Gson\JsonDeserializationContext;
13
use Tebru\PhpType\TypeToken;
14
15
/**
16
 * Class DefaultJsonDeserializationContext
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20
final class DefaultJsonDeserializationContext implements JsonDeserializationContext
21
{
22
    /**
23
     * @var TypeAdapterProvider
24
     */
25
    private $typeAdapterProvider;
26
27
    /**
28
     * @var ReaderContext
29
     */
30
    private $context;
31
32
    /**
33
     * Constructor
34
     *
35
     * @param TypeAdapterProvider $typeAdapterProvider
36
     * @param ReaderContext $context
37
     */
38 4
    public function __construct(TypeAdapterProvider $typeAdapterProvider, ReaderContext $context)
39
    {
40 4
        $this->typeAdapterProvider = $typeAdapterProvider;
41 4
        $this->context = $context;
42 4
    }
43
44
    /**
45
     * Delegate deserialization of normalized data.  Should not be called on the original
46
     * element as doing so will result in an infinite loop.  Should return a deserialized
47
     * object.
48
     *
49
     * @param mixed $value
50
     * @param string $type
51
     * @return mixed
52
     */
53 4
    public function deserialize($value, string $type)
54
    {
55 4
        $typeAdapter = $this->typeAdapterProvider->getAdapter(TypeToken::create($type));
56
57 4
        return $typeAdapter->read($value, $this->context);
58
    }
59
}
60