| Conditions | 14 |
| Paths | 7 |
| Total Lines | 94 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 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 |
||
| 192 | static function users_users () { |
||
| 193 | $L = Language::instance(); |
||
| 194 | $Page = Page::instance(); |
||
| 195 | $User = User::instance(); |
||
| 196 | $a = Index::instance(); |
||
| 197 | $rc = Route::instance()->route; |
||
| 198 | if (isset($rc[2], $rc[3])) { |
||
| 199 | $is_bot = in_array(3, (array)$User->get_groups($rc[3])); |
||
| 200 | switch ($rc[2]) { |
||
| 201 | case 'groups': |
||
| 202 | if ($is_bot || !isset($rc[3]) || $rc[3] == User::ROOT_ID) { |
||
| 203 | break; |
||
| 204 | } |
||
| 205 | $a->cancel_button_back = true; |
||
| 206 | $Group = Group::instance(); |
||
| 207 | $user_groups = array_reverse($User->get_groups($rc[3])); |
||
| 208 | $all_groups = $Group->get_all(); |
||
| 209 | $groups_selected = h::{'li.cs-block-primary.cs-text.primary'}( |
||
| 210 | $L->selected_groups |
||
| 211 | ); |
||
| 212 | $groups_list = h::{'li.cs-block-primary.cs-text.primary'}( |
||
| 213 | $L->other_groups |
||
| 214 | ); |
||
| 215 | if (is_array($user_groups) && !empty($user_groups)) { |
||
| 216 | foreach ($user_groups as $group) { |
||
| 217 | $group = $Group->get($group); |
||
| 218 | $groups_selected .= h::{'li.cs-block-success.cs-text-success'}( |
||
| 219 | $group['title'], |
||
| 220 | [ |
||
| 221 | 'data-id' => $group['id'], |
||
| 222 | 'tooltip' => $group['description'] |
||
| 223 | ] |
||
| 224 | ); |
||
| 225 | } |
||
| 226 | } |
||
| 227 | if (is_array($all_groups) && !empty($all_groups)) { |
||
| 228 | foreach ($all_groups as $group) { |
||
| 229 | if ($group['id'] == User::BOT_GROUP_ID || in_array($group['id'], $user_groups)) { |
||
| 230 | continue; |
||
| 231 | } |
||
| 232 | $groups_list .= h::{'li.cs-block-warning.cs-text-warning'}( |
||
| 233 | $group['title'], |
||
| 234 | [ |
||
| 235 | 'data-id' => $group['id'], |
||
| 236 | 'tooltip' => $group['description'] |
||
| 237 | ] |
||
| 238 | ); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | $Page->title( |
||
| 242 | $L->user_groups($User->username($rc[3])) |
||
|
|
|||
| 243 | ); |
||
| 244 | $a->content( |
||
| 245 | h::{'h2.cs-text-center'}( |
||
| 246 | $L->user_groups( |
||
| 247 | $User->username($rc[3]) |
||
| 248 | ), |
||
| 249 | [ |
||
| 250 | 'tooltip' => $L->user_groups_info |
||
| 251 | ] |
||
| 252 | ). |
||
| 253 | h::{'div'}( |
||
| 254 | h::{'ul#cs-users-groups-list-selected'}($groups_selected). |
||
| 255 | h::{'ul#cs-users-groups-list'}($groups_list) |
||
| 256 | ). |
||
| 257 | h::{'input[type=hidden]'}( |
||
| 258 | [ |
||
| 259 | 'name' => 'user[id]', |
||
| 260 | 'value' => $rc[3] |
||
| 261 | ] |
||
| 262 | ). |
||
| 263 | h::{'input#cs-user-groups[type=hidden]'}( |
||
| 264 | [ |
||
| 265 | 'name' => 'user[groups]' |
||
| 266 | ] |
||
| 267 | ) |
||
| 268 | ); |
||
| 269 | break; |
||
| 270 | } |
||
| 271 | $a->content( |
||
| 272 | h::{'input[type=hidden]'}( |
||
| 273 | [ |
||
| 274 | 'name' => 'mode', |
||
| 275 | 'value' => $rc[2] |
||
| 276 | ] |
||
| 277 | ) |
||
| 278 | ); |
||
| 279 | } else { |
||
| 280 | $a->form = false; |
||
| 281 | $a->content( |
||
| 282 | h::{'cs-system-admin-users-list'}() |
||
| 283 | ); |
||
| 284 | } |
||
| 285 | } |
||
| 286 | } |
||
| 287 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: