| Conditions | 14 |
| Paths | 7 |
| Total Lines | 94 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 107 | static function users_users () { |
||
| 108 | $L = Language::instance(); |
||
| 109 | $Page = Page::instance(); |
||
| 110 | $User = User::instance(); |
||
| 111 | $a = Index::instance(); |
||
| 112 | $rc = Route::instance()->route; |
||
| 113 | if (isset($rc[2], $rc[3])) { |
||
| 114 | $is_bot = in_array(3, (array)$User->get_groups($rc[3])); |
||
| 115 | switch ($rc[2]) { |
||
| 116 | case 'groups': |
||
| 117 | if ($is_bot || !isset($rc[3]) || $rc[3] == User::ROOT_ID) { |
||
| 118 | break; |
||
| 119 | } |
||
| 120 | $a->cancel_button_back = true; |
||
| 121 | $Group = Group::instance(); |
||
| 122 | $user_groups = array_reverse($User->get_groups($rc[3])); |
||
| 123 | $all_groups = $Group->get_all(); |
||
| 124 | $groups_selected = h::{'li.cs-block-primary.cs-text.primary'}( |
||
| 125 | $L->selected_groups |
||
| 126 | ); |
||
| 127 | $groups_list = h::{'li.cs-block-primary.cs-text.primary'}( |
||
| 128 | $L->other_groups |
||
| 129 | ); |
||
| 130 | if (is_array($user_groups) && !empty($user_groups)) { |
||
| 131 | foreach ($user_groups as $group) { |
||
| 132 | $group = $Group->get($group); |
||
| 133 | $groups_selected .= h::{'li.cs-block-success.cs-text-success'}( |
||
| 134 | $group['title'], |
||
| 135 | [ |
||
| 136 | 'data-id' => $group['id'], |
||
| 137 | 'tooltip' => $group['description'] |
||
| 138 | ] |
||
| 139 | ); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | if (is_array($all_groups) && !empty($all_groups)) { |
||
| 143 | foreach ($all_groups as $group) { |
||
| 144 | if ($group['id'] == User::BOT_GROUP_ID || in_array($group['id'], $user_groups)) { |
||
| 145 | continue; |
||
| 146 | } |
||
| 147 | $groups_list .= h::{'li.cs-block-warning.cs-text-warning'}( |
||
| 148 | $group['title'], |
||
| 149 | [ |
||
| 150 | 'data-id' => $group['id'], |
||
| 151 | 'tooltip' => $group['description'] |
||
| 152 | ] |
||
| 153 | ); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | $Page->title( |
||
| 157 | $L->user_groups($User->username($rc[3])) |
||
|
|
|||
| 158 | ); |
||
| 159 | $a->content( |
||
| 160 | h::{'h2.cs-text-center'}( |
||
| 161 | $L->user_groups( |
||
| 162 | $User->username($rc[3]) |
||
| 163 | ), |
||
| 164 | [ |
||
| 165 | 'tooltip' => $L->user_groups_info |
||
| 166 | ] |
||
| 167 | ). |
||
| 168 | h::{'div'}( |
||
| 169 | h::{'ul#cs-users-groups-list-selected'}($groups_selected). |
||
| 170 | h::{'ul#cs-users-groups-list'}($groups_list) |
||
| 171 | ). |
||
| 172 | h::{'input[type=hidden]'}( |
||
| 173 | [ |
||
| 174 | 'name' => 'user[id]', |
||
| 175 | 'value' => $rc[3] |
||
| 176 | ] |
||
| 177 | ). |
||
| 178 | h::{'input#cs-user-groups[type=hidden]'}( |
||
| 179 | [ |
||
| 180 | 'name' => 'user[groups]' |
||
| 181 | ] |
||
| 182 | ) |
||
| 183 | ); |
||
| 184 | break; |
||
| 185 | } |
||
| 186 | $a->content( |
||
| 187 | h::{'input[type=hidden]'}( |
||
| 188 | [ |
||
| 189 | 'name' => 'mode', |
||
| 190 | 'value' => $rc[2] |
||
| 191 | ] |
||
| 192 | ) |
||
| 193 | ); |
||
| 194 | } else { |
||
| 195 | $a->form = false; |
||
| 196 | $a->content( |
||
| 197 | h::{'cs-system-admin-users-list'}() |
||
| 198 | ); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 |
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: