| Conditions | 13 |
| Paths | 822 |
| Total Lines | 107 |
| Code Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 declare(strict_types=1); |
||
| 170 | public function reset(): void |
||
| 171 | { |
||
| 172 | $this->db->queryF('TRUNCATE TABLE ' . $this->table); |
||
| 173 | $now = \time(); |
||
| 174 | $time_start = [ |
||
| 175 | 'day' => '%Y%j', |
||
| 176 | 'week' => '%Y%u', |
||
| 177 | 'month' => '%Y%m', |
||
| 178 | ]; |
||
| 179 | $counts = []; |
||
| 180 | |||
| 181 | $sql = ' SELECT forum_id' . ' FROM ' . $this->db->prefix('newbb_forums'); |
||
| 182 | $ret = $this->db->query($sql); |
||
| 183 | if (!$this->db->isResultSet($ret)) { |
||
| 184 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 185 | } |
||
| 186 | while ([$forum_id] = $this->db->fetchRow($ret)) { |
||
| 187 | $sql = ' SELECT COUNT(*), SUM(topic_views)' . ' FROM ' . $this->db->prefix('newbb_topics') . " WHERE approved=1 AND forum_id = {$forum_id}"; |
||
| 188 | $result = $this->db->query($sql); |
||
| 189 | if (!$this->db->isResultSet($result)) { |
||
| 190 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 191 | } |
||
| 192 | [$topics, $views] = $this->db->fetchRow($result); |
||
| 193 | $this->update($forum_id, 'topic', (int)$topics); |
||
| 194 | $this->update($forum_id, 'view', (int)$views); |
||
| 195 | |||
| 196 | $sql = ' SELECT COUNT(*)' . ' FROM ' . $this->db->prefix('newbb_topics') . " WHERE approved=1 AND topic_digest >0 AND forum_id = {$forum_id}"; |
||
| 197 | $result = $this->db->query($sql); |
||
| 198 | if (!$this->db->isResultSet($result)) { |
||
| 199 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 200 | } |
||
| 201 | [$digests] = $this->db->fetchRow($result); |
||
| 202 | $this->update($forum_id, 'digest', (int)$digests); |
||
| 203 | |||
| 204 | $sql = ' SELECT COUNT(*)' . ' FROM ' . $this->db->prefix('newbb_posts') . " WHERE approved=1 AND forum_id = {$forum_id}"; |
||
| 205 | $result = $this->db->query($sql); |
||
| 206 | if (!$this->db->isResultSet($result)) { |
||
| 207 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 208 | } |
||
| 209 | [$posts] = $this->db->fetchRow($result); |
||
| 210 | $this->update($forum_id, 'post', (int)$posts); |
||
| 211 | |||
| 212 | foreach ($time_start as $period => $format) { |
||
| 213 | $sql = ' SELECT COUNT(*), SUM(topic_views)' . ' FROM ' . $this->db->prefix('newbb_topics') . " WHERE approved=1 AND forum_id = {$forum_id}" . " AND FROM_UNIXTIME(topic_time, '{$format}') >= FROM_UNIXTIME({$now}, '{$format}')"; |
||
| 214 | $result = $this->db->query($sql); |
||
| 215 | if (!$this->db->isResultSet($result)) { |
||
| 216 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 217 | } |
||
| 218 | [$topics, $views] = $this->db->fetchRow($result); |
||
| 219 | $views = empty($views) ? 0 : $views; // null check |
||
| 220 | |||
| 221 | $sql = " INSERT INTO {$this->table}" . ' (`stats_id`, `stats_value`, `stats_type`, `stats_period`, `time_update`, `time_format`) ' . ' VALUES ' . " ('{$forum_id}', '{$topics}', '" . \array_search('topic', $this->param['type'], true) . "', '" . \array_search( |
||
| 222 | $period, |
||
| 223 | $this->param['period'], |
||
| 224 | true |
||
| 225 | ) . "', NOW(), '{$format}')"; |
||
| 226 | $result = $this->db->queryF($sql); |
||
| 227 | |||
| 228 | $sql = " INSERT INTO {$this->table}" . ' (`stats_id`, `stats_value`, `stats_type`, `stats_period`, `time_update`, `time_format`) ' . ' VALUES ' . " ('{$forum_id}', '{$views}', '" . \array_search('view', $this->param['type'], true) . "', '" . \array_search( |
||
| 229 | $period, |
||
| 230 | $this->param['period'], |
||
| 231 | true |
||
| 232 | ) . "', NOW(), '{$format}')"; |
||
| 233 | $result = $this->db->queryF($sql); |
||
| 234 | @$counts['topic'][$period] += $topics; |
||
| 235 | @$counts['view'][$period] += $views; |
||
| 236 | |||
| 237 | $sql = ' SELECT COUNT(*)' . ' FROM ' . $this->db->prefix('newbb_topics') . " WHERE approved=1 AND topic_digest >0 AND forum_id = {$forum_id}" . " AND FROM_UNIXTIME(digest_time, '{$format}') >= FROM_UNIXTIME({$now}, '{$format}')"; |
||
| 238 | $result = $this->db->query($sql); |
||
| 239 | if (!$this->db->isResultSet($result)) { |
||
| 240 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 241 | } |
||
| 242 | [$digests] = $this->db->fetchRow($result); |
||
| 243 | $sql = " INSERT INTO {$this->table}" . ' (`stats_id`, `stats_value`, `stats_type`, `stats_period`, `time_update`, `time_format`) ' . ' VALUES ' . " ('{$forum_id}', '{$digests}', '" . \array_search('digest', $this->param['type'], true) . "', '" . \array_search( |
||
| 244 | $period, |
||
| 245 | $this->param['period'], |
||
| 246 | true |
||
| 247 | ) . "', NOW(), '{$format}')"; |
||
| 248 | $result = $this->db->queryF($sql); |
||
| 249 | @$counts['digest'][$period] += $digests; |
||
| 250 | |||
| 251 | $sql = ' SELECT COUNT(*)' . ' FROM ' . $this->db->prefix('newbb_posts') . " WHERE approved=1 AND forum_id = {$forum_id}" . " AND FROM_UNIXTIME(post_time, '{$format}') >= FROM_UNIXTIME({$now}, '{$format}')"; |
||
| 252 | $result = $this->db->query($sql); |
||
| 253 | if (!$this->db->isResultSet($result)) { |
||
| 254 | \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
||
| 255 | } |
||
| 256 | [$posts] = $this->db->fetchRow($result); |
||
| 257 | $sql = " INSERT INTO {$this->table}" . ' (`stats_id`, `stats_value`, `stats_type`, `stats_period`, `time_update`, `time_format`) ' . ' VALUES ' . " ('{$forum_id}', '{$posts}', '" . \array_search('post', $this->param['type'], true) . "', '" . \array_search( |
||
| 258 | $period, |
||
| 259 | $this->param['period'], |
||
| 260 | true |
||
| 261 | ) . "', NOW(), '{$format}')"; |
||
| 262 | $result = $this->db->queryF($sql); |
||
| 263 | @$counts['post'][$period] += $posts; |
||
| 264 | } |
||
| 265 | } |
||
| 266 | |||
| 267 | $sql = " DELETE FROM {$this->table}" . " WHERE stats_id = '0' AND stats_period <> " . \array_search('total', $this->param['period'], true); |
||
| 268 | $result = $this->db->queryF($sql); |
||
| 269 | foreach ($time_start as $period => $format) { |
||
| 270 | foreach (\array_keys($counts) as $type) { |
||
| 271 | $sql = " INSERT INTO {$this->table}" . ' (`stats_id`, `stats_value`, `stats_type`, `stats_period`, `time_update`, `time_format`) ' . ' VALUES ' . " ('0', '{$counts[$type][$period]}', '" . \array_search($type, $this->param['type'], true) . "', '" . \array_search( |
||
| 272 | $period, |
||
| 273 | $this->param['period'], |
||
| 274 | true |
||
| 275 | ) . "', NOW(), '{$format}')"; |
||
| 276 | $result = $this->db->queryF($sql); |
||
| 277 | } |
||
| 281 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.