| Conditions | 18 |
| Paths | > 20000 |
| Total Lines | 151 |
| Code Lines | 95 |
| 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 |
||
| 139 | protected function getList() |
||
| 140 | { |
||
| 141 | if (isset($this->request->get['sort'])) { |
||
| 142 | $sort = $this->request->get['sort']; |
||
| 143 | } else { |
||
| 144 | $sort = 'c.name'; |
||
| 145 | } |
||
| 146 | |||
| 147 | if (isset($this->request->get['order'])) { |
||
| 148 | $order = $this->request->get['order']; |
||
| 149 | } else { |
||
| 150 | $order = 'ASC'; |
||
| 151 | } |
||
| 152 | |||
| 153 | if (isset($this->request->get['page'])) { |
||
| 154 | $page = $this->request->get['page']; |
||
| 155 | } else { |
||
| 156 | $page = 1; |
||
| 157 | } |
||
| 158 | |||
| 159 | $url = ''; |
||
| 160 | |||
| 161 | if (isset($this->request->get['sort'])) { |
||
| 162 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 163 | } |
||
| 164 | |||
| 165 | if (isset($this->request->get['order'])) { |
||
| 166 | $url .= '&order=' . $this->request->get['order']; |
||
| 167 | } |
||
| 168 | |||
| 169 | if (isset($this->request->get['page'])) { |
||
| 170 | $url .= '&page=' . $this->request->get['page']; |
||
| 171 | } |
||
| 172 | |||
| 173 | $data['breadcrumbs'] = array(); |
||
| 174 | |||
| 175 | $data['breadcrumbs'][] = array( |
||
| 176 | 'text' => $this->language->get('text_home'), |
||
| 177 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
| 178 | ); |
||
| 179 | |||
| 180 | $data['breadcrumbs'][] = array( |
||
| 181 | 'text' => $this->language->get('heading_title'), |
||
| 182 | 'href' => $this->url->link('localisation/zone', 'token=' . $this->session->data['token'] . $url, true) |
||
| 183 | ); |
||
| 184 | |||
| 185 | $data['add'] = $this->url->link('localisation/zone/add', 'token=' . $this->session->data['token'] . $url, true); |
||
| 186 | $data['delete'] = $this->url->link('localisation/zone/delete', 'token=' . $this->session->data['token'] . $url, true); |
||
| 187 | |||
| 188 | $data['zones'] = array(); |
||
| 189 | |||
| 190 | $filter_data = array( |
||
| 191 | 'sort' => $sort, |
||
| 192 | 'order' => $order, |
||
| 193 | 'start' => ($page - 1) * $this->config->get('config_limit_admin'), |
||
| 194 | 'limit' => $this->config->get('config_limit_admin') |
||
| 195 | ); |
||
| 196 | |||
| 197 | $zone_total = $this->model_localisation_zone->getTotalZones(); |
||
| 198 | |||
| 199 | $results = $this->model_localisation_zone->getZones($filter_data); |
||
| 200 | |||
| 201 | foreach ($results as $result) { |
||
| 202 | $data['zones'][] = array( |
||
| 203 | 'zone_id' => $result['zone_id'], |
||
| 204 | 'country' => $result['country'], |
||
| 205 | 'name' => $result['name'] . (($result['zone_id'] == $this->config->get('config_zone_id')) ? $this->language->get('text_default') : null), |
||
| 206 | 'code' => $result['code'], |
||
| 207 | 'edit' => $this->url->link('localisation/zone/edit', 'token=' . $this->session->data['token'] . '&zone_id=' . $result['zone_id'] . $url, true) |
||
| 208 | ); |
||
| 209 | } |
||
| 210 | |||
| 211 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 212 | |||
| 213 | $data['text_list'] = $this->language->get('text_list'); |
||
| 214 | $data['text_no_results'] = $this->language->get('text_no_results'); |
||
| 215 | $data['text_confirm'] = $this->language->get('text_confirm'); |
||
| 216 | |||
| 217 | $data['column_country'] = $this->language->get('column_country'); |
||
| 218 | $data['column_name'] = $this->language->get('column_name'); |
||
| 219 | $data['column_code'] = $this->language->get('column_code'); |
||
| 220 | $data['column_action'] = $this->language->get('column_action'); |
||
| 221 | |||
| 222 | $data['button_add'] = $this->language->get('button_add'); |
||
| 223 | $data['button_edit'] = $this->language->get('button_edit'); |
||
| 224 | $data['button_delete'] = $this->language->get('button_delete'); |
||
| 225 | |||
| 226 | if (isset($this->error['warning'])) { |
||
| 227 | $data['error_warning'] = $this->error['warning']; |
||
| 228 | } else { |
||
| 229 | $data['error_warning'] = ''; |
||
| 230 | } |
||
| 231 | |||
| 232 | if (isset($this->session->data['success'])) { |
||
| 233 | $data['success'] = $this->session->data['success']; |
||
| 234 | |||
| 235 | unset($this->session->data['success']); |
||
| 236 | } else { |
||
| 237 | $data['success'] = ''; |
||
| 238 | } |
||
| 239 | |||
| 240 | if (isset($this->request->post['selected'])) { |
||
| 241 | $data['selected'] = (array)$this->request->post['selected']; |
||
| 242 | } else { |
||
| 243 | $data['selected'] = array(); |
||
| 244 | } |
||
| 245 | |||
| 246 | $url = ''; |
||
| 247 | |||
| 248 | if ($order == 'ASC') { |
||
| 249 | $url .= '&order=DESC'; |
||
| 250 | } else { |
||
| 251 | $url .= '&order=ASC'; |
||
| 252 | } |
||
| 253 | |||
| 254 | if (isset($this->request->get['page'])) { |
||
| 255 | $url .= '&page=' . $this->request->get['page']; |
||
| 256 | } |
||
| 257 | |||
| 258 | $data['sort_country'] = $this->url->link('localisation/zone', 'token=' . $this->session->data['token'] . '&sort=c.name' . $url, true); |
||
| 259 | $data['sort_name'] = $this->url->link('localisation/zone', 'token=' . $this->session->data['token'] . '&sort=z.name' . $url, true); |
||
| 260 | $data['sort_code'] = $this->url->link('localisation/zone', 'token=' . $this->session->data['token'] . '&sort=z.code' . $url, true); |
||
| 261 | |||
| 262 | $url = ''; |
||
| 263 | |||
| 264 | if (isset($this->request->get['sort'])) { |
||
| 265 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 266 | } |
||
| 267 | |||
| 268 | if (isset($this->request->get['order'])) { |
||
| 269 | $url .= '&order=' . $this->request->get['order']; |
||
| 270 | } |
||
| 271 | |||
| 272 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
| 273 | $pagination->total = $zone_total; |
||
| 274 | $pagination->page = $page; |
||
| 275 | $pagination->limit = $this->config->get('config_limit_admin'); |
||
| 276 | $pagination->url = $this->url->link('localisation/zone', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); |
||
| 277 | |||
| 278 | $data['pagination'] = $pagination->render(); |
||
| 279 | |||
| 280 | $data['results'] = sprintf($this->language->get('text_pagination'), ($zone_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($zone_total - $this->config->get('config_limit_admin'))) ? $zone_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $zone_total, ceil($zone_total / $this->config->get('config_limit_admin'))); |
||
| 281 | |||
| 282 | $data['sort'] = $sort; |
||
| 283 | $data['order'] = $order; |
||
| 284 | |||
| 285 | $data['header'] = $this->load->controller('common/header'); |
||
| 286 | $data['column'] = $this->load->controller('common/column_left'); |
||
| 287 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 288 | |||
| 289 | $this->response->setOutput($this->load->view('localisation/zone_list', $data)); |
||
| 290 | } |
||
| 445 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.