Completed
Push — master ( a3231e...8de51f )
by Dominik
02:02
created

FieldDenormalizer::getDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Denormalizer;
6
7
use Chubbyphp\Deserialization\Accessor\AccessorInterface;
8
9
final class FieldDenormalizer implements FieldDenormalizerInterface
10
{
11
    /**
12
     * @var AccessorInterface
13
     */
14
    private $accessor;
15
16
    /**
17
     * @var mixed
18
     */
19
    private $default;
20
21
    public function __construct(AccessorInterface $accessor, $default = null)
22
    {
23
        $this->accessor = $accessor;
24
        $this->default = $default;
25
    }
26
27
    /**
28
     * @param string                            $path
29
     * @param object                            $object
30
     * @param mixed                             $value
31
     * @param DenormalizerInterface|null        $denormalizer
32
     * @param DenormalizerContextInterface|null $context
33
     */
34
    public function denormalizeField(
35
        string $path,
36
        $object,
37
        $value,
38
        DenormalizerInterface $denormalizer = null,
39
        DenormalizerContextInterface $context = null
40
    ) {
41
        $this->accessor->setValue($object, $value);
42
    }
43
44
    /**
45
     * @return mixed|null
46
     */
47
    public function getDefault()
48
    {
49
        return $this->default;
50
    }
51
}
52