| Conditions | 7 |
| Paths | 9 |
| Total Lines | 61 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 59 | public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args) |
||
| 60 | { |
||
| 61 | if ( |
||
| 62 | !$this->config->getByNamespace('WbmTagManager', 'wbmTagManagerActive') || |
||
| 63 | empty($this->config->getByNamespace('WbmTagManager', 'wbmTagManagerContainer')) |
||
| 64 | ) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | $controller = $args->getSubject(); |
||
| 69 | $request = $controller->Request(); |
||
| 70 | |||
| 71 | $module = $oModule = join('_', [ |
||
| 72 | strtolower($request->getModuleName()), |
||
| 73 | strtolower($request->getControllerName()), |
||
| 74 | strtolower($request->getActionName()), |
||
| 75 | ]); |
||
| 76 | |||
| 77 | if ($module == 'frontend_checkout_ajaxcart') { |
||
| 78 | $module = 'frontend_checkout_' . strtolower($request->getParam('action')); |
||
| 79 | } |
||
| 80 | |||
| 81 | $search = [ |
||
| 82 | 'widgets_listing_ajaxlisting', |
||
| 83 | 'widgets_listing_listingcount', |
||
| 84 | 'frontend_checkout_ajaxcart', |
||
| 85 | 'frontend_checkout_ajax_add_article', |
||
| 86 | 'frontend_checkout_ajax_delete_article', |
||
| 87 | ]; |
||
| 88 | $replace = [ |
||
| 89 | 'frontend_listing_index', |
||
| 90 | 'frontend_listing_index', |
||
| 91 | 'frontend_checkout_cart', |
||
| 92 | 'frontend_checkout_ajaxaddarticlecart', |
||
| 93 | 'frontend_checkout_ajaxdeletearticlecart', |
||
| 94 | ]; |
||
| 95 | $module = str_replace($search, $replace, $module); |
||
| 96 | |||
| 97 | $this->variables->setViewVariables($controller->View()->getAssign()); |
||
| 98 | $this->variables->render($module); |
||
| 99 | |||
| 100 | // Since SW 5.3 the generic listingCountAction is used for paginated listings. |
||
| 101 | // Get the response json body, decode it, prepend the dataLayer to the listing key |
||
| 102 | // and set json encoded markup as response body. |
||
| 103 | if ($oModule == 'widgets_listing_listingcount') { |
||
| 104 | /** @var \Enlight_Controller_Response_ResponseHttp $response */ |
||
| 105 | $response = $controller->Response(); |
||
| 106 | $data = json_decode($response->getBody(), true); |
||
| 107 | |||
| 108 | if (isset($data['listing'])) { |
||
| 109 | if ($this->variables->getVariables()) { |
||
| 110 | $data['listing'] = $this->variables->prependDataLayer( |
||
| 111 | $data['listing'], |
||
| 112 | $this->config->getByNamespace('WbmTagManager', 'wbmTagManagerJsonPrettyPrint') |
||
| 113 | ); |
||
| 114 | |||
| 115 | $response->setBody(json_encode($data)); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 |