| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 162 |
| Code Lines | 100 |
| 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 = '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 | 'separator' => false |
||
| 179 | ); |
||
| 180 | |||
| 181 | $data['breadcrumbs'][] = array( |
||
| 182 | 'text' => $this->language->get('heading_title'), |
||
| 183 | 'href' => $this->url->link('design/benefit', 'token=' . $this->session->data['token'] . $url, true), |
||
| 184 | 'separator' => ' :: ' |
||
| 185 | ); |
||
| 186 | |||
| 187 | $data['add'] = $this->url->link('design/benefit/add', 'token=' . $this->session->data['token'] . $url, true); |
||
| 188 | $data['delete'] = $this->url->link('design/benefit/delete', 'token=' . $this->session->data['token'] . $url, true); |
||
| 189 | |||
| 190 | $data['benefits'] = array(); |
||
| 191 | |||
| 192 | $filter_data = array( |
||
| 193 | 'sort' => $sort, |
||
| 194 | 'order' => $order, |
||
| 195 | 'start' => ($page - 1) * $this->config->get('config_limit_admin'), |
||
| 196 | 'limit' => $this->config->get('config_limit_admin') |
||
| 197 | ); |
||
| 198 | |||
| 199 | $benefit_total = $this->model_design_benefit->getTotalBenefits(); |
||
| 200 | |||
| 201 | $results = $this->model_design_benefit->getBenefits($filter_data); |
||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | foreach ($results as $result) { |
||
| 206 | if ($result['image'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $result['image'])) { |
||
| 207 | $image = '/public_html/assets/images/' . $result['image']; |
||
| 208 | } else { |
||
| 209 | $image = '/public_html/assets/images/no_image.png'; |
||
| 210 | } |
||
| 211 | |||
| 212 | $data['benefits'][] = array( |
||
| 213 | 'benefit_id' => $result['benefit_id'], |
||
| 214 | 'name' => $result['name'], |
||
| 215 | 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), |
||
| 216 | 'edit' => $this->url->link('design/benefit/edit', 'token=' . $this->session->data['token'] . '&benefit_id=' . $result['benefit_id'] . $url, true), |
||
| 217 | 'image' => $image, |
||
| 218 | ); |
||
| 219 | } |
||
| 220 | |||
| 221 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 222 | |||
| 223 | $data['text_list'] = $this->language->get('text_list'); |
||
| 224 | $data['text_no_results'] = $this->language->get('text_no_results'); |
||
| 225 | $data['text_confirm'] = $this->language->get('text_confirm'); |
||
| 226 | |||
| 227 | $data['column_image'] = $this->language->get('column_image'); |
||
| 228 | $data['column_name'] = $this->language->get('column_name'); |
||
| 229 | $data['column_status'] = $this->language->get('column_status'); |
||
| 230 | $data['column_action'] = $this->language->get('column_action'); |
||
| 231 | |||
| 232 | $data['button_add'] = $this->language->get('button_add'); |
||
| 233 | $data['button_edit'] = $this->language->get('button_edit'); |
||
| 234 | $data['button_delete'] = $this->language->get('button_delete'); |
||
| 235 | |||
| 236 | |||
| 237 | |||
| 238 | if (isset($this->error['warning'])) { |
||
| 239 | $data['error_warning'] = $this->error['warning']; |
||
| 240 | } else { |
||
| 241 | $data['error_warning'] = ''; |
||
| 242 | } |
||
| 243 | |||
| 244 | if (isset($this->session->data['success'])) { |
||
| 245 | $data['success'] = $this->session->data['success']; |
||
| 246 | |||
| 247 | unset($this->session->data['success']); |
||
| 248 | } else { |
||
| 249 | $data['success'] = ''; |
||
| 250 | } |
||
| 251 | |||
| 252 | if (isset($this->request->post['selected'])) { |
||
| 253 | $data['selected'] = (array)$this->request->post['selected']; |
||
| 254 | } else { |
||
| 255 | $data['selected'] = array(); |
||
| 256 | } |
||
| 257 | |||
| 258 | $url = ''; |
||
| 259 | |||
| 260 | if ($order == 'ASC') { |
||
| 261 | $url .= '&order=DESC'; |
||
| 262 | } else { |
||
| 263 | $url .= '&order=ASC'; |
||
| 264 | } |
||
| 265 | |||
| 266 | if (isset($this->request->get['page'])) { |
||
| 267 | $url .= '&page=' . $this->request->get['page']; |
||
| 268 | } |
||
| 269 | |||
| 270 | $data['sort_name'] = $this->url->link('design/benefit', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true); |
||
| 271 | $data['sort_status'] = $this->url->link('design/benefit', 'token=' . $this->session->data['token'] . '&sort=status' . $url, true); |
||
| 272 | |||
| 273 | $url = ''; |
||
| 274 | |||
| 275 | if (isset($this->request->get['sort'])) { |
||
| 276 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 277 | } |
||
| 278 | |||
| 279 | if (isset($this->request->get['order'])) { |
||
| 280 | $url .= '&order=' . $this->request->get['order']; |
||
| 281 | } |
||
| 282 | |||
| 283 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
| 284 | $pagination->total = $benefit_total; |
||
| 285 | $pagination->page = $page; |
||
| 286 | $pagination->limit = $this->config->get('config_limit_admin'); |
||
| 287 | $pagination->url = $this->url->link('design/benefit', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); |
||
| 288 | |||
| 289 | $data['pagination'] = $pagination->render(); |
||
| 290 | |||
| 291 | $data['results'] = sprintf($this->language->get('text_pagination'), ($benefit_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($benefit_total - $this->config->get('config_limit_admin'))) ? $benefit_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $benefit_total, ceil($benefit_total / $this->config->get('config_limit_admin'))); |
||
| 292 | |||
| 293 | $data['sort'] = $sort; |
||
| 294 | $data['order'] = $order; |
||
| 295 | |||
| 296 | $data['header'] = $this->load->controller('common/header'); |
||
| 297 | $data['column'] = $this->load->controller('common/column_left'); |
||
| 298 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 299 | |||
| 300 | $this->response->setOutput($this->load->view('design/benefit_list', $data)); |
||
| 301 | } |
||
| 496 |
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.