| Conditions | 8 |
| Paths | 17 |
| Total Lines | 67 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 63 | public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args) |
||
| 64 | { |
||
| 65 | if ( |
||
| 66 | !$this->container->get('config')->getByNamespace('WbmTagManager', 'wbmTagManagerActive') || |
||
| 67 | empty($this->container->get('config')->getByNamespace('WbmTagManager', 'wbmTagManagerContainer')) |
||
| 68 | ) { |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | |||
| 72 | $controller = $args->getSubject(); |
||
| 73 | $request = $controller->Request(); |
||
| 74 | |||
| 75 | $module = $oModule = join('_', [ |
||
| 76 | strtolower($request->getModuleName()), |
||
| 77 | strtolower($request->getControllerName()), |
||
| 78 | strtolower($request->getActionName()), |
||
| 79 | ]); |
||
| 80 | |||
| 81 | if ($module == 'frontend_checkout_ajaxcart') { |
||
| 82 | $module = 'frontend_checkout_' . strtolower($request->getParam('action')); |
||
| 83 | } |
||
| 84 | |||
| 85 | $search = [ |
||
| 86 | 'widgets_listing_ajaxlisting', |
||
| 87 | 'widgets_listing_listingcount', |
||
| 88 | 'frontend_checkout_ajaxcart', |
||
| 89 | ]; |
||
| 90 | $replace = [ |
||
| 91 | 'frontend_listing_index', |
||
| 92 | 'frontend_listing_index', |
||
| 93 | 'frontend_checkout_cart', |
||
| 94 | ]; |
||
| 95 | $module = str_replace($search, $replace, $module); |
||
| 96 | |||
| 97 | /** @var Repository $propertyRepo */ |
||
| 98 | $propertyRepo = $this->container->get('models')->getRepository('WbmTagManager\Models\Property'); |
||
| 99 | $dataLayer = $propertyRepo->getChildrenList(0, $module, true); |
||
| 100 | |||
| 101 | if (!empty($dataLayer)) { |
||
| 102 | $this->viewVariables = $controller->View()->getAssign(); |
||
| 103 | |||
| 104 | $dataLayer = $this->fillValues($dataLayer); |
||
| 105 | |||
| 106 | $this->container->get('wbm_tag_manager.variables')->setVariables($dataLayer); |
||
| 107 | } |
||
| 108 | |||
| 109 | // Since SW 5.3 the generic listingCountAction is used for paginated listings. |
||
| 110 | // Get the response json body, decode it, prepend the dataLayer to the listing key |
||
| 111 | // and set json encoded markup as response body. |
||
| 112 | if ($oModule == 'widgets_listing_listingcount') { |
||
| 113 | /** @var \Enlight_Controller_Response_ResponseHttp $response */ |
||
| 114 | $response = $controller->Response(); |
||
| 115 | $data = json_decode($response->getBody(), true); |
||
| 116 | |||
| 117 | if (isset($data['listing'])) { |
||
| 118 | if ($dataLayer = $this->container->get('wbm_tag_manager.variables')->getVariables()) { |
||
| 119 | $data['listing'] = FilterRender::prependDataLayer( |
||
| 120 | $data['listing'], |
||
| 121 | $dataLayer, |
||
| 122 | $this->container->get('config')->getByNamespace('WbmTagManager', 'wbmTagManagerJsonPrettyPrint') |
||
| 123 | ); |
||
| 124 | |||
| 125 | $response->setBody(json_encode($data)); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 180 | } |