getDenormalizationFieldMappings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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
    public function __construct(string $class, callable $callable)
25
    {
26
        $this->class = $class;
27
        $this->callable = $callable;
28 3
    }
29
30 3
    public function getClass(): string
31 3
    {
32 3
        return $this->class;
33
    }
34
35
    public function getDenormalizationFactory(string $path, string $type = null): callable
36
    {
37 1
        return $this->getMapping()->getDenormalizationFactory($path, $type);
38
    }
39 1
40
    /**
41
     * @return DenormalizationFieldMappingInterface[]
42
     */
43
    public function getDenormalizationFieldMappings(string $path, string $type = null): array
44
    {
45
        return $this->getMapping()->getDenormalizationFieldMappings($path, $type);
46
    }
47
48 1
    private function getMapping(): DenormalizationObjectMappingInterface
49
    {
50 1
        if (null === $this->mapping) {
51
            $callable = $this->callable;
52
            $this->mapping = $callable();
53
        }
54
55
        return $this->mapping;
56
    }
57
}
58