| Conditions | 36 |
| Paths | > 20000 |
| Total Lines | 190 |
| Code Lines | 127 |
| 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 |
||
| 292 | protected function getForm() |
||
| 293 | { |
||
| 294 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 295 | |||
| 296 | $data['text_form'] = !isset($this->request->get['user_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
| 297 | $data['text_enabled'] = $this->language->get('text_enabled'); |
||
| 298 | $data['text_disabled'] = $this->language->get('text_disabled'); |
||
| 299 | |||
| 300 | $data['entry_username'] = $this->language->get('entry_username'); |
||
| 301 | $data['entry_user_group'] = $this->language->get('entry_user_group'); |
||
| 302 | $data['entry_password'] = $this->language->get('entry_password'); |
||
| 303 | $data['entry_confirm'] = $this->language->get('entry_confirm'); |
||
| 304 | $data['entry_firstname'] = $this->language->get('entry_firstname'); |
||
| 305 | $data['entry_lastname'] = $this->language->get('entry_lastname'); |
||
| 306 | $data['entry_email'] = $this->language->get('entry_email'); |
||
| 307 | $data['entry_image'] = $this->language->get('entry_image'); |
||
| 308 | $data['entry_status'] = $this->language->get('entry_status'); |
||
| 309 | |||
| 310 | $data['button_save'] = $this->language->get('button_save'); |
||
| 311 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
| 312 | |||
| 313 | if (isset($this->error['warning'])) { |
||
| 314 | $data['error_warning'] = $this->error['warning']; |
||
| 315 | } else { |
||
| 316 | $data['error_warning'] = ''; |
||
| 317 | } |
||
| 318 | |||
| 319 | if (isset($this->error['username'])) { |
||
| 320 | $data['error_username'] = $this->error['username']; |
||
| 321 | } else { |
||
| 322 | $data['error_username'] = ''; |
||
| 323 | } |
||
| 324 | |||
| 325 | if (isset($this->error['password'])) { |
||
| 326 | $data['error_password'] = $this->error['password']; |
||
| 327 | } else { |
||
| 328 | $data['error_password'] = ''; |
||
| 329 | } |
||
| 330 | |||
| 331 | if (isset($this->error['confirm'])) { |
||
| 332 | $data['error_confirm'] = $this->error['confirm']; |
||
| 333 | } else { |
||
| 334 | $data['error_confirm'] = ''; |
||
| 335 | } |
||
| 336 | |||
| 337 | if (isset($this->error['firstname'])) { |
||
| 338 | $data['error_firstname'] = $this->error['firstname']; |
||
| 339 | } else { |
||
| 340 | $data['error_firstname'] = ''; |
||
| 341 | } |
||
| 342 | |||
| 343 | if (isset($this->error['lastname'])) { |
||
| 344 | $data['error_lastname'] = $this->error['lastname']; |
||
| 345 | } else { |
||
| 346 | $data['error_lastname'] = ''; |
||
| 347 | } |
||
| 348 | |||
| 349 | if (isset($this->error['email'])) { |
||
| 350 | $data['error_email'] = $this->error['email']; |
||
| 351 | } else { |
||
| 352 | $data['error_email'] = ''; |
||
| 353 | } |
||
| 354 | |||
| 355 | $url = ''; |
||
| 356 | |||
| 357 | if (isset($this->request->get['sort'])) { |
||
| 358 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 359 | } |
||
| 360 | |||
| 361 | if (isset($this->request->get['order'])) { |
||
| 362 | $url .= '&order=' . $this->request->get['order']; |
||
| 363 | } |
||
| 364 | |||
| 365 | if (isset($this->request->get['page'])) { |
||
| 366 | $url .= '&page=' . $this->request->get['page']; |
||
| 367 | } |
||
| 368 | |||
| 369 | $data['breadcrumbs'] = array(); |
||
| 370 | |||
| 371 | $data['breadcrumbs'][] = array( |
||
| 372 | 'text' => $this->language->get('text_home'), |
||
| 373 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
| 374 | ); |
||
| 375 | |||
| 376 | $data['breadcrumbs'][] = array( |
||
| 377 | 'text' => $this->language->get('heading_title'), |
||
| 378 | 'href' => $this->url->link('user/user', 'token=' . $this->session->data['token'] . $url, true) |
||
| 379 | ); |
||
| 380 | |||
| 381 | if (!isset($this->request->get['user_id'])) { |
||
| 382 | $data['action'] = $this->url->link('user/user/add', 'token=' . $this->session->data['token'] . $url, true); |
||
| 383 | } else { |
||
| 384 | $data['action'] = $this->url->link('user/user/edit', 'token=' . $this->session->data['token'] . '&user_id=' . $this->request->get['user_id'] . $url, true); |
||
| 385 | } |
||
| 386 | |||
| 387 | $data['cancel'] = $this->url->link('user/user', 'token=' . $this->session->data['token'] . $url, true); |
||
| 388 | |||
| 389 | if (isset($this->request->get['user_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
| 390 | $user_info = $this->model_user_user->getUser($this->request->get['user_id']); |
||
| 391 | } |
||
| 392 | |||
| 393 | if (isset($this->request->post['username'])) { |
||
| 394 | $data['username'] = $this->request->post['username']; |
||
| 395 | } elseif (!empty($user_info)) { |
||
| 396 | $data['username'] = $user_info['username']; |
||
| 397 | } else { |
||
| 398 | $data['username'] = ''; |
||
| 399 | } |
||
| 400 | |||
| 401 | if (isset($this->request->post['user_group_id'])) { |
||
| 402 | $data['user_group_id'] = $this->request->post['user_group_id']; |
||
| 403 | } elseif (!empty($user_info)) { |
||
| 404 | $data['user_group_id'] = $user_info['user_group_id']; |
||
| 405 | } else { |
||
| 406 | $data['user_group_id'] = ''; |
||
| 407 | } |
||
| 408 | |||
| 409 | $this->load->model('user/user_group'); |
||
| 410 | |||
| 411 | $data['user_groups'] = $this->model_user_user_group->getUserGroups(); |
||
| 412 | |||
| 413 | if (isset($this->request->post['password'])) { |
||
| 414 | $data['password'] = $this->request->post['password']; |
||
| 415 | } else { |
||
| 416 | $data['password'] = ''; |
||
| 417 | } |
||
| 418 | |||
| 419 | if (isset($this->request->post['confirm'])) { |
||
| 420 | $data['confirm'] = $this->request->post['confirm']; |
||
| 421 | } else { |
||
| 422 | $data['confirm'] = ''; |
||
| 423 | } |
||
| 424 | |||
| 425 | if (isset($this->request->post['firstname'])) { |
||
| 426 | $data['firstname'] = $this->request->post['firstname']; |
||
| 427 | } elseif (!empty($user_info)) { |
||
| 428 | $data['firstname'] = $user_info['firstname']; |
||
| 429 | } else { |
||
| 430 | $data['firstname'] = ''; |
||
| 431 | } |
||
| 432 | |||
| 433 | if (isset($this->request->post['lastname'])) { |
||
| 434 | $data['lastname'] = $this->request->post['lastname']; |
||
| 435 | } elseif (!empty($user_info)) { |
||
| 436 | $data['lastname'] = $user_info['lastname']; |
||
| 437 | } else { |
||
| 438 | $data['lastname'] = ''; |
||
| 439 | } |
||
| 440 | |||
| 441 | if (isset($this->request->post['email'])) { |
||
| 442 | $data['email'] = $this->request->post['email']; |
||
| 443 | } elseif (!empty($user_info)) { |
||
| 444 | $data['email'] = $user_info['email']; |
||
| 445 | } else { |
||
| 446 | $data['email'] = ''; |
||
| 447 | } |
||
| 448 | |||
| 449 | if (isset($this->request->post['image'])) { |
||
| 450 | $data['image'] = $this->request->post['image']; |
||
| 451 | } elseif (!empty($user_info)) { |
||
| 452 | $data['image'] = $user_info['image']; |
||
| 453 | } else { |
||
| 454 | $data['image'] = ''; |
||
| 455 | } |
||
| 456 | |||
| 457 | |||
| 458 | |||
| 459 | if (isset($this->request->post['image']) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->request->post['image'])) { |
||
| 460 | $data['thumb'] = '/public_html/assets/images/' . $this->request->post['image']; |
||
| 461 | } elseif (!empty($user_info) && $user_info['image'] && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $user_info['image'])) { |
||
| 462 | $data['thumb'] = '/public_html/assets/images/' . $user_info['image']; |
||
| 463 | } else { |
||
| 464 | $data['thumb'] = '/public_html/assets/images/no_image.png'; |
||
| 465 | } |
||
| 466 | |||
| 467 | $data['placeholder'] = '/public_html/assets/images/no_image.png'; |
||
| 468 | |||
| 469 | if (isset($this->request->post['status'])) { |
||
| 470 | $data['status'] = $this->request->post['status']; |
||
| 471 | } elseif (!empty($user_info)) { |
||
| 472 | $data['status'] = $user_info['status']; |
||
| 473 | } else { |
||
| 474 | $data['status'] = 0; |
||
| 475 | } |
||
| 476 | |||
| 477 | $data['header'] = $this->load->controller('common/header'); |
||
| 478 | $data['column'] = $this->load->controller('common/column_left'); |
||
| 479 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 480 | |||
| 481 | $this->response->setOutput($this->load->view('user/user_form', $data)); |
||
| 482 | } |
||
| 558 |
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.