MappingDriverFactoryLazyLoadProxy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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 Symfony\Component\DependencyInjection\ContainerInterface;
14
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
15
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverFactoryInterface;
16
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
17
use ErrorException;
18
use Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver as DoctrineBundleMappingDriver;
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\Doctrine...e\Mapping\MappingDriver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
/**
21
 * Circumvents the symfony "circular reference" error by lazy-loading.
22
 */
23
final class MappingDriverFactoryLazyLoadProxy implements MappingDriverFactoryInterface
24
{
25
26
    /**
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * @var string
33
     */
34
    private $serviceId;
35
36
    /**
37
     * @var ?MappingDriverFactoryInterface
38
     */
39
    private $actualMappingDriverFactory;
40 7
41
    public function __construct(ContainerInterface $container, string $serviceId)
42 7
    {
43 7
        $this->container = $container;
44
        $this->serviceId = $serviceId;
45
    }
46 7
47
    public function createRDMMappingDriver(
48
        MappingDriver $mappingDriver
49 7
    ): ?MappingDriverInterface {
50
        if (is_null($this->actualMappingDriverFactory)) {
51 7
            /** @var object $actualMappingDriverFactory */
52 7
            $actualMappingDriverFactory = $this->container->get(
53
                $this->serviceId,
54
                ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE
55
            );
56 7
57 7
            if ($actualMappingDriverFactory instanceof MappingDriverFactoryInterface) {
58
                $this->actualMappingDriverFactory = $actualMappingDriverFactory;
59
60
            } else {
61
                throw new ErrorException(sprintf(
62
                    "The service '%s' is not an instance of %s!",
63
                    $this->serviceId,
64
                    MappingDriverFactoryInterface::class
65
                ));
66
            }
67
        }
68 7
        
69
        if ($mappingDriver instanceof DoctrineBundleMappingDriver) {
70
            $mappingDriver = $mappingDriver->getDriver();
0 ignored issues
show
Bug introduced by
The method getDriver() does not exist on Doctrine\Persistence\Mapping\Driver\MappingDriver. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
            /** @scrutinizer ignore-call */ 
71
            $mappingDriver = $mappingDriver->getDriver();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
        }
72
73
        return $this->actualMappingDriverFactory->createRDMMappingDriver($mappingDriver);
74
    }
75
76
}
77