Completed
Push — master ( 8a5483...1b0f78 )
by Dominik
02:45
created

LazyDenormalizationObjectMapping   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 0
loc 61
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A isDenormalizationResponsible() 0 6 1
A getDenormalizationFactory() 0 4 1
A getDenormalizationFieldMappings() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Mapping;
6
7
use Psr\Container\ContainerInterface;
8
9
final class LazyDenormalizationObjectMapping implements DenormalizationObjectMappingInterface
10
{
11
    /**
12
     * @var ContainerInterface
13
     */
14
    private $container;
15
16
    /**
17
     * @var string
18
     */
19
    private $serviceId;
20
21
    /**
22
     * @var callable
23
     */
24
    private $isDenormalizationResponsible;
25
26
    /**
27
     * @param ContainerInterface $container
28
     * @param string             $serviceId
29
     * @param callable           $isDenormalizationResponsible
30
     */
31 1
    public function __construct(ContainerInterface $container, $serviceId, callable $isDenormalizationResponsible)
32
    {
33 1
        $this->container = $container;
34 1
        $this->serviceId = $serviceId;
35 1
        $this->isDenormalizationResponsible = $isDenormalizationResponsible;
36 1
    }
37
38
    /**
39
     * @param string $class
40
     *
41
     * @return bool
42
     */
43 1
    public function isDenormalizationResponsible(string $class): bool
44
    {
45 1
        $isDenormalizationResponsible = $this->isDenormalizationResponsible;
46
47 1
        return $isDenormalizationResponsible($class);
48
    }
49
50
    /**
51
     * @param string|null $type
52
     *
53
     * @return callable
54
     */
55 1
    public function getDenormalizationFactory(string $type = null): callable
56
    {
57 1
        return $this->container->get($this->serviceId)->getDenormalizationFactory($type);
58
    }
59
60
    /**
61
     * @param string|null $type
62
     *
63
     * @return DenormalizationFieldMappingInterface[]
64
     */
65 1
    public function getDenormalizationFieldMappings(string $type = null): array
66
    {
67 1
        return $this->container->get($this->serviceId)->getDenormalizationFieldMappings($type);
68
    }
69
}
70