| Conditions | 22 |
| Paths | 34 |
| Total Lines | 161 |
| Code Lines | 99 |
| Lines | 48 |
| Ratio | 29.81 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 10 | public function main($id, $mode) |
||
|
|
|||
| 11 | { |
||
| 12 | |||
| 13 | global $phpbb_container, $request, $user; |
||
| 14 | |||
| 15 | $friends_controller = $phpbb_container->get('florinp.messenger.friends.controller'); |
||
| 16 | $friends_controller->set_page_url($this->u_action); |
||
| 17 | |||
| 18 | $this->tpl_name = 'friends'; |
||
| 19 | |||
| 20 | switch ($mode) |
||
| 21 | { |
||
| 22 | case 'friends': |
||
| 23 | |||
| 24 | $action = $request->variable('action', ''); |
||
| 25 | switch ($action) |
||
| 26 | { |
||
| 27 | View Code Duplication | case 'add_friend': |
|
| 28 | $user_id = $request->variable('user_id', 0); |
||
| 29 | if ($user_id > 0) |
||
| 30 | { |
||
| 31 | if (confirm_box(true)) |
||
| 32 | { |
||
| 33 | $user_id = $request->variable('user_id', 0); |
||
| 34 | $redirect_url = $request->variable('redirect_url', ''); |
||
| 35 | if ($friends_controller->send_request($user_id)) |
||
| 36 | { |
||
| 37 | redirect($redirect_url); |
||
| 38 | } |
||
| 39 | } else |
||
| 40 | { |
||
| 41 | $user_id = $request->variable('user_id', 0); |
||
| 42 | $redirect_url = $request->server('HTTP_REFERER'); |
||
| 43 | confirm_box(false, $user->lang('CONFIRM_ADD_FRIEND'), build_hidden_fields(array( |
||
| 44 | 'user_id' => $user_id, |
||
| 45 | 'redirect_url' => $redirect_url, |
||
| 46 | ))); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | break; |
||
| 50 | View Code Duplication | case 'remove_friend': |
|
| 51 | $user_id = $request->variable('user_id', 0); |
||
| 52 | if ($user_id > 0) |
||
| 53 | { |
||
| 54 | if (confirm_box(true)) |
||
| 55 | { |
||
| 56 | $user_id = $request->variable('user_id', 0); |
||
| 57 | $redirect_url = $request->variable('redirect_url', ''); |
||
| 58 | if ($friends_controller->remove_friend($user_id)) |
||
| 59 | { |
||
| 60 | redirect($redirect_url); |
||
| 61 | } |
||
| 62 | } else |
||
| 63 | { |
||
| 64 | $user_id = $request->variable('user_id', 0); |
||
| 65 | $redirect_url = $request->server('HTTP_REFERER'); |
||
| 66 | confirm_box(false, $user->lang('CONFIRM_REMOVE_FRIEND'), build_hidden_fields(array( |
||
| 67 | 'user_id' => $user_id, |
||
| 68 | 'redirect_url' => $redirect_url, |
||
| 69 | ))); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | break; |
||
| 73 | default: |
||
| 74 | if ($request->is_set_post('action')) |
||
| 75 | { |
||
| 76 | $action = $request->variable('action', ''); |
||
| 77 | switch ($action) |
||
| 78 | { |
||
| 79 | case 'remove': |
||
| 80 | if (confirm_box(true)) |
||
| 81 | { |
||
| 82 | $user_id = $request->variable('user_id', array(0)); |
||
| 83 | $redirect_url = $request->variable('redirect_url', ''); |
||
| 84 | if ($friends_controller->remove_friend($user_id)) |
||
| 85 | { |
||
| 86 | redirect($redirect_url); |
||
| 87 | } |
||
| 88 | } else |
||
| 89 | { |
||
| 90 | $user_id = $request->variable('user_id', array(0)); |
||
| 91 | $redirect_url = $request->server('HTTP_REFERER'); |
||
| 92 | confirm_box(false, $user->lang('CONFIRM_REMOVE_FRIEND'), build_hidden_fields(array( |
||
| 93 | 'user_id' => $user_id, |
||
| 94 | 'redirect_url' => $redirect_url, |
||
| 95 | ))); |
||
| 96 | } |
||
| 97 | break; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | $friends_controller->friends_list(); |
||
| 101 | $this->tpl_name = 'friends'; |
||
| 102 | break; |
||
| 103 | } |
||
| 104 | break; |
||
| 105 | |||
| 106 | case 'requests': |
||
| 107 | |||
| 108 | if ($request->is_set_post('action')) |
||
| 109 | { |
||
| 110 | $action = $request->variable('action', ''); |
||
| 111 | |||
| 112 | switch ($action) |
||
| 113 | { |
||
| 114 | case 'delete': |
||
| 115 | |||
| 116 | if (confirm_box(true)) |
||
| 117 | { |
||
| 118 | $requests_id = $request->variable('requests_id', array(0)); |
||
| 119 | $friends_controller->delete_request($requests_id); |
||
| 120 | } else |
||
| 121 | { |
||
| 122 | $requests_id = $request->variable('requests_id', array(0)); |
||
| 123 | confirm_box(false, $user->lang('CONFIRM_REMOVE_REQUESTS'), build_hidden_fields(array( |
||
| 124 | 'requests_id' => $requests_id, |
||
| 125 | 'action' => $action, |
||
| 126 | 'mode' => $mode |
||
| 127 | ))); |
||
| 128 | } |
||
| 129 | |||
| 130 | break; |
||
| 131 | case 'approve': |
||
| 132 | $requests_id = $request->variable('requests_id', array(0)); |
||
| 133 | $friends_controller->approve_request($requests_id); |
||
| 134 | break; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $action = $request->variable('action', ''); |
||
| 139 | switch ($action) |
||
| 140 | { |
||
| 141 | case 'cancel_request': |
||
| 142 | if (confirm_box(true)) |
||
| 143 | { |
||
| 144 | $request_id = $request->variable('request_id', 0); |
||
| 145 | $redirect_url = $request->variable('redirect_url', ''); |
||
| 146 | if ($friends_controller->delete_request($request_id)) |
||
| 147 | { |
||
| 148 | redirect($redirect_url); |
||
| 149 | } |
||
| 150 | } else |
||
| 151 | { |
||
| 152 | $request_id = $request->variable('request_id', 0); |
||
| 153 | $redirect_url = $request->server('HTTP_REFERER'); |
||
| 154 | confirm_box(false, $user->lang('CONFIRM_REMOVE_REQUESTS'), build_hidden_fields(array( |
||
| 155 | 'request_id' => $request_id, |
||
| 156 | 'action' => $action, |
||
| 157 | 'mode' => $mode, |
||
| 158 | 'redirect_url' => $redirect_url, |
||
| 159 | ))); |
||
| 160 | } |
||
| 161 | break; |
||
| 162 | } |
||
| 163 | |||
| 164 | $friends_controller->requests(); |
||
| 165 | $this->tpl_name = 'ucp_friends_requests'; |
||
| 166 | break; |
||
| 167 | |||
| 168 | } |
||
| 169 | |||
| 170 | } |
||
| 171 | |||
| 173 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.