Completed
Pull Request — master (#459)
by Vytautas
09:31
created

EntityResolverFactory::__invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
rs 9.2
cc 3
eloc 12
nc 4
nop 3
crap 3.0052
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModule\Service;
21
22
use Doctrine\Common\EventSubscriber;
23
use Doctrine\ORM\Events;
24
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
25
use DoctrineModule\Service\AbstractFactory;
26
use Interop\Container\ContainerInterface;
27
use Zend\ServiceManager\ServiceLocatorInterface;
28
29
class EntityResolverFactory extends AbstractFactory
30
{
31
    /**
32
     * {@inheritDoc}
33 56
     */
34
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
0 ignored issues
show
Unused Code introduced by
The parameter $requestedName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36 56
        /* @var $options \DoctrineORMModule\Options\EntityResolver */
37 56
        $options      = $this->getOptions($container, 'entity_resolver');
0 ignored issues
show
Documentation introduced by
$container is of type object<Interop\Container\ContainerInterface>, but the function expects a object<Zend\ServiceManag...erviceLocatorInterface>.

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...
38 56
        $eventManager = $container->get($options->getEventManager());
39
        $resolvers    = $options->getResolvers();
40 56
41
        $targetEntityListener = new ResolveTargetEntityListener();
42 56
43 56
        foreach ($resolvers as $oldEntity => $newEntity) {
44 56
            $targetEntityListener->addResolveTargetEntity($oldEntity, $newEntity, array());
45
        }
46
47 56
        // Starting from Doctrine ORM 2.5, the listener implements EventSubscriber
48 56
        if ($targetEntityListener instanceof EventSubscriber) {
49 56
            $eventManager->addEventSubscriber($targetEntityListener);
50
        } else {
51
            $eventManager->addEventListener(Events::loadClassMetadata, $targetEntityListener);
52
        }
53 56
54
        return $eventManager;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function createService(ServiceLocatorInterface $container)
61 56
    {
62
        return $this($container, \Zend\EventManager\EventManager::class);
63 56
    }
64
65
    /**
66
     * Get the class name of the options associated with this factory.
67
     *
68
     * @return string
69
     */
70
    public function getOptionsClass()
71
    {
72
        return 'DoctrineORMModule\Options\EntityResolver';
73
    }
74
}
75