| Conditions | 6 |
| Paths | 12 |
| Total Lines | 87 |
| Code Lines | 71 |
| 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 |
||
| 167 | public function reset() |
||
| 168 | { |
||
| 169 | $this->db->queryF('TRUNCATE TABLE ' . $this->table); |
||
| 170 | $now = \time(); |
||
| 171 | $time_start = [ |
||
| 172 | 'day' => '%Y%j', |
||
| 173 | 'week' => '%Y%u', |
||
| 174 | 'month' => '%Y%m', |
||
| 175 | ]; |
||
| 176 | $counts = []; |
||
| 177 | |||
| 178 | $sql = ' SELECT forum_id' . ' FROM ' . $this->db->prefix('newbb_forums'); |
||
| 179 | $ret = $this->db->query($sql); |
||
| 180 | while (list($forum_id) = $this->db->fetchRow($ret)) { |
||
| 181 | $sql = ' SELECT COUNT(*), SUM(topic_views)' . ' FROM ' . $this->db->prefix('newbb_topics') . " WHERE approved=1 AND forum_id = {$forum_id}"; |
||
| 182 | $result = $this->db->query($sql); |
||
| 183 | [$topics, $views] = $this->db->fetchRow($result); |
||
| 184 | $this->update($forum_id, 'topic', $topics); |
||
| 185 | $this->update($forum_id, 'view', $views); |
||
| 186 | |||
| 187 | $sql = ' SELECT COUNT(*)' . ' FROM ' . $this->db->prefix('newbb_topics') . " WHERE approved=1 AND topic_digest >0 AND forum_id = {$forum_id}"; |
||
| 188 | $result = $this->db->query($sql); |
||
| 189 | [$digests] = $this->db->fetchRow($result); |
||
| 190 | $this->update($forum_id, 'digest', $digests); |
||
| 191 | |||
| 192 | $sql = ' SELECT COUNT(*)' . ' FROM ' . $this->db->prefix('newbb_posts') . " WHERE approved=1 AND forum_id = {$forum_id}"; |
||
| 193 | $result = $this->db->query($sql); |
||
| 194 | [$posts] = $this->db->fetchRow($result); |
||
| 195 | $this->update($forum_id, 'post', $posts); |
||
| 196 | |||
| 197 | foreach ($time_start as $period => $format) { |
||
| 198 | $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}')"; |
||
| 199 | $result = $this->db->query($sql); |
||
| 200 | [$topics, $views] = $this->db->fetchRow($result); |
||
| 201 | $views = empty($views) ? 0 : $views; // null check |
||
| 202 | $this->db->queryF( |
||
| 203 | " 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( |
||
| 204 | $period, |
||
| 205 | $this->param['period'], |
||
| 206 | true |
||
| 207 | ) . "', NOW(), '{$format}')" |
||
| 208 | ); |
||
| 209 | $this->db->queryF( |
||
| 210 | " 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( |
||
| 211 | $period, |
||
| 212 | $this->param['period'], |
||
| 213 | true |
||
| 214 | ) . "', NOW(), '{$format}')" |
||
| 215 | ); |
||
| 216 | @$counts['topic'][$period] += $topics; |
||
| 217 | @$counts['view'][$period] += $views; |
||
| 218 | |||
| 219 | $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}')"; |
||
| 220 | $result = $this->db->query($sql); |
||
| 221 | [$digests] = $this->db->fetchRow($result); |
||
| 222 | $this->db->queryF( |
||
| 223 | " 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( |
||
| 224 | $period, |
||
| 225 | $this->param['period'], |
||
| 226 | true |
||
| 227 | ) . "', NOW(), '{$format}')" |
||
| 228 | ); |
||
| 229 | @$counts['digest'][$period] += $digests; |
||
| 230 | |||
| 231 | $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}')"; |
||
| 232 | $result = $this->db->query($sql); |
||
| 233 | [$posts] = $this->db->fetchRow($result); |
||
| 234 | $this->db->queryF( |
||
| 235 | " 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( |
||
| 236 | $period, |
||
| 237 | $this->param['period'], |
||
| 238 | true |
||
| 239 | ) . "', NOW(), '{$format}')" |
||
| 240 | ); |
||
| 241 | @$counts['post'][$period] += $posts; |
||
| 242 | } |
||
| 243 | } |
||
| 244 | |||
| 245 | $this->db->queryF(" DELETE FROM {$this->table}" . " WHERE stats_id = '0' AND stats_period <> " . \array_search('total', $this->param['period'], true)); |
||
| 246 | foreach ($time_start as $period => $format) { |
||
| 247 | foreach (\array_keys($counts) as $type) { |
||
| 248 | $this->db->queryF( |
||
| 249 | " 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( |
||
| 250 | $period, |
||
| 251 | $this->param['period'], |
||
| 252 | true |
||
| 253 | ) . "', NOW(), '{$format}')" |
||
| 254 | ); |
||
| 259 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.