Passed
Push — master ( edf8ee...072d65 )
by Dominik
04:11
created

getNormalizationEmbeddedFieldMappings()   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 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Mapping;
6
7
final class CallableNormalizationObjectMapping implements NormalizationObjectMappingInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $class;
13
14
    /**
15
     * @var callable
16
     */
17
    private $callable;
18
19
    /**
20
     * @var NormalizationObjectMappingInterface|null
21
     */
22
    private $mapping;
23
24
    /**
25
     * @param string   $class
26
     * @param callable $callable
27
     */
28 5
    public function __construct(string $class, callable $callable)
29
    {
30 5
        $this->class = $class;
31 5
        $this->callable = $callable;
32 5
    }
33
34
    /**
35
     * @return string
36
     */
37 1
    public function getClass(): string
38
    {
39 1
        return $this->class;
40
    }
41
42
    /**
43
     * @return string
44
     */
45 1
    public function getNormalizationType(): string
46
    {
47 1
        return $this->getMapping()->getNormalizationType();
48
    }
49
50
    /**
51
     * @param string $path
52
     *
53
     * @return NormalizationFieldMappingInterface[]
54
     */
55 1
    public function getNormalizationFieldMappings(string $path): array
56
    {
57 1
        return $this->getMapping()->getNormalizationFieldMappings($path);
58
    }
59
60
    /**
61
     * @param string $path
62
     *
63
     * @return NormalizationFieldMappingInterface[]
64
     */
65 1
    public function getNormalizationEmbeddedFieldMappings(string $path): array
66
    {
67 1
        return $this->getMapping()->getNormalizationEmbeddedFieldMappings($path);
68
    }
69
70
    /**
71
     * @param string $path
72
     *
73
     * @return NormalizationLinkMappingInterface[]
74
     */
75 1
    public function getNormalizationLinkMappings(string $path): array
76
    {
77 1
        return $this->getMapping()->getNormalizationLinkMappings($path);
78
    }
79
80
    /**
81
     * @return NormalizationObjectMappingInterface
82
     */
83 4
    private function getMapping(): NormalizationObjectMappingInterface
84
    {
85 4
        if (null === $this->mapping) {
86 4
            $callable = $this->callable;
87 4
            $this->mapping = $callable();
88
        }
89
90 4
        return $this->mapping;
91
    }
92
}
93