MappingPHPDriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
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 43
ccs 13
cts 13
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadRDMMetadataForClass() 0 30 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\Drivers;
12
13
use Doctrine\Persistence\Mapping\Driver\FileLocator;
14
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
15
use Addiks\RDMBundle\Mapping\EntityMappingInterface;
16
17
final class MappingPHPDriver implements MappingDriverInterface
18
{
19
20
    /**
21
     * @var FileLocator
22
     */
23
    private $fileLocator;
24
25 2
    public function __construct(FileLocator $fileLocator)
26
    {
27 2
        $this->fileLocator = $fileLocator;
28
    }
29
30 1
    public function loadRDMMetadataForClass(string $className): ?EntityMappingInterface
31
    {
32
        /** @var ?EntityMappingInterface $mapping */
33 1
        $mapping = null;
34
35 1
        if ($this->fileLocator->fileExists($className)) {
36
            /** @var string $mappingFile */
37 1
            $mappingFile = $this->fileLocator->findMappingFile($className);
38
39 1
            if (file_exists($mappingFile)) {
40
                /** @var mixed $mappingCandidate */
41 1
                $mappingCandidate = null;
42
43
                (
44
                    /**
45
                     * @param mixed $rdmMapping
46
                     */
47 1
                    function (&$rdmMapping) use ($mappingFile): void {
48
                        /** @psalm-suppress UnresolvableInclude */
49 1
                        include $mappingFile;
50
                    }
51
                )($mappingCandidate);
52
53 1
                if ($mappingCandidate instanceof EntityMappingInterface) {
54 1
                    $mapping = $mappingCandidate;
55
                }
56
            }
57
        }
58
59 1
        return $mapping;
60
    }
61
62
}
63