GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bc496a...73ae4f )
by Андрей
03:11
created

Module::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 2
eloc 11
nc 2
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A Module::getConfig() 0 4 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 64 and the first side effect is on line 37.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @link https://github.com/old-town/workflow-zf2-service
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Workflow\ZF2\Service;
7
8
9
use OldTown\Workflow\ZF2\ServiceEngine\Workflow;
10
use Zend\ModuleManager\ModuleManager;
11
use Zend\ModuleManager\ModuleManagerInterface;
12
use Zend\Mvc\ModuleRouteListener;
13
use Zend\Mvc\MvcEvent;
14
use Zend\EventManager\EventInterface;
15
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
16
use Zend\ModuleManager\Feature\ConfigProviderInterface;
17
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
18
use Zend\ModuleManager\Feature\InitProviderInterface;
19
use Zend\ServiceManager\ServiceLocatorAwareTrait;
20
use Zend\ServiceManager\ServiceLocatorInterface;
21
use Zend\ModuleManager\Listener\ServiceListenerInterface;
22
use OldTown\Workflow\ZF2\Service\Service\Manager;
23
use OldTown\Workflow\ZF2\Service\Service\ProviderInterface;
24
use Zend\ModuleManager\Feature\DependencyIndicatorInterface;
25
use OldTown\Workflow\ZF2\Service\Listener\InjectTypeResolver;
26
use Zend\ModuleManager\Feature\LocatorRegisteredInterface;
27
use OldTown\Workflow\ZF2\Service\Metadata\MetadataReaderManagerInterface;
28
use OldTown\Workflow\ZF2\Service\Options\ModuleOptions;
29
use ReflectionClass;
30
31
32
/**
33
 * Class Module
34
 *
35
 * @package OldTown\Workflow\ZF2\Service
36
 */
37
class Module implements
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
38
    BootstrapListenerInterface,
39
    ConfigProviderInterface,
40
    AutoloaderProviderInterface,
41
    InitProviderInterface,
42
    DependencyIndicatorInterface,
43
    LocatorRegisteredInterface
44
{
45
    use ServiceLocatorAwareTrait;
46
47
    /**
48
     * Имя секции в конфиги приложения
49
     *
50
     * @var string
51
     */
52
    const CONFIG_KEY = 'workflow_zf2_serviceEngine';
53
54
    /**
55
     * Менеджер для работы с метаданными сервисов
56
     *
57
     * @var MetadataReaderManagerInterface
58
     */
59
    protected $metadataReaderManager;
60
61
    /**
62
     * @return array
63
     */
64
    public function getModuleDependencies()
65
    {
66
        return [
67
            'OldTown\\Workflow\\ZF2'
68
        ];
69
    }
70
71
    /**
72
     * @param EventInterface $e
73
     *
74
     * @return array|void
75
     *
76
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
77
     */
78
    public function onBootstrap(EventInterface $e)
79
    {
80
        /** @var MvcEvent $e */
81
        $eventManager        = $e->getApplication()->getEventManager();
82
        $moduleRouteListener = new ModuleRouteListener();
83
        $moduleRouteListener->attach($eventManager);
84
85
        /** @var Workflow $workflowService */
86
        $workflowService = $e->getApplication()->getServiceManager()->get(Workflow::class);
87
        $listener = $e->getApplication()->getServiceManager()->get(InjectTypeResolver::class);
88
        $workflowService->getEventManager()->attach($listener);
89
    }
90
91
92
    /**
93
     * @return mixed
94
     */
95
    public function getConfig()
96
    {
97
        return include __DIR__ . '/config/module.config.php';
98
    }
99
100
    /**
101
     * @return array
102
     */
103
    public function getAutoloaderConfig()
104
    {
105
        return array(
106
            'Zend\Loader\StandardAutoloader' => array(
107
                'namespaces' => array(
108
                    __NAMESPACE__ => stream_resolve_include_path(__DIR__ . '/src/'),
109
                ),
110
            ),
111
        );
112
    }
113
114
115
    /**
116
     *
117
     * @param ModuleManagerInterface $manager
118
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
119
     * @throws \OldTown\Workflow\ZF2\Service\Exception\ErrorInitModuleException
120
     */
121
    public function init(ModuleManagerInterface $manager)
122
    {
123
        if (!$manager instanceof ModuleManager) {
124
            $errMsg =sprintf('Module manager not implement %s', ModuleManager::class);
125
            throw new Exception\ErrorInitModuleException($errMsg);
126
        }
127
        /** @var ModuleManager $manager */
128
129
        /** @var ServiceLocatorInterface $sm */
130
        $sm = $manager->getEvent()->getParam('ServiceManager');
131
132
        $this->setServiceLocator($sm);
133
134
        /** @var ServiceListenerInterface $serviceListener */
135
        $serviceListener = $sm->get('ServiceListener');
136
        $serviceListener->addServiceManager(
137
            Manager::class,
138
            'workflow_zf2_service',
139
            ProviderInterface::class,
140
            'getWorkflowServiceConfig'
141
        );
142
    }
143
144
    /**
145
     * Менеджер для работы с метаданными сервисов
146
     *
147
     * @return MetadataReaderManagerInterface
148
     *
149
     * @throws Exception\ErrorInitModuleException
150
     */
151
    public function getMetadataReaderManager()
152
    {
153
        if ($this->metadataReaderManager) {
154
            return $this->metadataReaderManager;
155
        }
156
157
        try {
158
            $sl = $this->getServiceLocator();
159
            /** @var ModuleOptions $moduleOptions */
160
            $moduleOptions = $sl->get(ModuleOptions::class);
161
162
            $className = $moduleOptions->getMetadataReaderManagerClassName();
163
164
            $r = new \ReflectionClass($className);
165
            $instance = $r->newInstance();
166
167
            if (!$instance instanceof MetadataReaderManagerInterface) {
168
                $errMsg = sprintf('Metadata reader manager not implement %s', MetadataReaderManagerInterface::class);
169
                throw new Exception\ErrorInitModuleException($errMsg);
170
            }
171
            $this->metadataReaderManager = $instance;
172
        } catch (\Exception $e) {
173
            throw new Exception\ErrorInitModuleException($e->getMessage(), $e->getCode(), $e);
174
        }
175
176
        return $this->metadataReaderManager;
177
    }
178
179
    /**
180
     * Устанавливает менеджер для работы с метаданными сервисов
181
     *
182
     * @param MetadataReaderManagerInterface $metadataReaderManager
183
     *
184
     * @return $this
185
     */
186
    public function setMetadataReaderManager(MetadataReaderManagerInterface $metadataReaderManager)
187
    {
188
        $this->metadataReaderManager = $metadataReaderManager;
189
190
        return $this;
191
    }
192
193
194
195
196
}