Passed
Push — master ( 1e174e...1d1a97 )
by Dominik
04:45
created

CallableDenormalizationObjectMapping::getClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Mapping;
6
7
final class CallableDenormalizationObjectMapping implements DenormalizationObjectMappingInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $class;
13
14
    /**
15
     * @var callable
16
     */
17
    private $callable;
18
19
    /**
20
     * @var DenormalizationObjectMappingInterface|null
21
     */
22
    private $mapping;
23
24
    /**
25
     * @param string   $class
26
     * @param callable $callable
27
     */
28 3
    public function __construct(string $class, callable $callable)
29
    {
30 3
        $this->class = $class;
31 3
        $this->callable = $callable;
32 3
    }
33
34
    /**
35
     * @return string
36
     */
37 1
    public function getClass(): string
38
    {
39 1
        return $this->class;
40
    }
41
42
    /**
43
     * @param string      $path
44
     * @param string|null $type
45
     *
46
     * @return callable
47
     */
48 1
    public function getDenormalizationFactory(string $path, string $type = null): callable
49
    {
50 1
        return $this->getMapping()->getDenormalizationFactory($path, $type);
51
    }
52
53
    /**
54
     * @param string      $path
55
     * @param string|null $type
56
     *
57
     * @return DenormalizationFieldMappingInterface[]
58
     */
59 1
    public function getDenormalizationFieldMappings(string $path, string $type = null): array
60
    {
61 1
        return $this->getMapping()->getDenormalizationFieldMappings($path, $type);
62
    }
63
64
    /**
65
     * @return DenormalizationObjectMappingInterface
66
     */
67 2
    private function getMapping(): DenormalizationObjectMappingInterface
68
    {
69 2
        if (null === $this->mapping) {
70 2
            $callable = $this->callable;
71 2
            $this->mapping = $callable();
72
        }
73
74 2
        return $this->mapping;
75
    }
76
}
77