| Conditions | 31 |
| Paths | 385 |
| Total Lines | 326 |
| Code Lines | 230 |
| 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 |
||
| 47 | public function doDefault($msg = '') |
||
| 48 | { |
||
| 49 | $lang = $this->lang; |
||
| 50 | $data = $this->misc->getDatabaseAccessor(); |
||
| 51 | |||
| 52 | $this->printTrail('table'); |
||
| 53 | $this->printTabs('table', 'info'); |
||
| 54 | $this->printMsg($msg); |
||
| 55 | |||
| 56 | // common params for printVal |
||
| 57 | $shownull = ['null' => true]; |
||
| 58 | |||
| 59 | // Fetch info |
||
| 60 | $referrers = $data->getReferrers($_REQUEST['table']); |
||
| 61 | $parents = $data->getTableParents($_REQUEST['table']); |
||
| 62 | $children = $data->getTableChildren($_REQUEST['table']); |
||
| 63 | $tablestatstups = $data->getStatsTableTuples($_REQUEST['table']); |
||
| 64 | $tablestatsio = $data->getStatsTableIO($_REQUEST['table']); |
||
| 65 | $indexstatstups = $data->getStatsIndexTuples($_REQUEST['table']); |
||
| 66 | $indexstatsio = $data->getStatsIndexIO($_REQUEST['table']); |
||
| 67 | |||
| 68 | // Check that there is some info |
||
| 69 | if (($referrers === -99 || ($referrers !== -99 && 0 == $referrers->recordCount())) |
||
| 70 | && 0 == $parents->recordCount() && 0 == $children->recordCount() |
||
| 71 | && (0 == $tablestatstups->recordCount() && 0 == $tablestatsio->recordCount() |
||
| 72 | && 0 == $indexstatstups->recordCount() && 0 == $indexstatsio->recordCount())) { |
||
|
2 ignored issues
–
show
|
|||
| 73 | $this->printMsg($lang['strnoinfo']); |
||
| 74 | } else { |
||
| 75 | // Referring foreign tables |
||
| 76 | if ($referrers !== -99 && $referrers->recordCount() > 0) { |
||
| 77 | echo "<h3>{$lang['strreferringtables']}</h3>\n"; |
||
| 78 | |||
| 79 | $columns = [ |
||
| 80 | 'schema' => [ |
||
| 81 | 'title' => $lang['strschema'], |
||
| 82 | 'field' => Decorator::field('nspname'), |
||
| 83 | ], |
||
| 84 | 'table' => [ |
||
| 85 | 'title' => $lang['strtable'], |
||
| 86 | 'field' => Decorator::field('relname'), |
||
| 87 | ], |
||
| 88 | 'name' => [ |
||
| 89 | 'title' => $lang['strname'], |
||
| 90 | 'field' => Decorator::field('conname'), |
||
| 91 | ], |
||
| 92 | 'definition' => [ |
||
| 93 | 'title' => $lang['strdefinition'], |
||
| 94 | 'field' => Decorator::field('consrc'), |
||
| 95 | ], |
||
| 96 | 'actions' => [ |
||
| 97 | 'title' => $lang['stractions'], |
||
| 98 | ], |
||
| 99 | ]; |
||
| 100 | |||
| 101 | $actions = [ |
||
| 102 | 'properties' => [ |
||
| 103 | 'content' => $lang['strproperties'], |
||
| 104 | 'attr' => [ |
||
| 105 | 'href' => [ |
||
| 106 | 'url' => 'constraints.php', |
||
| 107 | 'urlvars' => [ |
||
| 108 | 'schema' => Decorator::field('nspname'), |
||
| 109 | 'table' => Decorator::field('relname'), |
||
| 110 | ], |
||
| 111 | ], |
||
| 112 | ], |
||
| 113 | ], |
||
| 114 | ]; |
||
| 115 | |||
| 116 | echo $this->printTable($referrers, $columns, $actions, 'info-referrers', $lang['strnodata']); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Parent tables |
||
| 120 | if ($parents->recordCount() > 0) { |
||
| 121 | echo "<h3>{$lang['strparenttables']}</h3>\n"; |
||
| 122 | |||
| 123 | $columns = [ |
||
| 124 | 'schema' => [ |
||
| 125 | 'title' => $lang['strschema'], |
||
| 126 | 'field' => Decorator::field('nspname'), |
||
| 127 | ], |
||
| 128 | 'table' => [ |
||
| 129 | 'title' => $lang['strtable'], |
||
| 130 | 'field' => Decorator::field('relname'), |
||
| 131 | ], |
||
| 132 | 'actions' => [ |
||
| 133 | 'title' => $lang['stractions'], |
||
| 134 | ], |
||
| 135 | ]; |
||
| 136 | |||
| 137 | $actions = [ |
||
| 138 | 'properties' => [ |
||
| 139 | 'content' => $lang['strproperties'], |
||
| 140 | 'attr' => [ |
||
| 141 | 'href' => [ |
||
| 142 | 'url' => 'tblproperties.php', |
||
| 143 | 'urlvars' => [ |
||
| 144 | 'schema' => Decorator::field('nspname'), |
||
| 145 | 'table' => Decorator::field('relname'), |
||
| 146 | ], |
||
| 147 | ], |
||
| 148 | ], |
||
| 149 | ], |
||
| 150 | ]; |
||
| 151 | |||
| 152 | echo $this->printTable($parents, $columns, $actions, 'info-parents', $lang['strnodata']); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Child tables |
||
| 156 | if ($children->recordCount() > 0) { |
||
| 157 | echo "<h3>{$lang['strchildtables']}</h3>\n"; |
||
| 158 | |||
| 159 | $columns = [ |
||
| 160 | 'schema' => [ |
||
| 161 | 'title' => $lang['strschema'], |
||
| 162 | 'field' => Decorator::field('nspname'), |
||
| 163 | ], |
||
| 164 | 'table' => [ |
||
| 165 | 'title' => $lang['strtable'], |
||
| 166 | 'field' => Decorator::field('relname'), |
||
| 167 | ], |
||
| 168 | 'actions' => [ |
||
| 169 | 'title' => $lang['stractions'], |
||
| 170 | ], |
||
| 171 | ]; |
||
| 172 | |||
| 173 | $actions = [ |
||
| 174 | 'properties' => [ |
||
| 175 | 'content' => $lang['strproperties'], |
||
| 176 | 'attr' => [ |
||
| 177 | 'href' => [ |
||
| 178 | 'url' => 'tblproperties.php', |
||
| 179 | 'urlvars' => [ |
||
| 180 | 'schema' => Decorator::field('nspname'), |
||
| 181 | 'table' => Decorator::field('relname'), |
||
| 182 | ], |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | ]; |
||
| 187 | |||
| 188 | echo $this->printTable($children, $columns, $actions, 'info-children', $lang['strnodata']); |
||
| 189 | } |
||
| 190 | |||
| 191 | // Row performance |
||
| 192 | if ($tablestatstups->recordCount() > 0) { |
||
| 193 | echo "<h3>{$lang['strrowperf']}</h3>\n"; |
||
| 194 | |||
| 195 | echo "<table>\n"; |
||
| 196 | echo "\t<tr>\n"; |
||
| 197 | echo "\t\t<th class=\"data\" colspan=\"2\">{$lang['strsequential']}</th>\n"; |
||
| 198 | echo "\t\t<th class=\"data\" colspan=\"2\">{$lang['strindex']}</th>\n"; |
||
| 199 | echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strrows2']}</th>\n"; |
||
| 200 | echo "\t</tr>\n"; |
||
| 201 | echo "\t<tr>\n"; |
||
| 202 | echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n"; |
||
| 203 | echo "\t\t<th class=\"data\">{$lang['strread']}</th>\n"; |
||
| 204 | echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n"; |
||
| 205 | echo "\t\t<th class=\"data\">{$lang['strfetch']}</th>\n"; |
||
| 206 | echo "\t\t<th class=\"data\">{$lang['strinsert']}</th>\n"; |
||
| 207 | echo "\t\t<th class=\"data\">{$lang['strupdate']}</th>\n"; |
||
| 208 | echo "\t\t<th class=\"data\">{$lang['strdelete']}</th>\n"; |
||
| 209 | echo "\t</tr>\n"; |
||
| 210 | $i = 0; |
||
| 211 | |||
| 212 | while (!$tablestatstups->EOF) { |
||
| 213 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 214 | echo "\t<tr class=\"data{$id}\">\n"; |
||
| 215 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['seq_scan'], 'int4', $shownull), "</td>\n"; |
||
| 216 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['seq_tup_read'], 'int4', $shownull), "</td>\n"; |
||
| 217 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['idx_scan'], 'int4', $shownull), "</td>\n"; |
||
| 218 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['idx_tup_fetch'], 'int4', $shownull), "</td>\n"; |
||
| 219 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_ins'], 'int4', $shownull), "</td>\n"; |
||
| 220 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_upd'], 'int4', $shownull), "</td>\n"; |
||
| 221 | echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_del'], 'int4', $shownull), "</td>\n"; |
||
| 222 | echo "\t</tr>\n"; |
||
| 223 | $tablestatstups->movenext(); |
||
| 224 | ++$i; |
||
| 225 | } |
||
| 226 | |||
| 227 | echo "</table>\n"; |
||
| 228 | } |
||
| 229 | |||
| 230 | // I/O performance |
||
| 231 | if ($tablestatsio->recordCount() > 0) { |
||
| 232 | echo "<h3>{$lang['strioperf']}</h3>\n"; |
||
| 233 | |||
| 234 | echo "<table>\n"; |
||
| 235 | echo "\t<tr>\n"; |
||
| 236 | echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strheap']}</th>\n"; |
||
| 237 | echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strindex']}</th>\n"; |
||
| 238 | echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strtoast']}</th>\n"; |
||
| 239 | echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strtoastindex']}</th>\n"; |
||
| 240 | echo "\t</tr>\n"; |
||
| 241 | echo "\t<tr>\n"; |
||
| 242 | echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n"; |
||
| 243 | echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n"; |
||
| 244 | echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n"; |
||
| 245 | echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n"; |
||
| 246 | echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n"; |
||
| 247 | echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n"; |
||
| 248 | echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n"; |
||
| 249 | echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n"; |
||
| 250 | echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n"; |
||
| 251 | echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n"; |
||
| 252 | echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n"; |
||
| 253 | echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n"; |
||
| 254 | echo "\t</tr>\n"; |
||
| 255 | $i = 0; |
||
| 256 | |||
| 257 | while (!$tablestatsio->EOF) { |
||
| 258 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 259 | echo "\t<tr class=\"data{$id}\">\n"; |
||
| 260 | |||
| 261 | $total = $tablestatsio->fields['heap_blks_hit'] + $tablestatsio->fields['heap_blks_read']; |
||
| 262 | if ($total > 0) { |
||
| 263 | $percentage = round(($tablestatsio->fields['heap_blks_hit'] / $total) * 100); |
||
| 264 | } else { |
||
| 265 | $percentage = 0; |
||
| 266 | } |
||
| 267 | |||
| 268 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['heap_blks_read'], 'int4', $shownull), "</td>\n"; |
||
| 269 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['heap_blks_hit'], 'int4', $shownull), "</td>\n"; |
||
| 270 | echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n"; |
||
| 271 | |||
| 272 | $total = $tablestatsio->fields['idx_blks_hit'] + $tablestatsio->fields['idx_blks_read']; |
||
| 273 | if ($total > 0) { |
||
| 274 | $percentage = round(($tablestatsio->fields['idx_blks_hit'] / $total) * 100); |
||
| 275 | } else { |
||
| 276 | $percentage = 0; |
||
| 277 | } |
||
| 278 | |||
| 279 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['idx_blks_read'], 'int4', $shownull), "</td>\n"; |
||
| 280 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['idx_blks_hit'], 'int4', $shownull), "</td>\n"; |
||
| 281 | echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n"; |
||
| 282 | |||
| 283 | $total = $tablestatsio->fields['toast_blks_hit'] + $tablestatsio->fields['toast_blks_read']; |
||
| 284 | if ($total > 0) { |
||
| 285 | $percentage = round(($tablestatsio->fields['toast_blks_hit'] / $total) * 100); |
||
| 286 | } else { |
||
| 287 | $percentage = 0; |
||
| 288 | } |
||
| 289 | |||
| 290 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['toast_blks_read'], 'int4', $shownull), "</td>\n"; |
||
| 291 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['toast_blks_hit'], 'int4', $shownull), "</td>\n"; |
||
| 292 | echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n"; |
||
| 293 | |||
| 294 | $total = $tablestatsio->fields['tidx_blks_hit'] + $tablestatsio->fields['tidx_blks_read']; |
||
| 295 | if ($total > 0) { |
||
| 296 | $percentage = round(($tablestatsio->fields['tidx_blks_hit'] / $total) * 100); |
||
| 297 | } else { |
||
| 298 | $percentage = 0; |
||
| 299 | } |
||
| 300 | |||
| 301 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['tidx_blks_read'], 'int4', $shownull), "</td>\n"; |
||
| 302 | echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['tidx_blks_hit'], 'int4', $shownull), "</td>\n"; |
||
| 303 | echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n"; |
||
| 304 | echo "\t</tr>\n"; |
||
| 305 | $tablestatsio->movenext(); |
||
| 306 | ++$i; |
||
| 307 | } |
||
| 308 | |||
| 309 | echo "</table>\n"; |
||
| 310 | } |
||
| 311 | |||
| 312 | // Index row performance |
||
| 313 | if ($indexstatstups->recordCount() > 0) { |
||
| 314 | echo "<h3>{$lang['stridxrowperf']}</h3>\n"; |
||
| 315 | |||
| 316 | echo "<table>\n"; |
||
| 317 | echo "\t<tr>\n"; |
||
| 318 | echo "\t\t<th class=\"data\">{$lang['strindex']}</th>\n"; |
||
| 319 | echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n"; |
||
| 320 | echo "\t\t<th class=\"data\">{$lang['strread']}</th>\n"; |
||
| 321 | echo "\t\t<th class=\"data\">{$lang['strfetch']}</th>\n"; |
||
| 322 | echo "\t</tr>\n"; |
||
| 323 | $i = 0; |
||
| 324 | |||
| 325 | while (!$indexstatstups->EOF) { |
||
| 326 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 327 | echo "\t<tr class=\"data{$id}\">\n"; |
||
| 328 | echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['indexrelname']), "</td>\n"; |
||
| 329 | echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_scan'], 'int4', $shownull), "</td>\n"; |
||
| 330 | echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_tup_read'], 'int4', $shownull), "</td>\n"; |
||
| 331 | echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_tup_fetch'], 'int4', $shownull), "</td>\n"; |
||
| 332 | echo "\t</tr>\n"; |
||
| 333 | $indexstatstups->movenext(); |
||
| 334 | ++$i; |
||
| 335 | } |
||
| 336 | |||
| 337 | echo "</table>\n"; |
||
| 338 | } |
||
| 339 | |||
| 340 | // Index I/0 performance |
||
| 341 | if ($indexstatsio->recordCount() > 0) { |
||
| 342 | echo "<h3>{$lang['stridxioperf']}</h3>\n"; |
||
| 343 | |||
| 344 | echo "<table>\n"; |
||
| 345 | echo "\t<tr>\n"; |
||
| 346 | echo "\t\t<th class=\"data\">{$lang['strindex']}</th>\n"; |
||
| 347 | echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n"; |
||
| 348 | echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n"; |
||
| 349 | echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n"; |
||
| 350 | echo "\t</tr>\n"; |
||
| 351 | $i = 0; |
||
| 352 | |||
| 353 | while (!$indexstatsio->EOF) { |
||
| 354 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 355 | echo "\t<tr class=\"data{$id}\">\n"; |
||
| 356 | $total = $indexstatsio->fields['idx_blks_hit'] + $indexstatsio->fields['idx_blks_read']; |
||
| 357 | if ($total > 0) { |
||
| 358 | $percentage = round(($indexstatsio->fields['idx_blks_hit'] / $total) * 100); |
||
| 359 | } else { |
||
| 360 | $percentage = 0; |
||
| 361 | } |
||
| 362 | |||
| 363 | echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['indexrelname']), "</td>\n"; |
||
| 364 | echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['idx_blks_read'], 'int4', $shownull), "</td>\n"; |
||
| 365 | echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['idx_blks_hit'], 'int4', $shownull), "</td>\n"; |
||
| 366 | echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n"; |
||
| 367 | echo "\t</tr>\n"; |
||
| 368 | $indexstatsio->movenext(); |
||
| 369 | ++$i; |
||
| 370 | } |
||
| 371 | |||
| 372 | echo "</table>\n"; |
||
| 373 | } |
||
| 377 |