CallableDenormalizationObjectMapping   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 49
ccs 8
cts 8
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDenormalizationFieldMappings() 0 3 1
A getMapping() 0 8 2
A __construct() 0 4 1
A getDenormalizationFactory() 0 3 1
A getClass() 0 3 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
    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