| Conditions | 12 |
| Paths | 64 |
| Total Lines | 78 |
| Code Lines | 59 |
| 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 |
||
| 155 | function sort_db_info($db_name, $db_rec) { |
||
| 156 | $file_list = array(); |
||
| 157 | $file_sort = array(); |
||
| 158 | |||
| 159 | $sort = get_str("sort", true); |
||
| 160 | $r = get_str("r", true); |
||
| 161 | |||
| 162 | if (empty($sort)) $sort = "name"; |
||
| 163 | // check for allowed keys |
||
| 164 | if ((strcmp($sort, "name")!=0) && |
||
| 165 | (strcmp($sort, "data_size")!=0) && |
||
| 166 | (strcmp($sort, "index_size")!=0) && |
||
| 167 | (strcmp($sort, "total_size")!=0) && |
||
| 168 | (strcmp($sort, "rows")!=0) && |
||
| 169 | (strcmp($sort, "size_per_row")!=0) |
||
| 170 | ) { |
||
| 171 | $sort = "name"; |
||
| 172 | } |
||
| 173 | if (empty($r)) $r=0; |
||
| 174 | |||
| 175 | for ($i=0; $i < sizeof($db_rec)-1; $i++){ |
||
| 176 | $file_details["name"] = $db_rec[$i]->name; |
||
| 177 | $file_details["data_size"] = $db_rec[$i]->data_size; |
||
| 178 | $file_details["index_size"] = $db_rec[$i]->index_size; |
||
| 179 | $file_details["total_size"] = $db_rec[$i]->total_size; |
||
| 180 | $file_details["rows"] = $db_rec[$i]->rows; |
||
| 181 | $file_details["size_per_row"] = $db_rec[$i]->size_per_row; |
||
| 182 | |||
| 183 | $file_list[$i] = $file_details; |
||
| 184 | $key = strtolower($file_details[$sort]); |
||
| 185 | $file_sort[$i] = $key; |
||
| 186 | } |
||
| 187 | |||
| 188 | if ($r) { |
||
| 189 | arsort($file_sort); |
||
| 190 | } else { |
||
| 191 | asort($file_sort); |
||
| 192 | } |
||
| 193 | |||
| 194 | echo "<table cols=6>"; |
||
| 195 | echo "<tr>"; |
||
| 196 | echo "<th colspan=6> Database $db_name </th>"; |
||
| 197 | echo "</tr>"; |
||
| 198 | |||
| 199 | echo "<tr>"; |
||
| 200 | echo "<th><a href='dbinfo.php?sort=name&r=" . (!$r) . "'>Table </a></th>"; |
||
| 201 | echo "<th><a href='dbinfo.php?sort=data_size&r=" . (!$r) . "'>Data Size</a></th>"; |
||
| 202 | echo "<th><a href='dbinfo.php?sort=index_size&r=" . (!$r) . "'>Index Size</a></th>"; |
||
| 203 | echo "<th><a href='dbinfo.php?sort=total_size&r=" . (!$r) . "'>Total Size</a></th>"; |
||
| 204 | echo "<th><a href='dbinfo.php?sort=rows&r=" . (!$r) . "'>Total Rows</a></th>"; |
||
| 205 | echo "<th><a href='dbinfo.php?sort=size_per_row&r=" . (!$r) . "'>Avg. Size per Row</a></th>"; |
||
| 206 | echo "</tr>"; |
||
| 207 | |||
| 208 | foreach ($file_sort as $key=>$value) { |
||
| 209 | $value = $file_list[$key]; |
||
| 210 | |||
| 211 | echo "<tr>"; |
||
| 212 | echo "<td align=left valign=top class=fieldname>" . $value["name"] . "</td>"; |
||
| 213 | echo "<td align=left valign=top class=fieldname>" . size_format($value["data_size"]) . "</td>"; |
||
| 214 | echo "<td align=left valign=top class=fieldname>" . size_format($value["index_size"]) . "</td>"; |
||
| 215 | echo "<td align=left valign=top class=fieldname>" . size_format($value["total_size"]) . "</td>"; |
||
| 216 | echo "<td align=left valign=top class=fieldname>" . number_format($value["rows"]) . "</td>"; |
||
| 217 | echo "<td align=left valign=top class=fieldname>" . size_format($value["size_per_row"]) . "</td>"; |
||
| 218 | echo "</tr>"; |
||
| 219 | } |
||
| 220 | |||
| 221 | // Last record is a summary |
||
| 222 | $i = sizeof($db_rec)-1; |
||
| 223 | echo "<tr>"; |
||
| 224 | echo "<th align=left>" . $db_rec[$i]->name . "</th>"; |
||
| 225 | echo "<th align=left>" . size_format($db_rec[$i]->data_size) . "</th>"; |
||
| 226 | echo "<th align=left>" . size_format($db_rec[$i]->index_size) . "</th>"; |
||
| 227 | echo "<th align=left>" . size_format($db_rec[$i]->total_size) . "</th>"; |
||
| 228 | echo "<th align=left>" . number_format($db_rec[$i]->rows) . "</th>"; |
||
| 229 | echo "<th align=left></th>"; |
||
| 230 | echo "</tr>"; |
||
| 231 | |||
| 232 | echo "</table>"; |
||
| 233 | } |
||
| 236 |