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

CallableDenormalizationObjectMapping   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 70
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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