| Conditions | 9 |
| Paths | 13 |
| Total Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 97 | public function handleDispatch( |
||
| 98 | \Enlight_Controller_ActionEventArgs $args, |
||
| 99 | $isPreDispatch = false |
||
| 100 | ) { |
||
| 101 | if ( |
||
| 102 | !$this->config->getByNamespace('WbmTagManager', 'wbmTagManagerActive') || |
||
| 103 | empty($this->config->getByNamespace('WbmTagManager', 'wbmTagManagerContainer')) |
||
| 104 | ) { |
||
| 105 | return; |
||
| 106 | } |
||
| 107 | |||
| 108 | $controller = $args->getSubject(); |
||
| 109 | $request = $controller->Request(); |
||
| 110 | |||
| 111 | $module = $oModule = join('_', [ |
||
| 112 | strtolower($request->getModuleName()), |
||
| 113 | strtolower($request->getControllerName()), |
||
| 114 | strtolower($request->getActionName()), |
||
| 115 | ]); |
||
| 116 | |||
| 117 | if ($module == 'frontend_checkout_ajaxcart') { |
||
| 118 | $module = 'frontend_checkout_' . strtolower($request->getParam('action')); |
||
| 119 | } |
||
| 120 | |||
| 121 | $search = [ |
||
| 122 | 'widgets_listing_ajaxlisting', |
||
| 123 | 'widgets_listing_listingcount', |
||
| 124 | 'frontend_checkout_ajaxcart', |
||
| 125 | 'frontend_checkout_ajax_add_article', |
||
| 126 | 'frontend_checkout_ajax_delete_article', |
||
| 127 | ]; |
||
| 128 | $replace = [ |
||
| 129 | 'frontend_listing_index', |
||
| 130 | 'frontend_listing_index', |
||
| 131 | 'frontend_checkout_cart', |
||
| 132 | 'frontend_checkout_ajaxaddarticlecart', |
||
| 133 | 'frontend_checkout_ajaxdeletearticlecart', |
||
| 134 | ]; |
||
| 135 | $module = str_replace($search, $replace, $module); |
||
| 136 | |||
| 137 | if ($isPreDispatch !== $this->isPreDispatchByModule($module)) { |
||
| 138 | return; |
||
| 139 | } |
||
| 140 | |||
| 141 | $this->variables->setViewVariables($controller->View()->getAssign()); |
||
| 142 | $this->variables->render($module); |
||
| 143 | |||
| 144 | if ($isPreDispatch) { |
||
| 145 | return; |
||
| 146 | } |
||
| 147 | |||
| 148 | // Since SW 5.3 the generic listingCountAction is used for paginated listings. |
||
| 149 | // Get the response json body, decode it, prepend the dataLayer to the listing key |
||
| 150 | // and set json encoded markup as response body. |
||
| 151 | if ($oModule == 'widgets_listing_listingcount') { |
||
| 152 | /** @var \Enlight_Controller_Response_ResponseHttp $response */ |
||
| 153 | $response = $controller->Response(); |
||
| 154 | $data = json_decode($response->getBody(), true); |
||
| 155 | |||
| 156 | if (isset($data['listing'])) { |
||
| 157 | if ($this->variables->getVariables()) { |
||
| 158 | $data['listing'] = $this->variables->prependDataLayer( |
||
| 159 | $data['listing'], |
||
| 160 | $this->config->getByNamespace('WbmTagManager', 'wbmTagManagerJsonPrettyPrint') |
||
| 161 | ); |
||
| 162 | |||
| 163 | $response->setBody(json_encode($data)); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 188 |