Completed
Pull Request — master (#459)
by Vytautas
13:28 queued 09:14
created

EntityResolverFactory::__invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 12
cts 13
cp 0.9231
rs 9.2
cc 3
eloc 12
nc 4
nop 3
crap 3.004
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
     */
34 56
    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
        /* @var $options \DoctrineORMModule\Options\EntityResolver */
37 56
        $options      = $this->getOptions($container, 'entity_resolver');
0 ignored issues
show
Compatibility introduced by
$container of type object<Interop\Container\ContainerInterface> is not a sub-type of object<Zend\ServiceManag...erviceLocatorInterface>. It seems like you assume a child interface of the interface Interop\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

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