Conditions | 4 |
Paths | 4 |
Total Lines | 55 |
Code Lines | 36 |
Lines | 22 |
Ratio | 40 % |
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 |
||
11 | public function index() { |
||
12 | |||
13 | if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
||
14 | |||
15 | $this->load->helper('form'); |
||
16 | $this->load->library('form_validation'); |
||
17 | |||
18 | // validation rules |
||
19 | $this->form_validation->set_rules('full_name', 'First Name', 'trim|required|min_length[3]'); |
||
20 | $this->form_validation->set_rules('ern', 'ERN', 'trim|required|min_length[7]'); |
||
21 | $this->form_validation->set_rules('make', 'Make', 'trim|required|min_length[3]'); |
||
22 | $this->form_validation->set_rules('model', 'Model', 'trim|required|min_length[3]'); |
||
23 | $this->form_validation->set_rules('sn', 'Serial Number', 'trim|required|min_length[3]'); |
||
24 | |||
25 | if ($this->form_validation->run() === false) { |
||
26 | |||
27 | $this->load->view('templates/header'); |
||
28 | $this->load->view('computing-support/equipment-loan/view'); |
||
29 | $this->load->view('templates/footer'); |
||
30 | } else { |
||
31 | |||
32 | $logged = $this->input->post('logged'); |
||
33 | $first_name = $this->input->post('full_name'); |
||
|
|||
34 | $ern = $this->input->post('ern'); |
||
35 | $make = $this->input->post('make'); |
||
36 | $model = $this->input->post('model'); |
||
37 | $sn = $this->input->post('sn'); |
||
38 | |||
39 | View Code Duplication | if ($this->equipment_loan_model->loan($logged, $full_name, $ern, $make, $model, $sn)) { |
|
40 | |||
41 | $function = 'new_loan'; |
||
42 | $this->user_model->function_log($function); |
||
43 | |||
44 | // user created |
||
45 | $this->load->view('templates/header'); |
||
46 | $this->load->view('computing-support/equipment-loan/complete'); |
||
47 | $this->load->view('templates/footer'); |
||
48 | } else { |
||
49 | |||
50 | $function = 'new_loan_error'; |
||
51 | $this->user_model->function_log($function); |
||
52 | |||
53 | $data = new stdClass(); |
||
54 | $data->error = 'There was a problem accepting the terms. Please try again.'; |
||
55 | |||
56 | // failed to create user |
||
57 | $this->load->view('templates/header'); |
||
58 | $this->load->view('computing-support/equipment-loan/view', $data); |
||
59 | $this->load->view('templates/footer'); |
||
60 | } |
||
61 | } |
||
62 | } else { |
||
63 | redirect('permissions'); |
||
64 | } |
||
65 | } |
||
66 | |||
94 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.