Conditions | 18 |
Paths | 224 |
Total Lines | 57 |
Code Lines | 32 |
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 |
||
14 | function um_load_menu(&$menu_buttons) |
||
15 | { |
||
16 | global $smcFunc, $user_info, $scripturl, $context, $modSettings; |
||
17 | |||
18 | // Make damn sure we ALWAYS load last. Priority: 100! |
||
19 | if (substr($modSettings['integrate_menu_buttons'], -12) === 'um_load_menu') |
||
20 | { |
||
21 | remove_integration_function('integrate_menu_buttons', 'um_load_menu'); |
||
|
|||
22 | add_integration_function('integrate_menu_buttons', 'um_load_menu'); |
||
23 | } |
||
24 | |||
25 | $num_buttons = isset($modSettings['um_count']) |
||
26 | ? $modSettings['um_count'] |
||
27 | : 0; |
||
28 | |||
29 | for ($i = 1; $i <= $num_buttons; $i++) |
||
30 | { |
||
31 | $key = 'um_button_' . $i; |
||
32 | if (!isset($modSettings[$key])) |
||
33 | break; |
||
34 | $row = json_decode($modSettings[$key], true); |
||
35 | $temp_menu = array( |
||
36 | 'title' => $row['name'], |
||
37 | 'href' => ($row['type'] == 'forum' ? $scripturl . '?' : '') . $row['link'], |
||
38 | 'target' => $row['target'], |
||
39 | 'show' => (allowedTo('admin_forum') || count(array_intersect($user_info['groups'], explode(',', $row['permissions']))) >= 1) && $row['status'] == 'active', |
||
40 | ); |
||
41 | |||
42 | foreach ($menu_buttons as $area => &$info) |
||
43 | { |
||
44 | if ($area == $row['parent']) |
||
45 | { |
||
46 | if ($row['position'] == 'before' || $row['position'] == 'after') |
||
47 | { |
||
48 | if (array_key_exists($row['parent'], $menu_buttons)) |
||
49 | { |
||
50 | insert_button(array($key => $temp_menu), $menu_buttons, $row['parent'], $row['position']); |
||
51 | break; |
||
52 | } |
||
53 | } |
||
54 | elseif ($row['position'] == 'child_of') |
||
55 | { |
||
56 | $info['sub_buttons'][$key] = $temp_menu; |
||
57 | break; |
||
58 | } |
||
59 | } |
||
60 | elseif (isset($info['sub_buttons'][$row['parent']])) |
||
61 | { |
||
62 | if ($row['position'] == 'before' || $row['position'] == 'after') |
||
63 | { |
||
64 | insert_button(array($key => $temp_menu), $info['sub_buttons'], $row['parent'], $row['position']); |
||
65 | break; |
||
66 | } |
||
67 | elseif ($row['position'] == 'child_of') |
||
68 | { |
||
69 | $info['sub_buttons'][$row['parent']]['sub_buttons'][$key] = $temp_menu; |
||
70 | break; |
||
71 | } |
||
206 |