Module::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 1
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 DoctrineFixturesModule;
21
22
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
23
use Zend\ModuleManager\Feature\ServiceProviderInterface;
24
use Zend\ModuleManager\Feature\ConfigProviderInterface;
25
use Zend\EventManager\EventInterface;
26
use Zend\ModuleManager\ModuleManager;
27
use Doctrine\ORM\Tools\Console\ConsoleRunner;
28
use DoctrineFixturesModule\Command\LoadCommand;
29
use DoctrineFixturesModule\Service\FixtureFactory;
30
31
/**
32
 * Base module for Doctrine Data Fixture.
33
 *
34
 * @license MIT
35
 * @link    www.doctrine-project.org
36
 * @author  Kenneth Kataiwa <[email protected]>
37
 */
38
class Module implements
39
    AutoloaderProviderInterface,
40
    ServiceProviderInterface,
41
    ConfigProviderInterface
42
{
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function getAutoloaderConfig()
47
    {
48
        return array(
49
            'Zend\Loader\StandardAutoloader' => array(
50
                'namespaces' => array(
51
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
52
                ),
53
            ),
54
        );
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function init(ModuleManager $e)
61
    {
62
        $events = $e->getEventManager()->getSharedManager();
63
64
        // Attach to helper set event and load the entity manager helper.
65
        $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
66
            /* @var $cli \Symfony\Component\Console\Application */
67
            $cli = $e->getTarget();
68
69
            /* @var $sm ServiceLocatorInterface */
70
            $sm = $e->getParam('ServiceManager');
71
            $em = $cli->getHelperSet()->get('em')->getEntityManager();
72
            $paths = $sm->get('doctrine.configuration.fixtures');
73
74
            $loadCommand = new LoadCommand($sm);
75
            $loadCommand->setEntityManager($em);
76
            $loadCommand->setPath($paths);
77
            ConsoleRunner::addCommands($cli);
78
            $cli->addCommands(array(
79
                $loadCommand
80
            ));
81
        });
82
    }
83
84
    /**
85
     * {@inheritDoc}
86
     */
87
    public function getConfig()
88
    {
89
        return include __DIR__ . '/../../config/module.config.php';
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function getServiceConfig()
96
    {
97
        return array(
98
            'factories' => array(
99
                'doctrine.configuration.fixtures' => new FixtureFactory('fixtures_default'),
0 ignored issues
show
Unused Code introduced by
The call to FixtureFactory::__construct() has too many arguments starting with 'fixtures_default'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
100
            ),
101
        );
102
    }
103
}
104