Conditions | 13 |
Paths | 144 |
Total Lines | 65 |
Code Lines | 40 |
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 |
||
87 | function list_groups($checked, $disallowed = '', $inherited = false, $permission = null, $board_id = null) |
||
88 | { |
||
89 | global $context, $modSettings, $smcFunc, $sourcedir, $txt; |
||
90 | |||
91 | // We'll need this for loading up the names of each group. |
||
92 | if (!loadLanguage('ManageBoards')) |
||
93 | loadLanguage('ManageBoards'); |
||
94 | |||
95 | $checked = explode(',', $checked); |
||
96 | $disallowed = explode(',', $disallowed); |
||
97 | |||
98 | // Are we also looking up permissions? |
||
99 | if ($permission !== null) |
||
100 | { |
||
101 | require_once($sourcedir . '/Subs-Members.php'); |
||
102 | $member_groups = groupsAllowedTo($permission, $board_id); |
||
103 | $disallowed = array_diff(array_keys(list_groups(-3)), $member_groups['allowed']); |
||
104 | } |
||
105 | |||
106 | $groups = array(); |
||
107 | |||
108 | if (!in_array(-1, $disallowed)) |
||
109 | // Guests |
||
110 | $groups[-1] = array( |
||
111 | 'id' => -1, |
||
112 | 'name' => $txt['parent_guests_only'], |
||
113 | 'checked' => in_array(-1, $checked) || in_array(-3, $checked), |
||
114 | 'is_post_group' => false, |
||
115 | ); |
||
116 | |||
117 | if (!in_array(0, $disallowed)) |
||
118 | // Regular Members |
||
119 | $groups[0] = array( |
||
120 | 'id' => 0, |
||
121 | 'name' => $txt['parent_members_only'], |
||
122 | 'checked' => in_array(0, $checked) || in_array(-3, $checked), |
||
123 | 'is_post_group' => false, |
||
124 | ); |
||
125 | |||
126 | // Load membergroups. |
||
127 | $request = $smcFunc['db_query']('', ' |
||
128 | SELECT group_name, id_group, min_posts |
||
129 | FROM {db_prefix}membergroups |
||
130 | WHERE id_group > {int:is_zero}' . (!$inherited ? ' |
||
131 | AND id_parent = {int:not_inherited}' : '') . (!$inherited && empty($modSettings['permission_enable_postgroups']) ? ' |
||
132 | AND min_posts = {int:min_posts}' : ''), |
||
133 | array( |
||
134 | 'is_zero' => 0, |
||
135 | 'not_inherited' => -2, |
||
136 | 'min_posts' => -1, |
||
137 | ) |
||
138 | ); |
||
139 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
140 | if (!in_array($row['id_group'], $disallowed)) |
||
141 | $groups[(int) $row['id_group']] = array( |
||
142 | 'id' => $row['id_group'], |
||
143 | 'name' => trim($row['group_name']), |
||
144 | 'checked' => in_array($row['id_group'], $checked) || in_array(-3, $checked), |
||
145 | 'is_post_group' => $row['min_posts'] != -1, |
||
146 | ); |
||
147 | $smcFunc['db_free_result']($request); |
||
148 | |||
149 | asort($groups); |
||
150 | |||
151 | return $groups; |
||
152 | } |
||
205 |