| Conditions | 23 |
| Paths | > 20000 |
| Total Lines | 159 |
| Code Lines | 96 |
| 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 |
||
| 286 | protected function getForm() |
||
| 287 | { |
||
| 288 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 289 | |||
| 290 | $data['text_form'] = !isset($this->request->get['user_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
| 291 | $data['text_select_all'] = $this->language->get('text_select_all'); |
||
| 292 | $data['text_unselect_all'] = $this->language->get('text_unselect_all'); |
||
| 293 | |||
| 294 | $data['entry_name'] = $this->language->get('entry_name'); |
||
| 295 | $data['entry_access'] = $this->language->get('entry_access'); |
||
| 296 | $data['entry_modify'] = $this->language->get('entry_modify'); |
||
| 297 | |||
| 298 | $data['button_save'] = $this->language->get('button_save'); |
||
| 299 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
| 300 | |||
| 301 | if (isset($this->error['warning'])) { |
||
| 302 | $data['error_warning'] = $this->error['warning']; |
||
| 303 | } else { |
||
| 304 | $data['error_warning'] = ''; |
||
| 305 | } |
||
| 306 | |||
| 307 | if (isset($this->error['name'])) { |
||
| 308 | $data['error_name'] = $this->error['name']; |
||
| 309 | } else { |
||
| 310 | $data['error_name'] = ''; |
||
| 311 | } |
||
| 312 | |||
| 313 | $url = ''; |
||
| 314 | |||
| 315 | if (isset($this->request->get['sort'])) { |
||
| 316 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 317 | } |
||
| 318 | |||
| 319 | if (isset($this->request->get['order'])) { |
||
| 320 | $url .= '&order=' . $this->request->get['order']; |
||
| 321 | } |
||
| 322 | |||
| 323 | if (isset($this->request->get['page'])) { |
||
| 324 | $url .= '&page=' . $this->request->get['page']; |
||
| 325 | } |
||
| 326 | |||
| 327 | $data['breadcrumbs'] = array(); |
||
| 328 | |||
| 329 | $data['breadcrumbs'][] = array( |
||
| 330 | 'text' => $this->language->get('text_home'), |
||
| 331 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
| 332 | ); |
||
| 333 | |||
| 334 | $data['breadcrumbs'][] = array( |
||
| 335 | 'text' => $this->language->get('heading_title'), |
||
| 336 | 'href' => $this->url->link('user/user_permission', 'token=' . $this->session->data['token'] . $url, true) |
||
| 337 | ); |
||
| 338 | |||
| 339 | if (!isset($this->request->get['user_group_id'])) { |
||
| 340 | $data['action'] = $this->url->link('user/user_permission/add', 'token=' . $this->session->data['token'] . $url, true); |
||
| 341 | } else { |
||
| 342 | $data['action'] = $this->url->link('user/user_permission/edit', 'token=' . $this->session->data['token'] . '&user_group_id=' . $this->request->get['user_group_id'] . $url, true); |
||
| 343 | } |
||
| 344 | |||
| 345 | $data['cancel'] = $this->url->link('user/user_permission', 'token=' . $this->session->data['token'] . $url, true); |
||
| 346 | |||
| 347 | if (isset($this->request->get['user_group_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') { |
||
| 348 | $user_group_info = $this->model_user_user_group->getUserGroup($this->request->get['user_group_id']); |
||
| 349 | } |
||
| 350 | |||
| 351 | if (isset($this->request->post['name'])) { |
||
| 352 | $data['name'] = $this->request->post['name']; |
||
| 353 | } elseif (!empty($user_group_info)) { |
||
| 354 | $data['name'] = $user_group_info['name']; |
||
| 355 | } else { |
||
| 356 | $data['name'] = ''; |
||
| 357 | } |
||
| 358 | |||
| 359 | $ignore = array( |
||
| 360 | 'common/dashboard', |
||
| 361 | 'common/startup', |
||
| 362 | 'common/login', |
||
| 363 | 'common/logout', |
||
| 364 | 'common/forgotten', |
||
| 365 | 'common/reset', |
||
| 366 | 'common/footer', |
||
| 367 | 'common/header', |
||
| 368 | 'error/not_found', |
||
| 369 | 'error/permission' |
||
| 370 | ); |
||
| 371 | |||
| 372 | $data['permissions'] = array(); |
||
| 373 | |||
| 374 | $data['name_permission'] = array(); |
||
| 375 | $old_heading_title = ''; |
||
| 376 | |||
| 377 | $files = array(); |
||
| 378 | |||
| 379 | // Make path into an array |
||
| 380 | $path = array(SR_APPLICATION . 'controller/*'); |
||
| 381 | |||
| 382 | // While the path array is still populated keep looping through |
||
| 383 | while (count($path) != 0) { |
||
| 384 | $next = array_shift($path); |
||
| 385 | |||
| 386 | foreach (glob($next) as $file) { |
||
| 387 | // If directory add to path array |
||
| 388 | if (is_dir($file)) { |
||
| 389 | $path[] = $file . '/*'; |
||
| 390 | } |
||
| 391 | |||
| 392 | // Add the file to the files to be deleted array |
||
| 393 | if (is_file($file)) { |
||
| 394 | $files[] = $file; |
||
| 395 | } |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | // Sort the file array |
||
| 400 | sort($files); |
||
| 401 | |||
| 402 | foreach ($files as $file) { |
||
| 403 | $controller = substr($file, strlen(SR_APPLICATION . 'controller/')); |
||
| 404 | |||
| 405 | $permission = substr($controller, 0, strrpos($controller, '.')); |
||
| 406 | |||
| 407 | if (!in_array($permission, $ignore)) { |
||
| 408 | $data['permissions'][] = $permission; |
||
| 409 | |||
| 410 | $this->load->language($permission); |
||
| 411 | |||
| 412 | $heading_title = strip_tags($this->language->get('heading_title')); |
||
| 413 | |||
| 414 | if ($heading_title == $old_heading_title) { |
||
| 415 | $heading_title = ''; |
||
| 416 | } else { |
||
| 417 | $old_heading_title = $heading_title; |
||
| 418 | } |
||
| 419 | |||
| 420 | $data['name_permissions'][$permission] = $heading_title; |
||
| 421 | } |
||
| 422 | } |
||
| 423 | |||
| 424 | if (isset($this->request->post['permission']['access'])) { |
||
| 425 | $data['access'] = $this->request->post['permission']['access']; |
||
| 426 | } elseif (isset($user_group_info['permission']['access'])) { |
||
| 427 | $data['access'] = $user_group_info['permission']['access']; |
||
| 428 | } else { |
||
| 429 | $data['access'] = array(); |
||
| 430 | } |
||
| 431 | |||
| 432 | if (isset($this->request->post['permission']['modify'])) { |
||
| 433 | $data['modify'] = $this->request->post['permission']['modify']; |
||
| 434 | } elseif (isset($user_group_info['permission']['modify'])) { |
||
| 435 | $data['modify'] = $user_group_info['permission']['modify']; |
||
| 436 | } else { |
||
| 437 | $data['modify'] = array(); |
||
| 438 | } |
||
| 439 | |||
| 440 | $data['header'] = $this->load->controller('common/header'); |
||
| 441 | $data['column'] = $this->load->controller('common/column_left'); |
||
| 442 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 443 | |||
| 444 | $this->response->setOutput($this->load->view('user/user_group_form', $data)); |
||
| 445 | } |
||
| 479 |
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.