| Conditions | 9 |
| Paths | 11 |
| Total Lines | 57 |
| 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 |
||
| 82 | public function ajaxSubmit() { |
||
| 83 | |||
| 84 | $this->load->library('form_validation'); |
||
| 85 | $this->form_validation->set_rules('user_email', lang('Your e-mail', 'mailer'), 'required|trim|valid_email'); |
||
| 86 | |||
| 87 | if ($this->form_validation->run($this) == FALSE) { |
||
| 88 | assetManager::create() |
||
| 89 | ->setData( |
||
| 90 | [ |
||
| 91 | 'mailer_errors' => validation_errors(), |
||
| 92 | ] |
||
| 93 | ) |
||
| 94 | ->render('error', true); |
||
| 95 | } else { |
||
| 96 | |||
| 97 | $email = $this->input->post('user_email'); |
||
| 98 | |||
| 99 | /** @var CI_DB_result $query */ |
||
| 100 | $query = $this->db->get_where('mail', ['email' => $email]); |
||
| 101 | $row = $query->num_rows() > 0 ? $query->row() : false; |
||
| 102 | |||
| 103 | if ($row && $this->input->post('add_user_mail') != 1) { |
||
| 104 | |||
| 105 | assetManager::create()->render('already', true); |
||
| 106 | exit; |
||
| 107 | } elseif (!$row && $this->input->post('add_user_mail') == 1) { |
||
| 108 | |||
| 109 | assetManager::create()->render('no', true); |
||
| 110 | exit; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($this->input->post('add_user_mail') == 2) { |
||
| 114 | |||
| 115 | if ($this->dx_auth->is_email_available($email)) { |
||
| 116 | |||
| 117 | $this->registerUserByEmail($email); |
||
| 118 | } |
||
| 119 | |||
| 120 | $date = date('U'); |
||
| 121 | $data = [ |
||
| 122 | 'email' => $email, |
||
| 123 | 'date' => $date, |
||
| 124 | ]; |
||
| 125 | |||
| 126 | $this->db->insert('mail', $data); |
||
| 127 | assetManager::create() |
||
| 128 | ->setData( |
||
| 129 | ['email' => $query] |
||
| 130 | ) |
||
| 131 | ->render('success', true); |
||
| 132 | |||
| 133 | } else { |
||
| 134 | $this->db->delete('mail', ['email' => $email]); |
||
| 135 | assetManager::create()->render('cancel', true); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 246 | /* End of file mailer.php */ |