| Conditions | 21 |
| Paths | 72 |
| Total Lines | 86 |
| Code Lines | 50 |
| 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 |
||
| 81 | function print_feed_multi_select($id, $default_ids = [], $attributes = "", $include_all_feeds = true, $root_id = null, $nest_level = 0) |
||
| 82 | { |
||
| 83 | $pdo = DB::pdo(); |
||
| 84 | print_r(in_array("CAT:6", $default_ids)); |
||
| 85 | if (!$root_id) { |
||
| 86 | print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>"; |
||
| 87 | if ($include_all_feeds) { |
||
| 88 | $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; |
||
| 89 | print "<option $is_selected value=\"0\">".__('All feeds')."</option>"; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | if (get_pref('ENABLE_FEED_CATS')) { |
||
| 93 | if (!$root_id) { |
||
| 94 | $root_id = null; |
||
| 95 | } |
||
| 96 | $sth = $pdo->prepare("SELECT id,title, |
||
| 97 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE |
||
| 98 | c2.parent_cat = ttrss_feed_categories.id) AS num_children |
||
| 99 | FROM ttrss_feed_categories |
||
| 100 | WHERE owner_uid = :uid AND |
||
| 101 | (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); |
||
| 102 | $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
||
| 103 | while ($line = $sth->fetch()) { |
||
| 104 | for ($i = 0; $i < $nest_level; $i++) { |
||
| 105 | $line["title"] = " - ".$line["title"]; |
||
| 106 | } |
||
| 107 | $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; |
||
| 108 | printf("<option $is_selected value='CAT:%d'>%s</option>", |
||
| 109 | $line["id"], htmlspecialchars($line["title"])); |
||
| 110 | |||
| 111 | if ($line["num_children"] > 0) { |
||
| 112 | print_feed_multi_select($id, $default_ids, $attributes, $include_all_feeds, $line["id"], $nest_level + 1); |
||
| 113 | } |
||
| 114 | |||
| 115 | $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds WHERE cat_id = ? AND owner_uid = ? ORDER BY title"); |
||
| 116 | $f_sth->execute([$line['id'], $_SESSION['uid']]); |
||
| 117 | while ($fline = $f_sth->fetch()) { |
||
| 118 | $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; |
||
| 119 | $fline["title"] = " + ".$fline["title"]; |
||
| 120 | for ($i = 0; $i < $nest_level; $i++) { |
||
| 121 | $fline["title"] = " - ".$fline["title"]; |
||
| 122 | } |
||
| 123 | printf("<option $is_selected value='%d'>%s</option>", $fline["id"], htmlspecialchars($fline["title"])); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | if (!$root_id) { |
||
| 128 | $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; |
||
| 129 | |||
| 130 | printf("<option $is_selected value='CAT:0'>%s</option>", |
||
| 131 | __("Uncategorized")); |
||
| 132 | |||
| 133 | $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
||
| 134 | WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title"); |
||
| 135 | $f_sth->execute([$_SESSION['uid']]); |
||
| 136 | |||
| 137 | while ($fline = $f_sth->fetch()) { |
||
| 138 | $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; |
||
| 139 | |||
| 140 | $fline["title"] = " + ".$fline["title"]; |
||
| 141 | |||
| 142 | for ($i = 0; $i < $nest_level; $i++) { |
||
| 143 | $fline["title"] = " - ".$fline["title"]; |
||
| 144 | } |
||
| 145 | |||
| 146 | printf("<option $is_selected value='%d'>%s</option>", |
||
| 147 | $fline["id"], htmlspecialchars($fline["title"])); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | } else { |
||
| 152 | $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
||
| 153 | WHERE owner_uid = ? ORDER BY title"); |
||
| 154 | $sth->execute([$_SESSION['uid']]); |
||
| 155 | |||
| 156 | while ($line = $sth->fetch()) { |
||
| 157 | |||
| 158 | $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; |
||
| 159 | |||
| 160 | printf("<option $is_selected value='%d'>%s</option>", |
||
| 161 | $line["id"], htmlspecialchars($line["title"])); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | if (!$root_id) { |
||
| 166 | print "</select>"; |
||
| 167 | } |
||
| 328 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.