| Conditions | 11 |
| Paths | 23 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 96 | public function handleDispatch( |
||
| 97 | \Enlight_Controller_ActionEventArgs $args, |
||
| 98 | $isPreDispatch = false |
||
| 99 | ) { |
||
| 100 | if ( |
||
| 101 | !$this->pluginConfig['wbmTagManagerActive'] || |
||
| 102 | empty($this->pluginConfig['wbmTagManagerContainer']) |
||
| 103 | ) { |
||
| 104 | return; |
||
| 105 | } |
||
| 106 | |||
| 107 | $controller = $args->getSubject(); |
||
| 108 | $request = $controller->Request(); |
||
| 109 | |||
| 110 | $module = $oModule = join('_', [ |
||
| 111 | strtolower($request->getModuleName()), |
||
| 112 | strtolower($request->getControllerName()), |
||
| 113 | strtolower($request->getActionName()), |
||
| 114 | ]); |
||
| 115 | |||
| 116 | if ($module == 'frontend_checkout_ajaxcart') { |
||
| 117 | $module = 'frontend_checkout_' . strtolower($request->getParam('action')); |
||
| 118 | } |
||
| 119 | |||
| 120 | $module = $this->rewriteModuleKey($module); |
||
| 121 | |||
| 122 | if (!isset($this->modules[$module]) || (bool) $this->modules[$module] !== $isPreDispatch) { |
||
| 123 | return; |
||
| 124 | } |
||
| 125 | |||
| 126 | if (!$this->variables->getVariables()) { |
||
| 127 | $this->variables->setViewVariables($controller->View()->getAssign()); |
||
| 128 | $this->variables->render($module); |
||
| 129 | } |
||
| 130 | |||
| 131 | if ($isPreDispatch) { |
||
| 132 | return; |
||
| 133 | } |
||
| 134 | |||
| 135 | // Since SW 5.3 the generic listingCountAction is used for paginated listings. |
||
| 136 | // Get the response json body, decode it, prepend the dataLayer to the listing key |
||
| 137 | // and set json encoded markup as response body. |
||
| 138 | if ($oModule == 'widgets_listing_listingcount') { |
||
| 139 | /** @var \Enlight_Controller_Response_ResponseHttp $response */ |
||
| 140 | $response = $controller->Response(); |
||
| 141 | $data = json_decode($response->getBody(), true); |
||
| 142 | |||
| 143 | if (isset($data['listing'])) { |
||
| 144 | if ($this->variables->getVariables()) { |
||
| 145 | $data['listing'] = $this->variables->prependDataLayer( |
||
| 146 | $data['listing'], |
||
| 147 | $this->pluginConfig['wbmTagManagerJsonPrettyPrint'] |
||
| 148 | ); |
||
| 149 | |||
| 150 | $response->setBody(json_encode($data)); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 184 |