| Conditions | 9 |
| Paths | 34 |
| Total Lines | 106 |
| Code Lines | 58 |
| 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 |
||
| 129 | public function hook_prefs_tab($args) { |
||
| 130 | if ($args != "prefFeeds") { |
||
| 131 | return; |
||
| 132 | } |
||
| 133 | |||
| 134 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
||
| 135 | title=\"<i class='material-icons'>extension</i> ".__('Mark similar articles as read')."\">"; |
||
| 136 | |||
| 137 | if (DB_TYPE != "pgsql") { |
||
|
|
|||
| 138 | print_error("Database type not supported."); |
||
| 139 | } else { |
||
| 140 | |||
| 141 | $res = $this->pdo->query("select 'similarity'::regproc"); |
||
| 142 | |||
| 143 | if (!$res->fetch()) { |
||
| 144 | print_error("pg_trgm extension not found."); |
||
| 145 | } |
||
| 146 | |||
| 147 | $similarity = $this->host->get($this, "similarity"); |
||
| 148 | $min_title_length = $this->host->get($this, "min_title_length"); |
||
| 149 | $enable_globally = $this->host->get($this, "enable_globally"); |
||
| 150 | |||
| 151 | if (!$similarity) { |
||
| 152 | $similarity = '0.75'; |
||
| 153 | } |
||
| 154 | if (!$min_title_length) { |
||
| 155 | $min_title_length = '32'; |
||
| 156 | } |
||
| 157 | |||
| 158 | print "<form dojoType=\"dijit.form.Form\">"; |
||
| 159 | |||
| 160 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
||
| 161 | evt.preventDefault(); |
||
| 162 | if (this.validate()) { |
||
| 163 | console.log(dojo.objectToQuery(this.getValues())); |
||
| 164 | new Ajax.Request('backend.php', { |
||
| 165 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 166 | onComplete: function(transport) { |
||
| 167 | Notify.info(transport.responseText); |
||
| 168 | } |
||
| 169 | }); |
||
| 170 | //this.reset(); |
||
| 171 | } |
||
| 172 | </script>"; |
||
| 173 | |||
| 174 | print_hidden("op", "pluginhandler"); |
||
| 175 | print_hidden("method", "save"); |
||
| 176 | print_hidden("plugin", "af_psql_trgm"); |
||
| 177 | |||
| 178 | print "<h2>".__("Global settings")."</h2>"; |
||
| 179 | |||
| 180 | print_notice("Enable for specific feeds in the feed editor."); |
||
| 181 | |||
| 182 | print "<fieldset>"; |
||
| 183 | |||
| 184 | print "<label>".__("Minimum similarity:")."</label> "; |
||
| 185 | print "<input dojoType=\"dijit.form.NumberSpinner\" |
||
| 186 | placeholder=\"0.75\" id='psql_trgm_similarity' |
||
| 187 | required=\"1\" name=\"similarity\" value=\"$similarity\">"; |
||
| 188 | |||
| 189 | print "<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>". |
||
| 190 | __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking."). |
||
| 191 | "</div>"; |
||
| 192 | |||
| 193 | print "</fieldset><fieldset>"; |
||
| 194 | |||
| 195 | print "<label>".__("Minimum title length:")."</label> "; |
||
| 196 | print "<input dojoType=\"dijit.form.NumberSpinner\" |
||
| 197 | placeholder=\"32\" |
||
| 198 | required=\"1\" name=\"min_title_length\" value=\"$min_title_length\">"; |
||
| 199 | |||
| 200 | print "</fieldset><fieldset>"; |
||
| 201 | |||
| 202 | print "<label class='checkbox'>"; |
||
| 203 | print_checkbox("enable_globally", $enable_globally); |
||
| 204 | print " ".__("Enable for all feeds:"); |
||
| 205 | print "</label>"; |
||
| 206 | |||
| 207 | print "</fieldset>"; |
||
| 208 | |||
| 209 | print_button("submit", __("Save"), "class='alt-primary'"); |
||
| 210 | print "</form>"; |
||
| 211 | |||
| 212 | $enabled_feeds = $this->host->get($this, "enabled_feeds"); |
||
| 213 | if (!array($enabled_feeds)) { |
||
| 214 | $enabled_feeds = array(); |
||
| 215 | } |
||
| 216 | |||
| 217 | $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds); |
||
| 218 | $this->host->set($this, "enabled_feeds", $enabled_feeds); |
||
| 219 | |||
| 220 | if (count($enabled_feeds) > 0) { |
||
| 221 | print "<h3>".__("Currently enabled for (click to edit):")."</h3>"; |
||
| 222 | |||
| 223 | print "<ul class=\"panel panel-scrollable list list-unstyled\">"; |
||
| 224 | foreach ($enabled_feeds as $f) { |
||
| 225 | print "<li>". |
||
| 226 | "<i class='material-icons'>rss_feed</i> <a href='#' |
||
| 227 | onclick='CommonDialogs.editFeed($f)'>". |
||
| 228 | Feeds::getFeedTitle($f)."</a></li>"; |
||
| 229 | } |
||
| 230 | print "</ul>"; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | print "</div>"; |
||
| 235 | } |
||
| 377 |