| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 208 |
| Code Lines | 143 |
| 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 |
||
| 333 | protected function getForm() |
||
| 334 | { |
||
| 335 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 336 | |||
| 337 | $data['text_form'] = !isset($this->request->get['custom_field_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
| 338 | $data['text_choose'] = $this->language->get('text_choose'); |
||
| 339 | $data['text_select'] = $this->language->get('text_select'); |
||
| 340 | $data['text_radio'] = $this->language->get('text_radio'); |
||
| 341 | $data['text_checkbox'] = $this->language->get('text_checkbox'); |
||
| 342 | $data['text_input'] = $this->language->get('text_input'); |
||
| 343 | $data['text_text'] = $this->language->get('text_text'); |
||
| 344 | $data['text_textarea'] = $this->language->get('text_textarea'); |
||
| 345 | $data['text_file'] = $this->language->get('text_file'); |
||
| 346 | $data['text_date'] = $this->language->get('text_date'); |
||
| 347 | $data['text_datetime'] = $this->language->get('text_datetime'); |
||
| 348 | $data['text_time'] = $this->language->get('text_time'); |
||
| 349 | $data['text_account'] = $this->language->get('text_account'); |
||
| 350 | $data['text_address'] = $this->language->get('text_address'); |
||
| 351 | $data['text_enabled'] = $this->language->get('text_enabled'); |
||
| 352 | $data['text_disabled'] = $this->language->get('text_disabled'); |
||
| 353 | $data['text_regex'] = $this->language->get('text_regex'); |
||
| 354 | |||
| 355 | $data['entry_name'] = $this->language->get('entry_name'); |
||
| 356 | $data['entry_location'] = $this->language->get('entry_location'); |
||
| 357 | $data['entry_type'] = $this->language->get('entry_type'); |
||
| 358 | $data['entry_value'] = $this->language->get('entry_value'); |
||
| 359 | $data['entry_validation'] = $this->language->get('entry_validation'); |
||
| 360 | $data['entry_custom_value'] = $this->language->get('entry_custom_value'); |
||
| 361 | $data['entry_customer_group'] = $this->language->get('entry_customer_group'); |
||
| 362 | $data['entry_required'] = $this->language->get('entry_required'); |
||
| 363 | $data['entry_status'] = $this->language->get('entry_status'); |
||
| 364 | $data['entry_sort_order'] = $this->language->get('entry_sort_order'); |
||
| 365 | |||
| 366 | $data['help_regex'] = $this->language->get('help_regex'); |
||
| 367 | $data['help_sort_order'] = $this->language->get('help_sort_order'); |
||
| 368 | |||
| 369 | $data['button_save'] = $this->language->get('button_save'); |
||
| 370 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
| 371 | $data['button_custom_field_value_add'] = $this->language->get('button_custom_field_value_add'); |
||
| 372 | $data['button_remove'] = $this->language->get('button_remove'); |
||
| 373 | |||
| 374 | if (isset($this->error['warning'])) { |
||
| 375 | $data['error_warning'] = $this->error['warning']; |
||
| 376 | } else { |
||
| 377 | $data['error_warning'] = ''; |
||
| 378 | } |
||
| 379 | |||
| 380 | if (isset($this->error['name'])) { |
||
| 381 | $data['error_name'] = $this->error['name']; |
||
| 382 | } else { |
||
| 383 | $data['error_name'] = array(); |
||
| 384 | } |
||
| 385 | |||
| 386 | if (isset($this->error['custom_field_value'])) { |
||
| 387 | $data['error_custom_field_value'] = $this->error['custom_field_value']; |
||
| 388 | } else { |
||
| 389 | $data['error_custom_field_value'] = array(); |
||
| 390 | } |
||
| 391 | |||
| 392 | $url = ''; |
||
| 393 | |||
| 394 | if (isset($this->request->get['sort'])) { |
||
| 395 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 396 | } |
||
| 397 | |||
| 398 | if (isset($this->request->get['order'])) { |
||
| 399 | $url .= '&order=' . $this->request->get['order']; |
||
| 400 | } |
||
| 401 | |||
| 402 | if (isset($this->request->get['page'])) { |
||
| 403 | $url .= '&page=' . $this->request->get['page']; |
||
| 404 | } |
||
| 405 | |||
| 406 | $data['breadcrumbs'] = array(); |
||
| 407 | |||
| 408 | $data['breadcrumbs'][] = array( |
||
| 409 | 'text' => $this->language->get('text_home'), |
||
| 410 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
| 411 | ); |
||
| 412 | |||
| 413 | $data['breadcrumbs'][] = array( |
||
| 414 | 'text' => $this->language->get('heading_title'), |
||
| 415 | 'href' => $this->url->link('customer/custom_field', 'token=' . $this->session->data['token'] . $url, true) |
||
| 416 | ); |
||
| 417 | |||
| 418 | if (!isset($this->request->get['custom_field_id'])) { |
||
| 419 | $data['action'] = $this->url->link('customer/custom_field/add', 'token=' . $this->session->data['token'] . $url, true); |
||
| 420 | } else { |
||
| 421 | $data['action'] = $this->url->link('customer/custom_field/edit', 'token=' . $this->session->data['token'] . '&custom_field_id=' . $this->request->get['custom_field_id'] . $url, true); |
||
| 422 | } |
||
| 423 | |||
| 424 | $data['cancel'] = $this->url->link('customer/custom_field', 'token=' . $this->session->data['token'] . $url, true); |
||
| 425 | |||
| 426 | if (isset($this->request->get['custom_field_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
| 427 | $custom_field_info = $this->model_customer_custom_field->getCustomField($this->request->get['custom_field_id']); |
||
| 428 | } |
||
| 429 | |||
| 430 | $data['token'] = $this->session->data['token']; |
||
| 431 | |||
| 432 | $this->load->model('localisation/language'); |
||
| 433 | |||
| 434 | $data['languages'] = $this->model_localisation_language->getLanguages(); |
||
| 435 | |||
| 436 | if (isset($this->request->post['custom_field_description'])) { |
||
| 437 | $data['custom_field_description'] = $this->request->post['custom_field_description']; |
||
| 438 | } elseif (isset($this->request->get['custom_field_id'])) { |
||
| 439 | $data['custom_field_description'] = $this->model_customer_custom_field->getCustomFieldDescriptions($this->request->get['custom_field_id']); |
||
| 440 | } else { |
||
| 441 | $data['custom_field_description'] = array(); |
||
| 442 | } |
||
| 443 | |||
| 444 | if (isset($this->request->post['location'])) { |
||
| 445 | $data['location'] = $this->request->post['location']; |
||
| 446 | } elseif (!empty($custom_field_info)) { |
||
| 447 | $data['location'] = $custom_field_info['location']; |
||
| 448 | } else { |
||
| 449 | $data['location'] = ''; |
||
| 450 | } |
||
| 451 | |||
| 452 | if (isset($this->request->post['type'])) { |
||
| 453 | $data['type'] = $this->request->post['type']; |
||
| 454 | } elseif (!empty($custom_field_info)) { |
||
| 455 | $data['type'] = $custom_field_info['type']; |
||
| 456 | } else { |
||
| 457 | $data['type'] = ''; |
||
| 458 | } |
||
| 459 | |||
| 460 | if (isset($this->request->post['value'])) { |
||
| 461 | $data['value'] = $this->request->post['value']; |
||
| 462 | } elseif (!empty($custom_field_info)) { |
||
| 463 | $data['value'] = $custom_field_info['value']; |
||
| 464 | } else { |
||
| 465 | $data['value'] = ''; |
||
| 466 | } |
||
| 467 | |||
| 468 | if (isset($this->request->post['validation'])) { |
||
| 469 | $data['validation'] = $this->request->post['validation']; |
||
| 470 | } elseif (!empty($custom_field_info)) { |
||
| 471 | $data['validation'] = $custom_field_info['validation']; |
||
| 472 | } else { |
||
| 473 | $data['validation'] = ''; |
||
| 474 | } |
||
| 475 | |||
| 476 | if (isset($this->request->post['status'])) { |
||
| 477 | $data['status'] = $this->request->post['status']; |
||
| 478 | } elseif (!empty($custom_field_info)) { |
||
| 479 | $data['status'] = $custom_field_info['status']; |
||
| 480 | } else { |
||
| 481 | $data['status'] = ''; |
||
| 482 | } |
||
| 483 | |||
| 484 | if (isset($this->request->post['sort_order'])) { |
||
| 485 | $data['sort_order'] = $this->request->post['sort_order']; |
||
| 486 | } elseif (!empty($custom_field_info)) { |
||
| 487 | $data['sort_order'] = $custom_field_info['sort_order']; |
||
| 488 | } else { |
||
| 489 | $data['sort_order'] = ''; |
||
| 490 | } |
||
| 491 | |||
| 492 | if (isset($this->request->post['custom_field_value'])) { |
||
| 493 | $custom_field_values = $this->request->post['custom_field_value']; |
||
| 494 | } elseif (isset($this->request->get['custom_field_id'])) { |
||
| 495 | $custom_field_values = $this->model_customer_custom_field->getCustomFieldValueDescriptions($this->request->get['custom_field_id']); |
||
| 496 | } else { |
||
| 497 | $custom_field_values = array(); |
||
| 498 | } |
||
| 499 | |||
| 500 | $data['custom_field_values'] = array(); |
||
| 501 | |||
| 502 | foreach ($custom_field_values as $custom_field_value) { |
||
| 503 | $data['custom_field_values'][] = array( |
||
| 504 | 'custom_field_value_id' => $custom_field_value['custom_field_value_id'], |
||
| 505 | 'custom_field_value_description' => $custom_field_value['custom_field_value_description'], |
||
| 506 | 'sort_order' => $custom_field_value['sort_order'] |
||
| 507 | ); |
||
| 508 | } |
||
| 509 | |||
| 510 | if (isset($this->request->post['custom_field_customer_group'])) { |
||
| 511 | $custom_field_customer_groups = $this->request->post['custom_field_customer_group']; |
||
| 512 | } elseif (isset($this->request->get['custom_field_id'])) { |
||
| 513 | $custom_field_customer_groups = $this->model_customer_custom_field->getCustomFieldCustomerGroups($this->request->get['custom_field_id']); |
||
| 514 | } else { |
||
| 515 | $custom_field_customer_groups = array(); |
||
| 516 | } |
||
| 517 | |||
| 518 | $data['custom_field_customer_group'] = array(); |
||
| 519 | |||
| 520 | foreach ($custom_field_customer_groups as $custom_field_customer_group) { |
||
| 521 | $data['custom_field_customer_group'][] = $custom_field_customer_group['customer_group_id']; |
||
| 522 | } |
||
| 523 | |||
| 524 | $data['custom_field_required'] = array(); |
||
| 525 | |||
| 526 | foreach ($custom_field_customer_groups as $custom_field_customer_group) { |
||
| 527 | if ($custom_field_customer_group['required']) { |
||
| 528 | $data['custom_field_required'][] = $custom_field_customer_group['customer_group_id']; |
||
| 529 | } |
||
| 530 | } |
||
| 531 | |||
| 532 | $this->load->model('customer/customer_group'); |
||
| 533 | |||
| 534 | $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); |
||
| 535 | |||
| 536 | $data['header'] = $this->load->controller('common/header'); |
||
| 537 | $data['column'] = $this->load->controller('common/column_left'); |
||
| 538 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 539 | |||
| 540 | $this->response->setOutput($this->load->view('customer/custom_field_form', $data)); |
||
| 541 | } |
||
| 583 |
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.