createRDMMappingDriver()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 18
ccs 8
cts 8
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Mapping\DriverFactories;
12
13
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverFactoryInterface;
14
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
15
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
16
use Psr\Cache\CacheItemPoolInterface;
17
use Addiks\RDMBundle\Mapping\Drivers\CachedMappingDriver;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
20
final class CachedMappingDriverFactory implements MappingDriverFactoryInterface
21
{
22
23
    /**
24
     * @var MappingDriverFactoryInterface
25
     */
26
    private $innerMappingDriverFactory;
27
28
    /**
29
     * @var CacheItemPoolInterface
30
     */
31
    private $cacheItemPool;
32
33
    /**
34
     * @var ContainerInterface
35
     */
36
    private $container;
37
38 7
    public function __construct(
39
        ContainerInterface $container,
40
        MappingDriverFactoryInterface $innerMappingDriverFactory,
41
        CacheItemPoolInterface $cacheItemPool
42
    ) {
43 7
        $this->container = $container;
44 7
        $this->innerMappingDriverFactory = $innerMappingDriverFactory;
45 7
        $this->cacheItemPool = $cacheItemPool;
46
    }
47
48 7
    public function createRDMMappingDriver(
49
        MappingDriver $mappingDriver
50
    ): ?MappingDriverInterface {
51
        /** @var ?MappingDriverInterface $rdmMappingDriver */
52 7
        $rdmMappingDriver = null;
53
54
        /** @var MappingDriverInterface $innerRdmMappingDriver */
55 7
        $innerRdmMappingDriver = $this->innerMappingDriverFactory->createRDMMappingDriver($mappingDriver);
56
57 7
        if ($innerRdmMappingDriver instanceof MappingDriverInterface) {
0 ignored issues
show
introduced by
$innerRdmMappingDriver is always a sub-type of Addiks\RDMBundle\Mapping...\MappingDriverInterface.
Loading history...
58 7
            $rdmMappingDriver = new CachedMappingDriver(
59
                $innerRdmMappingDriver,
60 7
                $this->container,
61 7
                $this->cacheItemPool
62
            );
63
        }
64
65 7
        return $rdmMappingDriver;
66
    }
67
68
}
69