| Conditions | 40 |
| Paths | > 20000 |
| Total Lines | 196 |
| Code Lines | 94 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 168 | public function display_similar_topics($topic_data) |
||
| 169 | { |
||
| 170 | // If the forum should not display similar topics, no need to continue |
||
| 171 | if ($topic_data['similar_topics_hide']) |
||
| 172 | { |
||
| 173 | return; |
||
| 174 | } |
||
| 175 | |||
| 176 | $topic_title = $this->clean_topic_title($topic_data['topic_title']); |
||
| 177 | |||
| 178 | // If the cleaned up topic_title is empty, no need to continue |
||
| 179 | if (empty($topic_title)) |
||
| 180 | { |
||
| 181 | return; |
||
| 182 | } |
||
| 183 | |||
| 184 | // Get stored sensitivity value and divide by 10. In query, it should be a number between 0.0 to 1.0. |
||
| 185 | $sensitivity = $this->config->offsetExists('similar_topics_sense') ? number_format($this->config['similar_topics_sense'] / 10, 1, '.', '') : '0.5'; |
||
| 186 | |||
| 187 | // Similar Topics SQL query is generated in similar topics driver |
||
| 188 | $sql_array = $this->similartopics->get_query($topic_data['topic_id'], $topic_title, $this->config['similar_topics_time'], $sensitivity); |
||
| 189 | |||
| 190 | // Add topic tracking data to the query (only if query caching is off) |
||
| 191 | if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) |
||
| 192 | { |
||
| 193 | $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']); |
||
| 194 | $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = f.forum_id AND ft.user_id = ' . $this->user->data['user_id']); |
||
| 195 | $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as f_mark_time'; |
||
| 196 | } |
||
| 197 | else if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) |
||
| 198 | { |
||
| 199 | // Cookie based tracking copied from search.php |
||
| 200 | $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE); |
||
| 201 | $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array(); |
||
| 202 | } |
||
| 203 | |||
| 204 | // We need to exclude passworded forums, so we do not leak the topic title |
||
| 205 | $passworded_forums = $this->user->get_passworded_forums(); |
||
| 206 | |||
| 207 | // See if the admin set this forum to only search a specific group of other forums, and include them |
||
| 208 | if (!empty($topic_data['similar_topic_forums'])) |
||
| 209 | { |
||
| 210 | // Remove any passworded forums from this group of forums we will be searching |
||
| 211 | $included_forums = array_diff(json_decode($topic_data['similar_topic_forums'], true), $passworded_forums); |
||
| 212 | // if there's nothing left to display (user has no access to the forums we want to search) |
||
| 213 | if (empty($included_forums)) |
||
| 214 | { |
||
| 215 | return; |
||
| 216 | } |
||
| 217 | |||
| 218 | $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $included_forums); |
||
| 219 | } |
||
| 220 | // Otherwise, exclude any ignored forums |
||
| 221 | else |
||
| 222 | { |
||
| 223 | // Remove any passworded forums |
||
| 224 | if (count($passworded_forums)) |
||
| 225 | { |
||
| 226 | $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $passworded_forums, true); |
||
| 227 | } |
||
| 228 | |||
| 229 | $sql_array['WHERE'] .= ' AND f.similar_topics_ignore = 0'; |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Event to modify the sql_array for similar topics |
||
| 234 | * |
||
| 235 | * @event vse.similartopics.get_topic_data |
||
| 236 | * @var array sql_array SQL array to get similar topics data |
||
| 237 | * @since 1.3.0 |
||
| 238 | */ |
||
| 239 | $vars = array('sql_array'); |
||
| 240 | extract($this->dispatcher->trigger_event('vse.similartopics.get_topic_data', compact($vars))); |
||
| 241 | |||
| 242 | $rowset = array(); |
||
| 243 | |||
| 244 | $sql = $this->db->sql_build_query('SELECT', $sql_array); |
||
| 245 | $result = $this->db->sql_query_limit($sql, $this->config['similar_topics_limit'], 0, $this->config['similar_topics_cache']); |
||
| 246 | while ($row = $this->db->sql_fetchrow($result)) |
||
| 247 | { |
||
| 248 | $rowset[(int) $row['topic_id']] = $row; |
||
| 249 | } |
||
| 250 | $this->db->sql_freeresult($result); |
||
| 251 | |||
| 252 | // Grab icons |
||
| 253 | $icons = $this->cache->obtain_icons(); |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Modify the rowset data for similar topics |
||
| 257 | * |
||
| 258 | * @event vse.similartopics.modify_rowset |
||
| 259 | * @var array rowset Array with the search results data |
||
| 260 | * @since 1.4.2 |
||
| 261 | */ |
||
| 262 | $vars = array('rowset'); |
||
| 263 | extract($this->dispatcher->trigger_event('vse.similartopics.modify_rowset', compact($vars))); |
||
| 264 | |||
| 265 | foreach ($rowset as $row) |
||
| 266 | { |
||
| 267 | $similar_forum_id = (int) $row['forum_id']; |
||
| 268 | $similar_topic_id = (int) $row['topic_id']; |
||
| 269 | |||
| 270 | if ($this->auth->acl_get('f_read', $similar_forum_id)) |
||
| 271 | { |
||
| 272 | // Get topic tracking info |
||
| 273 | if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) |
||
| 274 | { |
||
| 275 | $topic_tracking_info = get_topic_tracking($similar_forum_id, $similar_topic_id, $rowset, array($similar_forum_id => $row['f_mark_time'])); |
||
| 276 | } |
||
| 277 | else if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) |
||
| 278 | { |
||
| 279 | $topic_tracking_info = get_complete_topic_tracking($similar_forum_id, $similar_topic_id); |
||
| 280 | |||
| 281 | if (!$this->user->data['is_registered']) |
||
| 282 | { |
||
| 283 | $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? ((int) base_convert($tracking_topics['l'], 36, 10) + (int) $this->config['board_startdate']) : 0; |
||
| 284 | } |
||
| 285 | } |
||
| 286 | |||
| 287 | // Replies |
||
| 288 | $replies = $this->content_visibility->get_count('topic_posts', $row, $similar_forum_id) - 1; |
||
| 289 | |||
| 290 | // Get folder img, topic status/type related information |
||
| 291 | $folder_img = $folder_alt = $topic_type = ''; |
||
| 292 | $unread_topic = isset($topic_tracking_info[$similar_topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$similar_topic_id]; |
||
| 293 | topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); |
||
| 294 | |||
| 295 | $view_topic_url_params = 't=' . $similar_topic_id; |
||
| 296 | |||
| 297 | $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $similar_forum_id); |
||
| 298 | $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $similar_forum_id); |
||
| 299 | $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$this->root_path}mcp.$this->php_ext", 'i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&t=$similar_topic_id", true, $this->user->session_id) : ''; |
||
| 300 | |||
| 301 | $base_url = append_sid("{$this->root_path}viewtopic.$this->php_ext", $view_topic_url_params); |
||
| 302 | |||
| 303 | $topic_row = array( |
||
| 304 | 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), |
||
| 305 | 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), |
||
| 306 | 'FIRST_POST_TIME_RFC3339' => gmdate(DATE_RFC3339, $row['topic_time']), |
||
| 307 | 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), |
||
| 308 | 'LAST_POST_TIME_RFC3339' => gmdate(DATE_RFC3339, $row['topic_last_post_time']), |
||
| 309 | 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), |
||
| 310 | |||
| 311 | 'TOPIC_REPLIES' => $replies, |
||
| 312 | 'TOPIC_VIEWS' => $row['topic_views'], |
||
| 313 | 'TOPIC_TITLE' => censor_text($row['topic_title']), |
||
| 314 | 'FORUM_TITLE' => $row['forum_name'], |
||
| 315 | |||
| 316 | 'TOPIC_IMG_STYLE' => $folder_img, |
||
| 317 | 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), |
||
| 318 | 'TOPIC_FOLDER_IMG_ALT' => $this->language->lang($folder_alt), |
||
| 319 | |||
| 320 | 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', |
||
| 321 | 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', |
||
| 322 | 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', |
||
| 323 | 'ATTACH_ICON_IMG' => ($this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $similar_forum_id) && $row['topic_attachment']) ? $this->user->img('icon_topic_attach', $this->language->lang('TOTAL_ATTACHMENTS')) : '', |
||
| 324 | 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', |
||
| 325 | |||
| 326 | 'S_UNREAD_TOPIC' => $unread_topic, |
||
| 327 | 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $this->auth->acl_get('m_report', $similar_forum_id), |
||
| 328 | 'S_TOPIC_UNAPPROVED' => $topic_unapproved, |
||
| 329 | 'S_POSTS_UNAPPROVED' => $posts_unapproved, |
||
| 330 | 'S_HAS_POLL' => (bool) $row['poll_start'], |
||
| 331 | |||
| 332 | 'U_NEWEST_POST' => append_sid("{$this->root_path}viewtopic.$this->php_ext", $view_topic_url_params . '&view=unread') . '#unread', |
||
| 333 | 'U_LAST_POST' => append_sid("{$this->root_path}viewtopic.$this->php_ext", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], |
||
| 334 | 'U_VIEW_TOPIC' => $base_url, |
||
| 335 | 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.$this->php_ext", 'f=' . $similar_forum_id), |
||
| 336 | 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.$this->php_ext", 'i=reports&mode=reports&' . $view_topic_url_params, true, $this->user->session_id), |
||
| 337 | 'U_MCP_QUEUE' => $u_mcp_queue, |
||
| 338 | ); |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Event to modify the similar topics template block |
||
| 342 | * |
||
| 343 | * @event vse.similartopics.modify_topicrow |
||
| 344 | * @var array row Array with similar topic data |
||
| 345 | * @var array topic_row Template block array |
||
| 346 | * @since 1.3.0 |
||
| 347 | */ |
||
| 348 | $vars = array('row', 'topic_row'); |
||
| 349 | extract($this->dispatcher->trigger_event('vse.similartopics.modify_topicrow', compact($vars))); |
||
| 350 | |||
| 351 | $this->template->assign_block_vars('similar', $topic_row); |
||
| 352 | |||
| 353 | $this->pagination->generate_template_pagination($base_url, 'similar.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true); |
||
| 354 | } |
||
| 355 | } |
||
| 356 | |||
| 357 | $this->language->add_lang('similar_topics', 'vse/similartopics'); |
||
| 358 | |||
| 359 | $this->template->assign_vars(array( |
||
| 360 | 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), |
||
| 361 | 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), |
||
| 362 | 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), |
||
| 363 | 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), |
||
| 364 | )); |
||
| 487 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths