Conditions | 6 |
Paths | 4 |
Total Lines | 75 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
130 | public function onBootstrap(MvcEvent $e) |
||
131 | { |
||
132 | // Register the TimezoneAwareDate type with DoctrineMongoODM |
||
133 | // Use it in Annotations ( @Field(type="tz_date") ) |
||
134 | if (!DoctrineType::hasType('tz_date')) { |
||
135 | DoctrineType::addType( |
||
136 | 'tz_date', |
||
137 | '\Core\Repository\DoctrineMongoODM\Types\TimezoneAwareDate' |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | $sm = $e->getApplication()->getServiceManager(); |
||
142 | $translator = $sm->get('translator'); // initialize translator! |
||
143 | \Zend\Validator\AbstractValidator::setDefaultTranslator($translator); |
||
144 | $eventManager = $e->getApplication()->getEventManager(); |
||
145 | $sharedManager = $eventManager->getSharedManager(); |
||
146 | |||
147 | if (!\Zend\Console\Console::isConsole()) { |
||
148 | (new ErrorHandlerListener())->attach($eventManager); |
||
149 | |||
150 | /* @var \Core\Options\ModuleOptions $options */ |
||
151 | $languageRouteListener = new LanguageRouteListener( |
||
152 | $sm->get('Core/Locale'), |
||
153 | $sm->get('Core/Options') |
||
154 | ); |
||
155 | $languageRouteListener->attach($eventManager); |
||
156 | |||
157 | $ajaxRenderListener = new AjaxRenderListener(); |
||
158 | $ajaxRenderListener->attach($eventManager); |
||
159 | |||
160 | $ajaxRouteListener = $sm->get(AjaxRouteListener::class); |
||
161 | $ajaxRouteListener->attach($eventManager); |
||
162 | |||
163 | $xmlRenderListener = new XmlRenderListener(); |
||
164 | $xmlRenderListener->attach($eventManager); |
||
165 | |||
166 | $enforceJsonResponseListener = new EnforceJsonResponseListener(); |
||
167 | $enforceJsonResponseListener->attach($eventManager); |
||
168 | |||
169 | $stringListener = new StringListener(); |
||
170 | $stringListener->attach($eventManager); |
||
171 | } |
||
172 | |||
173 | $notificationListener = $sm->get('Core/Listener/Notification'); |
||
174 | $notificationListener->attachShared($sharedManager); |
||
175 | $notificationAjaxHandler = new NotificationAjaxHandler(); |
||
176 | $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($notificationAjaxHandler, 'injectView'), -20); |
||
177 | $notificationListener->attach(NotificationEvent::EVENT_NOTIFICATION_HTML, array($notificationAjaxHandler, 'render'), -20); |
||
178 | |||
179 | |||
180 | $eventManager->attach( |
||
181 | MvcEvent::EVENT_DISPATCH_ERROR, |
||
182 | function ($event) { |
||
183 | if ($event instanceof MvcEvent) { |
||
184 | $application = $event->getApplication(); |
||
185 | |||
186 | if ($application::ERROR_EXCEPTION == $event->getError()) { |
||
187 | $ex = $event->getParam('exception'); |
||
188 | if (404 == $ex->getCode()) { |
||
189 | $event->setError($application::ERROR_CONTROLLER_NOT_FOUND); |
||
190 | } |
||
191 | } |
||
192 | } |
||
193 | }, |
||
194 | 500 |
||
195 | ); |
||
196 | $eventManager->attach( |
||
197 | MvcEvent::EVENT_DISPATCH, |
||
198 | function ($event) use ($eventManager) { |
||
199 | $eventManager->trigger('postDispatch', $event); |
||
200 | }, |
||
201 | -150 |
||
202 | ); |
||
203 | |||
204 | $sm->get('Tracy')->startDebug(); |
||
205 | } |
||
257 |