| Total Complexity | 90 |
| Total Lines | 537 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ControllerMarketingMarketing often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ControllerMarketingMarketing, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class ControllerMarketingMarketing extends \Divine\Engine\Core\Controller |
||
|
|
|||
| 24 | { |
||
| 25 | private $error = array(); |
||
| 26 | |||
| 27 | public function index() |
||
| 28 | { |
||
| 29 | $this->load->language('marketing/marketing'); |
||
| 30 | |||
| 31 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 32 | |||
| 33 | $this->load->model('marketing/marketing'); |
||
| 34 | |||
| 35 | $this->getList(); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function add() |
||
| 39 | { |
||
| 40 | $this->load->language('marketing/marketing'); |
||
| 41 | |||
| 42 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 43 | |||
| 44 | $this->load->model('marketing/marketing'); |
||
| 45 | |||
| 46 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
||
| 47 | $this->model_marketing_marketing->addMarketing($this->request->post); |
||
| 48 | |||
| 49 | $this->session->data['success'] = $this->language->get('text_success'); |
||
| 50 | |||
| 51 | $url = ''; |
||
| 52 | |||
| 53 | if (isset($this->request->get['filter_name'])) { |
||
| 54 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
||
| 55 | } |
||
| 56 | |||
| 57 | if (isset($this->request->get['filter_code'])) { |
||
| 58 | $url .= '&filter_code=' . $this->request->get['filter_code']; |
||
| 59 | } |
||
| 60 | |||
| 61 | if (isset($this->request->get['filter_date_added'])) { |
||
| 62 | $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; |
||
| 63 | } |
||
| 64 | |||
| 65 | if (isset($this->request->get['sort'])) { |
||
| 66 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 67 | } |
||
| 68 | |||
| 69 | if (isset($this->request->get['order'])) { |
||
| 70 | $url .= '&order=' . $this->request->get['order']; |
||
| 71 | } |
||
| 72 | |||
| 73 | if (isset($this->request->get['page'])) { |
||
| 74 | $url .= '&page=' . $this->request->get['page']; |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->response->redirect($this->url->link('marketing/marketing', 'token=' . $this->session->data['token'] . $url, true)); |
||
| 78 | } |
||
| 79 | |||
| 80 | $this->getForm(); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function edit() |
||
| 84 | { |
||
| 85 | $this->load->language('marketing/marketing'); |
||
| 86 | |||
| 87 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 88 | |||
| 89 | $this->load->model('marketing/marketing'); |
||
| 90 | |||
| 91 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
||
| 92 | $this->model_marketing_marketing->editMarketing($this->request->get['marketing_id'], $this->request->post); |
||
| 93 | |||
| 94 | $this->session->data['success'] = $this->language->get('text_success'); |
||
| 95 | |||
| 96 | $url = ''; |
||
| 97 | |||
| 98 | if (isset($this->request->get['filter_name'])) { |
||
| 99 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
||
| 100 | } |
||
| 101 | |||
| 102 | if (isset($this->request->get['filter_code'])) { |
||
| 103 | $url .= '&filter_code=' . $this->request->get['filter_code']; |
||
| 104 | } |
||
| 105 | |||
| 106 | if (isset($this->request->get['filter_date_added'])) { |
||
| 107 | $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; |
||
| 108 | } |
||
| 109 | |||
| 110 | if (isset($this->request->get['sort'])) { |
||
| 111 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (isset($this->request->get['order'])) { |
||
| 115 | $url .= '&order=' . $this->request->get['order']; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (isset($this->request->get['page'])) { |
||
| 119 | $url .= '&page=' . $this->request->get['page']; |
||
| 120 | } |
||
| 121 | |||
| 122 | $this->response->redirect($this->url->link('marketing/marketing', 'token=' . $this->session->data['token'] . $url, true)); |
||
| 123 | } |
||
| 124 | |||
| 125 | $this->getForm(); |
||
| 126 | } |
||
| 127 | |||
| 128 | public function delete() |
||
| 129 | { |
||
| 130 | $this->load->language('marketing/marketing'); |
||
| 131 | |||
| 132 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 133 | |||
| 134 | $this->load->model('marketing/marketing'); |
||
| 135 | |||
| 136 | if (isset($this->request->post['selected']) && $this->validateDelete()) { |
||
| 137 | foreach ($this->request->post['selected'] as $marketing_id) { |
||
| 138 | $this->model_marketing_marketing->deleteMarketing($marketing_id); |
||
| 139 | } |
||
| 140 | |||
| 141 | $this->session->data['success'] = $this->language->get('text_success'); |
||
| 142 | |||
| 143 | $url = ''; |
||
| 144 | |||
| 145 | if (isset($this->request->get['filter_name'])) { |
||
| 146 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (isset($this->request->get['filter_code'])) { |
||
| 150 | $url .= '&filter_code=' . $this->request->get['filter_code']; |
||
| 151 | } |
||
| 152 | |||
| 153 | if (isset($this->request->get['filter_date_added'])) { |
||
| 154 | $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; |
||
| 155 | } |
||
| 156 | |||
| 157 | if (isset($this->request->get['sort'])) { |
||
| 158 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 159 | } |
||
| 160 | |||
| 161 | if (isset($this->request->get['order'])) { |
||
| 162 | $url .= '&order=' . $this->request->get['order']; |
||
| 163 | } |
||
| 164 | |||
| 165 | if (isset($this->request->get['page'])) { |
||
| 166 | $url .= '&page=' . $this->request->get['page']; |
||
| 167 | } |
||
| 168 | |||
| 169 | $this->response->redirect($this->url->link('marketing/marketing', 'token=' . $this->session->data['token'] . $url, true)); |
||
| 170 | } |
||
| 171 | |||
| 172 | $this->getList(); |
||
| 173 | } |
||
| 174 | |||
| 175 | protected function getList() |
||
| 402 | } |
||
| 403 | |||
| 404 | protected function getForm() |
||
| 405 | { |
||
| 406 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 407 | |||
| 408 | $data['text_form'] = !isset($this->request->get['marketing_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
| 409 | |||
| 410 | $data['entry_name'] = $this->language->get('entry_name'); |
||
| 411 | $data['entry_description'] = $this->language->get('entry_description'); |
||
| 412 | $data['entry_code'] = $this->language->get('entry_code'); |
||
| 413 | $data['entry_example'] = $this->language->get('entry_example'); |
||
| 414 | |||
| 415 | $data['help_code'] = $this->language->get('help_code'); |
||
| 416 | $data['help_example'] = $this->language->get('help_example'); |
||
| 417 | |||
| 418 | $data['button_save'] = $this->language->get('button_save'); |
||
| 419 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
| 420 | |||
| 421 | if (isset($this->error['warning'])) { |
||
| 422 | $data['error_warning'] = $this->error['warning']; |
||
| 423 | } else { |
||
| 424 | $data['error_warning'] = ''; |
||
| 425 | } |
||
| 426 | |||
| 427 | if (isset($this->error['name'])) { |
||
| 428 | $data['error_name'] = $this->error['name']; |
||
| 429 | } else { |
||
| 430 | $data['error_name'] = ''; |
||
| 431 | } |
||
| 432 | |||
| 433 | if (isset($this->error['code'])) { |
||
| 434 | $data['error_code'] = $this->error['code']; |
||
| 435 | } else { |
||
| 436 | $data['error_code'] = ''; |
||
| 437 | } |
||
| 438 | |||
| 439 | $url = ''; |
||
| 440 | |||
| 441 | if (isset($this->request->get['filter_name'])) { |
||
| 442 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
||
| 443 | } |
||
| 444 | |||
| 445 | if (isset($this->request->get['filter_code'])) { |
||
| 446 | $url .= '&filter_code=' . $this->request->get['filter_code']; |
||
| 447 | } |
||
| 448 | |||
| 449 | if (isset($this->request->get['filter_date_added'])) { |
||
| 450 | $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; |
||
| 451 | } |
||
| 452 | |||
| 453 | if (isset($this->request->get['sort'])) { |
||
| 454 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 455 | } |
||
| 456 | |||
| 457 | if (isset($this->request->get['order'])) { |
||
| 458 | $url .= '&order=' . $this->request->get['order']; |
||
| 459 | } |
||
| 460 | |||
| 461 | if (isset($this->request->get['page'])) { |
||
| 462 | $url .= '&page=' . $this->request->get['page']; |
||
| 463 | } |
||
| 464 | |||
| 465 | $data['breadcrumbs'] = array(); |
||
| 466 | |||
| 467 | $data['breadcrumbs'][] = array( |
||
| 468 | 'text' => $this->language->get('text_home'), |
||
| 469 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
| 470 | ); |
||
| 471 | |||
| 472 | $data['breadcrumbs'][] = array( |
||
| 473 | 'text' => $this->language->get('heading_title'), |
||
| 474 | 'href' => $this->url->link('marketing/marketing', 'token=' . $this->session->data['token'] . $url, true) |
||
| 475 | ); |
||
| 476 | |||
| 477 | if (!isset($this->request->get['marketing_id'])) { |
||
| 478 | $data['action'] = $this->url->link('marketing/marketing/add', 'token=' . $this->session->data['token'] . $url, true); |
||
| 479 | } else { |
||
| 480 | $data['action'] = $this->url->link('marketing/marketing/edit', 'token=' . $this->session->data['token'] . '&marketing_id=' . $this->request->get['marketing_id'] . $url, true); |
||
| 481 | } |
||
| 482 | |||
| 483 | $data['cancel'] = $this->url->link('marketing/marketing', 'token=' . $this->session->data['token'] . $url, true); |
||
| 484 | |||
| 485 | if (isset($this->request->get['marketing_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
| 486 | $marketing_info = $this->model_marketing_marketing->getMarketing($this->request->get['marketing_id']); |
||
| 487 | } |
||
| 488 | |||
| 489 | $data['token'] = $this->session->data['token']; |
||
| 490 | |||
| 491 | $data['store'] = '/'; |
||
| 492 | |||
| 493 | if (isset($this->request->post['name'])) { |
||
| 494 | $data['name'] = $this->request->post['name']; |
||
| 495 | } elseif (!empty($marketing_info)) { |
||
| 496 | $data['name'] = $marketing_info['name']; |
||
| 497 | } else { |
||
| 498 | $data['name'] = ''; |
||
| 499 | } |
||
| 500 | |||
| 501 | if (isset($this->request->post['description'])) { |
||
| 502 | $data['description'] = $this->request->post['description']; |
||
| 503 | } elseif (!empty($marketing_info)) { |
||
| 504 | $data['description'] = $marketing_info['description']; |
||
| 505 | } else { |
||
| 506 | $data['description'] = ''; |
||
| 507 | } |
||
| 508 | |||
| 509 | if (isset($this->request->post['code'])) { |
||
| 510 | $data['code'] = $this->request->post['code']; |
||
| 511 | } elseif (!empty($marketing_info)) { |
||
| 512 | $data['code'] = $marketing_info['code']; |
||
| 513 | } else { |
||
| 514 | $data['code'] = uniqid(); |
||
| 515 | } |
||
| 516 | |||
| 517 | $data['header'] = $this->load->controller('common/header'); |
||
| 518 | $data['column'] = $this->load->controller('common/column_left'); |
||
| 519 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 520 | |||
| 521 | $this->response->setOutput($this->load->view('marketing/marketing_form', $data)); |
||
| 522 | } |
||
| 523 | |||
| 524 | protected function validateForm() |
||
| 525 | { |
||
| 526 | if (!$this->user->hasPermission('modify', 'marketing/marketing')) { |
||
| 527 | $this->error['warning'] = $this->language->get('error_permission'); |
||
| 528 | } |
||
| 529 | |||
| 530 | if ((\voku\helper\UTF8::strlen($this->request->post['name']) < 1) || (\voku\helper\UTF8::strlen($this->request->post['name']) > 32)) { |
||
| 531 | $this->error['name'] = $this->language->get('error_name'); |
||
| 532 | } |
||
| 533 | |||
| 534 | if (!$this->request->post['code']) { |
||
| 535 | $this->error['code'] = $this->language->get('error_code'); |
||
| 536 | } |
||
| 537 | |||
| 538 | $marketing_info = $this->model_marketing_marketing->getMarketingByCode($this->request->post['code']); |
||
| 539 | |||
| 540 | if (!isset($this->request->get['marketing_id'])) { |
||
| 541 | if ($marketing_info) { |
||
| 542 | $this->error['code'] = $this->language->get('error_exists'); |
||
| 543 | } |
||
| 544 | } else { |
||
| 545 | if ($marketing_info && ($this->request->get['marketing_id'] != $marketing_info['marketing_id'])) { |
||
| 546 | $this->error['code'] = $this->language->get('error_exists'); |
||
| 547 | } |
||
| 548 | } |
||
| 549 | |||
| 550 | return !$this->error; |
||
| 551 | } |
||
| 552 | |||
| 553 | protected function validateDelete() |
||
| 560 | } |
||
| 561 | } |
||
| 562 |
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.