MappingPHPDriver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\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