| Conditions | 3 |
| Paths | 3 |
| Total Lines | 61 |
| Code Lines | 42 |
| 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 |
||
| 13 | public function index() { |
||
| 14 | |||
| 15 | $this->load->helper('form'); |
||
| 16 | $this->load->library('form_validation'); |
||
| 17 | |||
| 18 | // validation rules |
||
| 19 | $this->form_validation->set_rules('staff_full', 'Staff Full Name', 'trim|required|min_length[6]'); |
||
| 20 | $this->form_validation->set_rules('make', 'Device Make', 'trim|required|min_length[3]'); |
||
| 21 | $this->form_validation->set_rules('model', 'Device Model', 'trim|required|min_length[3]'); |
||
| 22 | $this->form_validation->set_rules('sn', 'Device Serial Number', 'trim|required|min_length[3]'); |
||
| 23 | |||
| 24 | if ($this->form_validation->run() === false) { |
||
| 25 | |||
| 26 | $this->load->view('templates/header'); |
||
| 27 | $this->load->view('computing-support/ownership/view'); |
||
| 28 | $this->load->view('templates/footer'); |
||
| 29 | } else { |
||
| 30 | |||
| 31 | $logged = $this->input->post('logged'); |
||
| 32 | $staff_full = $this->input->post('staff_full'); |
||
| 33 | $make = $this->input->post('make'); |
||
| 34 | $model = $this->input->post('model'); |
||
| 35 | $sn = $this->input->post('sn'); |
||
| 36 | |||
| 37 | if ($this->ownership_model->create($logged, $staff_full, $make, $model, $sn)) { |
||
| 38 | |||
| 39 | $staff_email = $this->ownership_model->email_id($staff_full); |
||
| 40 | |||
| 41 | $this->email->from('[email protected]', 'Ownership Transfer'); |
||
| 42 | $this->email->to($staff_email[0]['email']); |
||
| 43 | $this->email->subject('Ownership Transfer Request'); |
||
| 44 | $this->email->message('An IT equipment ownership transfer request has been submitted.' |
||
| 45 | . 'You must accept the terms and conditions at the following link before it can be approved by Computing Support.' |
||
| 46 | . '' |
||
| 47 | . 'https://intranet.cant-col.ac.uk/dashboard/computing-support/ownership/check' |
||
| 48 | . '' |
||
| 49 | . 'Use the same link to cancel the request or/and check the progress.'); |
||
| 50 | $this->email->send(); |
||
| 51 | |||
| 52 | $function = 'ownership_application'; |
||
| 53 | $this->user_model->function_log($function); |
||
| 54 | |||
| 55 | // user created |
||
| 56 | $this->load->view('templates/header'); |
||
| 57 | $this->load->view('computing-support/ownership/requested'); |
||
| 58 | $this->load->view('templates/footer'); |
||
| 59 | } else { |
||
| 60 | |||
| 61 | $function = 'ownership_error'; |
||
| 62 | $this->user_model->function_log($function); |
||
| 63 | |||
| 64 | $data = new stdClass(); |
||
| 65 | $data->error = 'There was a problem submitting this request. Please try again.'; |
||
| 66 | |||
| 67 | // failed to create user |
||
| 68 | $this->load->view('templates/header'); |
||
| 69 | $this->load->view('computing-support/ownership/view', $data); |
||
| 70 | $this->load->view('templates/footer'); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 240 |
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.