| Conditions | 18 |
| Paths | 30 |
| Total Lines | 153 |
| Code Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 16 | ||
| 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 |
||
| 97 | public function main() |
||
| 98 | { |
||
| 99 | $this->user->add_lang_ext('vse/similartopics', 'acp_similar_topics'); |
||
| 100 | |||
| 101 | $this->tpl_name = 'acp_similar_topics'; |
||
| 102 | $this->page_title = $this->user->lang('PST_TITLE_ACP'); |
||
| 103 | |||
| 104 | $form_key = 'acp_similar_topics'; |
||
| 105 | add_form_key($form_key); |
||
| 106 | |||
| 107 | $action = $this->request->variable('action', ''); |
||
| 108 | |||
| 109 | switch ($action) |
||
| 110 | { |
||
| 111 | case 'advanced': |
||
| 112 | $forum_id = $this->request->variable('f', 0); |
||
| 113 | |||
| 114 | if ($this->request->is_set_post('submit')) |
||
| 115 | { |
||
| 116 | $this->check_form_key($form_key); |
||
| 117 | |||
| 118 | $similar_topic_forums = $this->request->variable('similar_forums_id', array(0)); |
||
| 119 | $similar_topic_forums = !empty($similar_topic_forums) ? json_encode($similar_topic_forums) : ''; |
||
| 120 | |||
| 121 | $sql = 'UPDATE ' . FORUMS_TABLE . " |
||
| 122 | SET similar_topic_forums = '" . $this->db->sql_escape($similar_topic_forums) . "' |
||
| 123 | WHERE forum_id = $forum_id"; |
||
| 124 | $this->db->sql_query($sql); |
||
| 125 | |||
| 126 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'PST_LOG_MSG'); |
||
| 127 | |||
| 128 | $this->end('PST_SAVED'); |
||
| 129 | } |
||
| 130 | |||
| 131 | $forum_name = ''; |
||
| 132 | $selected = array(); |
||
| 133 | if ($forum_id > 0) |
||
| 134 | { |
||
| 135 | $sql = 'SELECT forum_name, similar_topic_forums |
||
| 136 | FROM ' . FORUMS_TABLE . " |
||
| 137 | WHERE forum_id = $forum_id"; |
||
| 138 | $result = $this->db->sql_query($sql); |
||
| 139 | while ($fid = $this->db->sql_fetchrow($result)) |
||
| 140 | { |
||
| 141 | $selected = json_decode($fid['similar_topic_forums'], true); |
||
| 142 | $forum_name = $fid['forum_name']; |
||
| 143 | } |
||
| 144 | $this->db->sql_freeresult($result); |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->template->assign_vars(array( |
||
| 148 | 'S_ADVANCED_SETTINGS' => true, |
||
| 149 | 'SIMILAR_FORUMS_OPTIONS' => make_forum_select($selected, false, false, true), |
||
| 150 | 'PST_FORUM_NAME' => $forum_name, |
||
| 151 | 'U_ACTION' => $this->u_action . '&action=advanced&f=' . $forum_id, |
||
| 152 | 'U_BACK' => $this->u_action, |
||
| 153 | )); |
||
| 154 | break; |
||
| 155 | |||
| 156 | default: |
||
| 157 | if ($this->request->is_set_post('submit')) |
||
| 158 | { |
||
| 159 | $this->check_form_key($form_key); |
||
| 160 | |||
| 161 | // Set basic config settings |
||
| 162 | $this->config->set('similar_topics', $this->request->variable('pst_enable', 0)); |
||
| 163 | $this->config->set('similar_topics_limit', abs($this->request->variable('pst_limit', 0))); // use abs for positive values only |
||
| 164 | $this->config->set('similar_topics_cache', abs($this->request->variable('pst_cache', 0))); // use abs for positive values only |
||
| 165 | $this->config_text_set('similar_topics_words', $this->request->variable('pst_words', '', true)); |
||
| 166 | |||
| 167 | // Set sensitivity |
||
| 168 | $pst_sense = min(abs($this->request->variable('pst_sense', 5)), 10); // use abs for positive values only |
||
| 169 | $this->config->set('similar_topics_sense', $pst_sense); |
||
| 170 | |||
| 171 | // Set date/time config settings |
||
| 172 | $pst_time = abs($this->request->variable('pst_time', 0)); // use abs for positive values only |
||
| 173 | $pst_time_type = $this->request->variable('pst_time_type', ''); |
||
| 174 | $this->config->set('similar_topics_type', $pst_time_type); |
||
| 175 | $this->config->set('similar_topics_time', $this->set_pst_time($pst_time, $pst_time_type)); |
||
| 176 | |||
| 177 | // Set checkbox array form data |
||
| 178 | $this->update_forum('similar_topics_hide', $this->request->variable('mark_noshow_forum', array(0), true)); |
||
| 179 | $this->update_forum('similar_topics_ignore', $this->request->variable('mark_ignore_forum', array(0), true)); |
||
| 180 | |||
| 181 | // Set PostgreSQL TS Name |
||
| 182 | if ($this->similartopics && $this->similartopics->get_type() === 'postgres') |
||
| 183 | { |
||
| 184 | $ts_name = $this->request->variable('pst_postgres_ts_name', ($this->config['pst_postgres_ts_name'] ?: 'simple')); |
||
| 185 | $this->config->set('pst_postgres_ts_name', $ts_name); |
||
| 186 | $this->similartopics->create_fulltext_index('topic_title'); |
||
| 187 | } |
||
| 188 | |||
| 189 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'PST_LOG_MSG'); |
||
| 190 | |||
| 191 | $this->cache->destroy('sql', TOPICS_TABLE); |
||
| 192 | |||
| 193 | $this->end('PST_SAVED'); |
||
| 194 | } |
||
| 195 | |||
| 196 | // Build the time options select menu |
||
| 197 | $time_options = array( |
||
| 198 | 'd' => 'PST_DAYS', |
||
| 199 | 'w' => 'PST_WEEKS', |
||
| 200 | 'm' => 'PST_MONTHS', |
||
| 201 | 'y' => 'PST_YEARS' |
||
| 202 | ); |
||
| 203 | foreach ($time_options as $value => $label) |
||
| 204 | { |
||
| 205 | $this->template->assign_block_vars('similar_time_options', array( |
||
| 206 | 'VALUE' => $value, |
||
| 207 | 'LABEL' => $label, |
||
| 208 | 'S_SELECTED' => $value === $this->config['similar_topics_type'], |
||
| 209 | )); |
||
| 210 | } |
||
| 211 | |||
| 212 | $this->template->assign_vars(array( |
||
| 213 | 'S_PST_ENABLE' => $this->isset_or_default($this->config['similar_topics'], false), |
||
| 214 | 'PST_LIMIT' => $this->isset_or_default($this->config['similar_topics_limit'], ''), |
||
| 215 | 'PST_CACHE' => $this->isset_or_default($this->config['similar_topics_cache'], ''), |
||
| 216 | 'PST_SENSE' => $this->isset_or_default($this->config['similar_topics_sense'], ''), |
||
| 217 | 'PST_WORDS' => $this->isset_or_default($this->config_text_get('similar_topics_words'), ''), |
||
| 218 | 'PST_TIME' => $this->get_pst_time($this->config['similar_topics_time'], $this->config['similar_topics_type']), |
||
| 219 | 'S_PST_NO_COMPAT' => $this->similartopics === null || !$this->similartopics->is_fulltext('topic_title'), |
||
| 220 | 'U_ACTION' => $this->u_action, |
||
| 221 | )); |
||
| 222 | |||
| 223 | // If postgresql, we need to make an options list of text search names |
||
| 224 | if ($this->similartopics && $this->similartopics->get_type() === 'postgres') |
||
| 225 | { |
||
| 226 | $this->user->add_lang('acp/search'); |
||
| 227 | foreach ($this->get_cfgname_list() as $row) |
||
| 228 | { |
||
| 229 | $this->template->assign_block_vars('postgres_ts_names', array( |
||
| 230 | 'NAME' => $row['ts_name'], |
||
| 231 | 'S_SELECTED' => $row['ts_name'] === $this->config['pst_postgres_ts_name'], |
||
| 232 | )); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | $forum_list = $this->get_forum_list(); |
||
| 237 | foreach ($forum_list as $row) |
||
| 238 | { |
||
| 239 | $this->template->assign_block_vars('forums', array( |
||
| 240 | 'FORUM_NAME' => $row['forum_name'], |
||
| 241 | 'FORUM_ID' => $row['forum_id'], |
||
| 242 | 'CHECKED_IGNORE_FORUM' => $row['similar_topics_ignore'] ? 'checked="checked"' : '', |
||
| 243 | 'CHECKED_NOSHOW_FORUM' => $row['similar_topics_hide'] ? 'checked="checked"' : '', |
||
| 244 | 'S_IS_ADVANCED' => (bool) $row['similar_topic_forums'], |
||
| 245 | 'U_ADVANCED' => "{$this->u_action}&action=advanced&f=" . $row['forum_id'], |
||
| 246 | 'U_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']), |
||
| 247 | )); |
||
| 248 | } |
||
| 249 | break; |
||
| 250 | } |
||
| 411 |
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