Conditions | 3 |
Paths | 3 |
Total Lines | 66 |
Code Lines | 45 |
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 defined('BASEPATH') OR exit('No direct script access allowed'); |
||
11 | public function index() { |
||
12 | |||
13 | $this->load->helper('form'); |
||
14 | $this->load->library('form_validation'); |
||
15 | |||
16 | $data = array(); |
||
17 | $data['faculty'] = $this->address_book_model->get_faculty(); |
||
18 | $data['department'] = $this->address_book_model->get_department(); |
||
19 | |||
20 | // validation rules |
||
21 | $this->form_validation->set_rules('phone', 'Phone', 'trim|numeric'); |
||
22 | |||
23 | if ($this->form_validation->run() === false) { |
||
24 | |||
25 | $this->load->view('templates/header'); |
||
26 | $this->load->view('computing-support/address-book/view', $data); |
||
27 | $this->load->view('templates/footer'); |
||
28 | } else { |
||
29 | |||
30 | $faculty = $this->input->post('faculty'); |
||
31 | $department = $this->input->post('department'); |
||
32 | $name = $this->input->post('name'); |
||
33 | $room = $this->input->post('room'); |
||
34 | $phone = $this->input->post('phone'); |
||
35 | $position = $this->input->post('position'); |
||
36 | |||
37 | $faculty = $this->address_book_model->get_faculty_from_number($faculty); |
||
38 | $department = $this->address_book_model->get_department_from_number($department); |
||
39 | |||
40 | if ($this->address_book_model->change($faculty, $department, $name, $room, $phone, $position)) { |
||
41 | |||
42 | $function = 'address_book_update'; |
||
43 | $this->user_model->function_log($function); |
||
44 | |||
45 | $this->email->from('[email protected]', 'Address Book Update'); |
||
46 | $this->email->to('[email protected]'); |
||
47 | $this->email->subject('Address Book Update'); |
||
48 | $this->email->message('A global address book update request been made by ' . $_SESSION['ldap']['full_name'] . ' |
||
49 | Change name to: ' . $name . ' |
||
50 | Change Faculty to: ' . $faculty[0]['faculty'] . ' |
||
51 | Change Department to: ' . $department[0]['subfaculty'] . ' |
||
52 | Change Room to : ' . $room . ' |
||
53 | Change Telephone to : ' . $phone.' |
||
54 | Change Position to : ' . $position); |
||
55 | |||
56 | $this->email->send(); |
||
57 | |||
58 | // user created |
||
59 | $this->load->view('templates/header'); |
||
60 | $this->load->view('computing-support/address-book/complete'); |
||
61 | $this->load->view('templates/footer'); |
||
62 | } else { |
||
63 | |||
64 | $function = 'address_book_error'; |
||
65 | $this->user_model->function_log($function); |
||
66 | |||
67 | $data = new stdClass(); |
||
68 | $data->error = 'There was a problem requesting these changes. Please try again.'; |
||
69 | |||
70 | // failed to create user |
||
71 | $this->load->view('templates/header'); |
||
72 | $this->load->view('computing-support/address-book/view', $data); |
||
73 | $this->load->view('templates/footer'); |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
103 |