| Conditions | 13 |
| Paths | 264 |
| Total Lines | 93 |
| Code Lines | 55 |
| 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 |
||
| 27 | public function index() |
||
| 28 | { |
||
| 29 | if ($this->user->isLogged() && isset($this->request->get['token']) && ($this->request->get['token'] == $this->session->data['token'])) { |
||
| 30 | $this->response->redirect($this->url->link('common/dashboard', '', true)); |
||
| 31 | } |
||
| 32 | |||
| 33 | if (!$this->config->get('config_password')) { |
||
| 34 | $this->response->redirect($this->url->link('common/login', '', true)); |
||
| 35 | } |
||
| 36 | |||
| 37 | if (isset($this->request->get['code'])) { |
||
| 38 | $code = $this->request->get['code']; |
||
| 39 | } else { |
||
| 40 | $code = ''; |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->load->model('user/user'); |
||
| 44 | |||
| 45 | $user_info = $this->model_user_user->getUserByCode($code); |
||
| 46 | |||
| 47 | if ($user_info) { |
||
| 48 | $this->load->language('common/reset'); |
||
| 49 | |||
| 50 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 51 | |||
| 52 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { |
||
| 53 | $this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']); |
||
| 54 | |||
| 55 | $this->session->data['success'] = $this->language->get('text_success'); |
||
| 56 | |||
| 57 | $this->response->redirect($this->url->link('common/login', '', true)); |
||
| 58 | } |
||
| 59 | |||
| 60 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 61 | |||
| 62 | $data['text_password'] = $this->language->get('text_password'); |
||
| 63 | |||
| 64 | $data['entry_password'] = $this->language->get('entry_password'); |
||
| 65 | $data['entry_confirm'] = $this->language->get('entry_confirm'); |
||
| 66 | |||
| 67 | $data['button_save'] = $this->language->get('button_save'); |
||
| 68 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
| 69 | |||
| 70 | $data['breadcrumbs'] = array(); |
||
| 71 | |||
| 72 | $data['breadcrumbs'][] = array( |
||
| 73 | 'text' => $this->language->get('text_home'), |
||
| 74 | 'href' => $this->url->link('common/dashboard', '', true) |
||
| 75 | ); |
||
| 76 | |||
| 77 | $data['breadcrumbs'][] = array( |
||
| 78 | 'text' => $this->language->get('heading_title'), |
||
| 79 | 'href' => $this->url->link('common/reset', '', true) |
||
| 80 | ); |
||
| 81 | |||
| 82 | if (isset($this->error['password'])) { |
||
| 83 | $data['error_password'] = $this->error['password']; |
||
| 84 | } else { |
||
| 85 | $data['error_password'] = ''; |
||
| 86 | } |
||
| 87 | |||
| 88 | if (isset($this->error['confirm'])) { |
||
| 89 | $data['error_confirm'] = $this->error['confirm']; |
||
| 90 | } else { |
||
| 91 | $data['error_confirm'] = ''; |
||
| 92 | } |
||
| 93 | |||
| 94 | $data['action'] = $this->url->link('common/reset', 'code=' . $code, true); |
||
| 95 | |||
| 96 | $data['cancel'] = $this->url->link('common/login', '', true); |
||
| 97 | |||
| 98 | if (isset($this->request->post['password'])) { |
||
| 99 | $data['password'] = $this->request->post['password']; |
||
| 100 | } else { |
||
| 101 | $data['password'] = ''; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (isset($this->request->post['confirm'])) { |
||
| 105 | $data['confirm'] = $this->request->post['confirm']; |
||
| 106 | } else { |
||
| 107 | $data['confirm'] = ''; |
||
| 108 | } |
||
| 109 | |||
| 110 | $data['header'] = $this->load->controller('common/header'); |
||
| 111 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 112 | |||
| 113 | $this->response->setOutput($this->load->view('common/reset', $data)); |
||
| 114 | } else { |
||
| 115 | $this->load->model('setting/setting'); |
||
| 116 | |||
| 117 | $this->model_setting_setting->editSettingValue('config', 'config_password', '0'); |
||
| 118 | |||
| 119 | return new \Divine\Engine\Core\Action('common/login'); |
||
| 120 | } |
||
| 136 |
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.