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