| Conditions | 26 |
| Paths | 2880 |
| Total Lines | 116 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 95 | function sportal_get_shouts($shoutbox, $parameters) |
||
| 96 | { |
||
| 97 | global $scripturl, $context, $user_info, $modSettings, $txt; |
||
| 98 | |||
| 99 | $db = database(); |
||
| 100 | |||
| 101 | // Set defaults or used what was passed |
||
| 102 | $shoutbox = !empty($shoutbox) ? (int) $shoutbox : 0; |
||
| 103 | $start = !empty($parameters['start']) ? (int) $parameters['start'] : 0; |
||
| 104 | $limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 20; |
||
| 105 | $bbc = !empty($parameters['bbc']) ? $parameters['bbc'] : array(); |
||
| 106 | $reverse = !empty($parameters['reverse']); |
||
| 107 | $cache = !empty($parameters['cache']); |
||
| 108 | $can_delete = !empty($parameters['can_moderate']); |
||
| 109 | |||
| 110 | // BBC Parser just for the shoutbox |
||
| 111 | $parser = new BBCParser($codes = new Codes()); |
||
| 112 | |||
| 113 | // We only allow a few codes in the shoutbox, so turn off others |
||
| 114 | foreach ($codes->getTags() as $key => $code) |
||
| 115 | { |
||
| 116 | if (!in_array($key, $bbc)) |
||
| 117 | { |
||
| 118 | $codes->disable($key); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | // Cached, use it first |
||
| 123 | if (!empty($start) || !$cache || ($shouts = cache_get_data('shoutbox_shouts-' . $shoutbox, 240)) === null) |
||
| 124 | { |
||
| 125 | $request = $db->query('', ' |
||
| 126 | SELECT |
||
| 127 | sh.id_shout, sh.body, sh.log_time, |
||
| 128 | IFNULL(mem.id_member, 0) AS id_member, |
||
| 129 | IFNULL(mem.real_name, sh.member_name) AS member_name, |
||
| 130 | mg.online_color AS member_group_color, |
||
| 131 | pg.online_color AS post_group_color |
||
| 132 | FROM {db_prefix}sp_shouts AS sh |
||
| 133 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = sh.id_member) |
||
| 134 | LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group) |
||
| 135 | LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group) |
||
| 136 | WHERE sh.id_shoutbox = {int:id_shoutbox} |
||
| 137 | ORDER BY sh.id_shout DESC |
||
| 138 | LIMIT {int:start}, {int:limit}', |
||
| 139 | array( |
||
| 140 | 'id_shoutbox' => $shoutbox, |
||
| 141 | 'start' => $start, |
||
| 142 | 'limit' => $limit, |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | $shouts = array(); |
||
| 146 | while ($row = $db->fetch_assoc($request)) |
||
| 147 | { |
||
| 148 | $online_color = !empty($row['member_group_color']) ? $row['member_group_color'] : $row['post_group_color']; |
||
| 149 | $shouts[$row['id_shout']] = array( |
||
| 150 | 'id' => $row['id_shout'], |
||
| 151 | 'author' => array( |
||
| 152 | 'id' => $row['id_member'], |
||
| 153 | 'name' => $row['member_name'], |
||
| 154 | 'link' => $row['id_member'] |
||
| 155 | ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(standardTime($row['log_time'])) . '"' . (!empty($online_color) |
||
| 156 | ? ' style="color: ' . $online_color . ';"' : '') . '>' . $row['member_name'] . '</a>') |
||
| 157 | : $row['member_name'], |
||
| 158 | 'color' => $online_color, |
||
| 159 | ), |
||
| 160 | 'time' => $row['log_time'], |
||
| 161 | 'text' => $parser->enableSmileys(true)->parse($row['body']) |
||
| 162 | ); |
||
| 163 | } |
||
| 164 | $db->free_result($request); |
||
| 165 | |||
| 166 | if (empty($start) && $cache) |
||
| 167 | { |
||
| 168 | cache_put_data('shoutbox_shouts-' . $shoutbox, $shouts, 240); |
||
|
|
|||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | // Restore BBC codes |
||
| 173 | unset($parser); |
||
| 174 | |||
| 175 | foreach ($shouts as $shout) |
||
| 176 | { |
||
| 177 | // Private shouts @username: only get shown to the shouter and shoutee, and the admin ;) |
||
| 178 | if (preg_match('~^@(.+?): ~u', $shout['text'], $target) && Util::strtolower($target[1]) !== Util::strtolower($user_info['name']) && $shout['author']['id'] != $user_info['id'] && !$user_info['is_admin']) |
||
| 179 | { |
||
| 180 | unset($shouts[$shout['id']]); |
||
| 181 | continue; |
||
| 182 | } |
||
| 183 | |||
| 184 | $shouts[$shout['id']] += array( |
||
| 185 | 'is_me' => preg_match('~^<div\sclass="meaction">\* ' . preg_quote($shout['author']['name'], '~') . '.+</div>$~', $shout['text']) != 0, |
||
| 186 | 'delete_link' => $can_delete |
||
| 187 | ? '<a class="dot dotdelete" href="' . $scripturl . '?action=shoutbox;shoutbox_id=' . $shoutbox . ';delete=' . $shout['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '"></a> ' : '', |
||
| 188 | 'delete_link_js' => $can_delete |
||
| 189 | ? '<a class="dot dotdelete" href="' . $scripturl . '?action=shoutbox;shoutbox_id=' . $shoutbox . ';delete=' . $shout['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="sp_delete_shout(' . $shoutbox . ', ' . $shout['id'] . ', \'' . $context['session_var'] . '\', \'' . $context['session_id'] . '\'); return false;"></a> ' : '', |
||
| 190 | ); |
||
| 191 | |||
| 192 | // Prepare for display in the box |
||
| 193 | $shouts[$shout['id']]['time'] = standardTime($shouts[$shout['id']]['time']); |
||
| 194 | $shouts[$shout['id']]['text'] = preg_replace('~(</?)div([^<]*>)~', '$1span$2', $shouts[$shout['id']]['text']); |
||
| 195 | $shouts[$shout['id']]['text'] = preg_replace('~<a([^>]+>)([^<]+)</a>~', '<a$1' . $txt['sp_link'] . '</a>', $shouts[$shout['id']]['text']); |
||
| 196 | $shouts[$shout['id']]['text'] = censor($shouts[$shout['id']]['text']); |
||
| 197 | |||
| 198 | // Ignored user, hide the shout with option to show it |
||
| 199 | if (!empty($modSettings['enable_buddylist']) && in_array($shout['author']['id'], $context['user']['ignoreusers'])) |
||
| 200 | { |
||
| 201 | $shouts[$shout['id']]['text'] = '<a href="#toggle" id="ignored_shout_link_' . $shout['id'] . '" onclick="sp_show_ignored_shout(' . $shout['id'] . '); return false;">[' . $txt['sp_shoutbox_show_ignored'] . ']</a><span id="ignored_shout_' . $shout['id'] . '" style="display: none;">' . $shouts[$shout['id']]['text'] . '</span>'; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | if ($reverse) |
||
| 206 | { |
||
| 207 | $shouts = array_reverse($shouts); |
||
| 208 | } |
||
| 209 | |||
| 210 | return $shouts; |
||
| 211 | } |
||
| 372 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.