| Conditions | 8 |
| Paths | 12 |
| Total Lines | 89 |
| Code Lines | 54 |
| 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 |
||
| 60 | public function onBootstrap(MvcEvent $e) |
||
| 61 | { |
||
| 62 | // Register the TimezoneAwareDate type with DoctrineMongoODM |
||
| 63 | // Use it in Annotations ( @Field(type="tz_date") ) |
||
| 64 | if (!DoctrineType::hasType('tz_date')) { |
||
| 65 | DoctrineType::addType( |
||
| 66 | 'tz_date', |
||
| 67 | '\Core\Repository\DoctrineMongoODM\Types\TimezoneAwareDate' |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | $sm = $e->getApplication()->getServiceManager(); |
||
| 72 | $translator = $sm->get('translator'); // initialise translator! |
||
| 73 | \Zend\Validator\AbstractValidator::setDefaultTranslator($translator); |
||
|
|
|||
| 74 | $eventManager = $e->getApplication()->getEventManager(); |
||
| 75 | $sharedManager = $eventManager->getSharedManager(); |
||
| 76 | |||
| 77 | $tracyConfig = $sm->get('Config')['tracy']; |
||
| 78 | |||
| 79 | if ($tracyConfig['enabled']) { |
||
| 80 | (new TracyService())->register($tracyConfig); |
||
| 81 | (new TracyListener())->attach($eventManager); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!\Zend\Console\Console::isConsole()) { |
||
| 85 | $redirectCallback = function () use ($e) { |
||
| 86 | $routeMatch = $e->getRouteMatch(); |
||
| 87 | $lang = $routeMatch ? $routeMatch->getParam('lang', 'en') : 'en'; |
||
| 88 | $uri = $e->getRouter()->getBaseUrl() . '/' . $lang . '/error'; |
||
| 89 | |||
| 90 | header('Location: ' . $uri); |
||
| 91 | }; |
||
| 92 | |||
| 93 | if (!$tracyConfig['enabled']) { |
||
| 94 | $errorHandlerListener = new ErrorHandlerListener($sm->get('ErrorLogger'), $redirectCallback); |
||
| 95 | $errorHandlerListener->attach($eventManager); |
||
| 96 | } |
||
| 97 | |||
| 98 | /* @var \Core\Options\ModuleOptions $options */ |
||
| 99 | $languageRouteListener = new LanguageRouteListener($sm->get('Core/Locale')); |
||
| 100 | $languageRouteListener->attach($eventManager); |
||
| 101 | |||
| 102 | |||
| 103 | $ajaxRenderListener = new AjaxRenderListener(); |
||
| 104 | $ajaxRenderListener->attach($eventManager); |
||
| 105 | |||
| 106 | $xmlRenderListener = new XmlRenderListener(); |
||
| 107 | $xmlRenderListener->attach($eventManager); |
||
| 108 | |||
| 109 | $enforceJsonResponseListener = new EnforceJsonResponseListener(); |
||
| 110 | $enforceJsonResponseListener->attach($eventManager); |
||
| 111 | |||
| 112 | $stringListener = new StringListener(); |
||
| 113 | $stringListener->attach($eventManager); |
||
| 114 | |||
| 115 | } |
||
| 116 | |||
| 117 | $notificationListener = $sm->get('Core/Listener/Notification'); |
||
| 118 | $notificationListener->attachShared($sharedManager); |
||
| 119 | $notificationAjaxHandler = new NotificationAjaxHandler(); |
||
| 120 | $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($notificationAjaxHandler, 'injectView'), -20); |
||
| 121 | $notificationListener->attach(NotificationEvent::EVENT_NOTIFICATION_HTML, array($notificationAjaxHandler, 'render'), -20); |
||
| 122 | |||
| 123 | $persistenceListener = new PersistenceListener(); |
||
| 124 | $persistenceListener->attach($eventManager); |
||
| 125 | |||
| 126 | $eventManager->attach( |
||
| 127 | MvcEvent::EVENT_DISPATCH_ERROR, |
||
| 128 | function ($event) { |
||
| 129 | $application = $event->getApplication(); |
||
| 130 | if ($application::ERROR_EXCEPTION == $event->getError()) { |
||
| 131 | $ex = $event->getParam('exception'); |
||
| 132 | if (404 == $ex->getCode()) { |
||
| 133 | $event->setError($application::ERROR_CONTROLLER_NOT_FOUND); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | }, |
||
| 138 | 500 |
||
| 139 | ); |
||
| 140 | $eventManager->attach( |
||
| 141 | MvcEvent::EVENT_DISPATCH, |
||
| 142 | function ($event) use ($eventManager) { |
||
| 143 | $eventManager->trigger('postDispatch', $event); |
||
| 144 | }, |
||
| 145 | -150 |
||
| 146 | ); |
||
| 147 | |||
| 148 | } |
||
| 149 | |||
| 182 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: