MappingDriverChainFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createRDMMappingDriver() 0 29 4
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 Doctrine\Persistence\Mapping\Driver\MappingDriver;
14
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
15
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverFactoryInterface;
16
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
17
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverChain as RDMMappingDriverChain;
18
19
final class MappingDriverChainFactory implements MappingDriverFactoryInterface
20
{
21
22
    /**
23
     * @var MappingDriverFactoryInterface
24
     */
25
    private $rootMetadataDriverFactory;
26
27 7
    public function __construct(MappingDriverFactoryInterface $rootMetadataDriverFactory)
28
    {
29 7
        $this->rootMetadataDriverFactory = $rootMetadataDriverFactory;
30
    }
31
32 7
    public function createRDMMappingDriver(
33
        MappingDriver $mappingDriver
34
    ): ?MappingDriverInterface {
35
        /** @var ?MappingDriverInterface $rdmMetadataDriver */
36 7
        $rdmMetadataDriver = null;
37
38 7
        if ($mappingDriver instanceof MappingDriverChain) {
39
            /** @var MappingDriverChain $mappingDriverChain */
40 7
            $mappingDriverChain = $mappingDriver;
41
42
            /** @var array<MappingDriverFactoryInterface> $subRDMMetadataDrivers */
43 7
            $subRDMMetadataDrivers = array();
44
45 7
            foreach ($mappingDriverChain->getDrivers() as $subMappingDriver) {
46
                /** @var MappingDriver $subMappingDriver */
47
48 7
                $subRDMMetadataDriver = $this->rootMetadataDriverFactory->createRDMMappingDriver(
49
                    $subMappingDriver
50
                );
51
52 7
                if ($subRDMMetadataDriver instanceof MappingDriverInterface) {
53 7
                    $subRDMMetadataDrivers[] = $subRDMMetadataDriver;
54
                }
55
            }
56
57 7
            $rdmMetadataDriver = new RDMMappingDriverChain($subRDMMetadataDrivers);
58
        }
59
60 7
        return $rdmMetadataDriver;
61
    }
62
63
}
64