Completed
Push — master ( 9ce2ea...baff27 )
by Daniel
12:24
created

MappingDriverProvider::getMappingDriver()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 13
cp 0
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Provider;
9
10
use Doctrine\Common\Annotations\AnnotationReader;
11
use Doctrine\Common\Annotations\AnnotationRegistry;
12
use Doctrine\Common\Annotations\CachedReader;
13
use Doctrine\Common\Cache\Cache;
14
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
15
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
16
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
17
use Gedmo\DoctrineExtensions;
18
use GravityMedia\Commander\Commander;
19
20
/**
21
 * Mapping driver provider class.
22
 *
23
 * @package GravityMedia\Commander\Provider
24
 */
25
class MappingDriverProvider
26
{
27
    /**
28
     * The cache.
29
     *
30
     * @var Cache
31
     */
32
    protected $cache;
33
34
    /**
35
     * The mapping driver.
36
     *
37
     * @var MappingDriver
38
     */
39
    protected $mappingDriver;
40
41
    /**
42
     * Create mapping driver provider object.
43
     *
44
     * @param Cache $cache
45
     */
46
    public function __construct(Cache $cache)
47
    {
48
        $this->cache = $cache;
49
    }
50
51
    /**
52
     * Get mapping driver.
53
     *
54
     * @return MappingDriver
55
     */
56
    public function getMappingDriver()
57
    {
58
        if (null === $this->mappingDriver) {
59
            AnnotationRegistry::registerFile(
60
                __DIR__ . '/../../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
61
            );
62
63
            $driverChain = new MappingDriverChain();
64
            $reader = new CachedReader(new AnnotationReader(), $this->cache);
65
66
            DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $reader);
67
68
            $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../ORM']);
0 ignored issues
show
Documentation introduced by
$reader is of type object<Doctrine\Common\Annotations\CachedReader>, but the function expects a object<Doctrine\Common\A...tions\AnnotationReader>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
            $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE);
70
71
            $this->mappingDriver = $driverChain;
72
        }
73
74
        return $this->mappingDriver;
75
    }
76
}
77