Module   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 20
c 3
b 0
f 0
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceConfig() 0 3 1
A init() 0 23 1
A getAutoloaderConfig() 0 3 1
A getConfig() 0 3 1
1
<?php
2
3
namespace DoctrineDataFixtureModule;
4
5
use Doctrine\ORM\EntityManager;
6
use Symfony\Component\Console\Application;
7
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
8
use Zend\ModuleManager\Feature\ServiceProviderInterface;
9
use Zend\ModuleManager\Feature\ConfigProviderInterface;
10
use Zend\EventManager\EventInterface;
11
use Zend\ModuleManager\ModuleManager;
12
use Doctrine\ORM\Tools\Console\ConsoleRunner;
13
use DoctrineDataFixtureModule\Command\ImportCommand;
14
use DoctrineDataFixtureModule\Service\FixtureFactory;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
/**
18
 * Base module for Doctrine Data Fixture.
19
 *
20
 * @license MIT
21
 * @link    www.doctrine-project.org
22
 * @author  Martin Shwalbe <[email protected]>s
23
 * @author  Rob van der Lee <[email protected]>
24
 */
25
class Module implements
26
    AutoloaderProviderInterface,
27
    ServiceProviderInterface,
28
    ConfigProviderInterface
29
{
30
    /**
31
     * @var ModuleManager
32
     */
33
    protected $moduleManager;
34
35
    /**
36
     * @param ModuleManager $e
37
     */
38
    public function init(ModuleManager $e)
39
    {
40
        $events = $e->getEventManager()->getSharedManager();
41
42
        // Attach to helper set event and load the entity manager helper.
43
        $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
44
            /* @var $cli Application */
45
            $cli = $e->getTarget();
46
            /* @var $sm ServiceLocatorInterface */
47
            $sm = $e->getParam('ServiceManager');
48
            /** @var EntityManager $em */
49
            $em = $cli->getHelperSet()->get('em')->getEntityManager();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not exist on Symfony\Component\Console\Helper\Helper. It seems like you code against a sub-type of Symfony\Component\Console\Helper\Helper such as Doctrine\ORM\Tools\Conso...per\EntityManagerHelper. ( Ignorable by Annotation )

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

49
            $em = $cli->getHelperSet()->get('em')->/** @scrutinizer ignore-call */ getEntityManager();
Loading history...
50
            /** @var array $paths */
51
            $paths = $sm->get('doctrine.configuration.fixtures');
52
53
            $importCommand = new ImportCommand($sm);
54
            $importCommand->setEntityManager($em);
55
            $importCommand->setPaths($paths);
56
57
            ConsoleRunner::addCommands($cli);
58
59
            $cli->addCommands([
60
                $importCommand
61
            ]);
62
        });
63
    }
64
65
    /**
66
     * @return array|mixed|\Traversable
67
     */
68
    public function getConfig()
69
    {
70
        return include __DIR__ . '/../../config/module.config.php';
71
    }
72
73
    /**
74
     * @return array|\Zend\ServiceManager\Config
75
     */
76
    public function getServiceConfig()
77
    {
78
        return ['factories' => $this->getConfig()['factories']];
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    public function getAutoloaderConfig()
85
    {
86
        return ['Zend\Loader\StandardAutoloader' => $this->getConfig()['Zend\Loader\StandardAutoloader']];
87
    }
88
}
89