Conditions | 7 |
Paths | 4 |
Total Lines | 60 |
Code Lines | 41 |
Lines | 19 |
Ratio | 31.67 % |
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 |
||
13 | public function index() { |
||
14 | |||
15 | if (isset($_COOKIE['CI_PASSKEY']) === TRUE && in_array('visitor', unserialize($_COOKIE['CI_PASSKEY'])) || |
||
16 | in_array('CN=Intranet_Edit_Marketing,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) || |
||
17 | in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['dashboard_groups'])) { |
||
18 | |||
19 | $this->load->helper('form'); |
||
20 | $this->load->library('form_validation'); |
||
21 | |||
22 | // validation rules |
||
23 | $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|min_length[2]'); |
||
24 | $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|min_length[2]'); |
||
25 | $this->form_validation->set_rules('dob_d', 'Date of Birth Day', 'trim|required|numeric|min_length[2]'); |
||
26 | $this->form_validation->set_rules('dob_m', 'Date of Birth Month', 'trim|required|numeric|min_length[2]'); |
||
27 | $this->form_validation->set_rules('dob_y', 'Date of Birth Year', 'trim|required|numeric|min_length[4]'); |
||
28 | |||
29 | if ($this->form_validation->run() === false) { |
||
30 | |||
31 | $this->load->view('templates/header'); |
||
32 | $this->load->view('marketing/visitor/view'); |
||
33 | $this->load->view('templates/footer'); |
||
34 | } else { |
||
35 | |||
36 | $first_name = $this->input->post('first_name'); |
||
37 | $last_name = $this->input->post('last_name'); |
||
38 | $email = $this->input->post('email'); |
||
39 | $postcode = $this->input->post('postcode'); |
||
40 | $dob = $this->input->post('dob_d') . '/' . $this->input->post('dob_m') . '/' . $this->input->post('dob_y'); |
||
41 | $current = $this->input->post('current'); |
||
42 | $current_other = $this->input->post('current_other'); |
||
43 | $subject = $this->input->post('subject'); |
||
44 | $hear = $this->input->post('hear'); |
||
45 | $year = $this->input->post('year'); |
||
46 | |||
47 | View Code Duplication | if ($this->visitor_model->post($first_name, $last_name, $email, $postcode, $dob, $current, $current_other, $subject, $hear, $year)) { |
|
|
|||
48 | |||
49 | // user created |
||
50 | $this->load->view('templates/header'); |
||
51 | $this->load->view('marketing/visitor/complete'); |
||
52 | $this->load->view('templates/footer'); |
||
53 | } else { |
||
54 | |||
55 | $function = 'ERROR_visitor_form_submition'; |
||
56 | $this->user_model->function_log($function); |
||
57 | |||
58 | $data = new stdClass(); |
||
59 | $data->error = 'There was a problem submitting this form. Please try again.'; |
||
60 | |||
61 | // failed to create user |
||
62 | $this->load->view('templates/header'); |
||
63 | $this->load->view('marketing/visitor/view', $data); |
||
64 | $this->load->view('templates/footer'); |
||
65 | } |
||
66 | } |
||
67 | } else { |
||
68 | |||
69 | $this->session->set_userdata('last_url', current_url()); |
||
70 | redirect('authentication/passkey?id=visitor'); |
||
71 | } |
||
72 | } |
||
73 | |||
108 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.