| Conditions | 10 |
| Paths | 20 |
| Total Lines | 51 |
| 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 |
||
| 30 | public function index() { |
||
| 31 | $this->load->library('form_validation'); |
||
| 32 | |||
| 33 | if ($this->input->post()) { |
||
| 34 | |||
| 35 | $this->form_validation->set_rules('user_email', lang('Your e-mail', 'mailer'), 'required|trim|valid_email'); |
||
| 36 | |||
| 37 | if ($this->form_validation->run($this) == FALSE) { |
||
| 38 | |||
| 39 | echo $errors = validation_errors(); |
||
| 40 | redirect('/mailer/error/'); |
||
| 41 | } else { |
||
| 42 | |||
| 43 | $email = $this->input->post('user_email'); |
||
| 44 | |||
| 45 | /** @var CI_DB_result $query */ |
||
| 46 | $query = $this->db->get_where('mail', ['email' => $email]); |
||
| 47 | $row = $query->num_rows() > 0 ? $query->row() : false; |
||
| 48 | |||
| 49 | if ($row && $this->input->post('add_user_mail') != 1) { |
||
| 50 | redirect('/mailer/already/'); |
||
| 51 | |||
| 52 | } elseif (!$row && $this->input->post('add_user_mail') == 1) { |
||
| 53 | redirect('/mailer/no/'); |
||
| 54 | |||
| 55 | } |
||
| 56 | |||
| 57 | if ($this->input->post('add_user_mail') == 2) { |
||
| 58 | |||
| 59 | $date = date('U'); |
||
| 60 | |||
| 61 | if ($this->dx_auth->is_email_available($email)) { |
||
| 62 | |||
| 63 | $this->registerUserByEmail($email); |
||
| 64 | } |
||
| 65 | |||
| 66 | $data = [ |
||
| 67 | 'email' => $email, |
||
| 68 | 'date' => $date, |
||
| 69 | ]; |
||
| 70 | |||
| 71 | $this->db->insert('mail', $data); |
||
| 72 | |||
| 73 | redirect('/mailer/success/'); |
||
| 74 | } else { |
||
| 75 | $this->db->delete('mail', ['email' => $email]); |
||
| 76 | redirect('/mailer/cancel/'); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 246 | /* End of file mailer.php */ |