| Conditions | 13 |
| Paths | 200 |
| Total Lines | 93 |
| Code Lines | 67 |
| 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 |
||
| 19 | public function render() |
||
| 20 | { |
||
| 21 | $lang = $this->lang; |
||
| 22 | $data = $this->misc->getDatabaseAccessor(); |
||
| 23 | $action = $this->action; |
||
| 24 | |||
| 25 | if (isset($_POST['offset'])) { |
||
| 26 | $offset = " OFFSET {$_POST['offset']}"; |
||
| 27 | } else { |
||
| 28 | $_POST['offset'] = 0; |
||
| 29 | $offset = ' OFFSET 0'; |
||
| 30 | } |
||
| 31 | |||
| 32 | $keynames = []; |
||
| 33 | foreach ($_POST['fkeynames'] as $k => $v) { |
||
| 34 | $fkeynames[$k] = html_entity_decode($v, ENT_QUOTES); |
||
| 35 | } |
||
| 36 | |||
| 37 | $keyspos = array_combine($fkeynames, $_POST['keys']); |
||
| 38 | |||
| 39 | $f_schema = html_entity_decode($_POST['f_schema'], ENT_QUOTES); |
||
| 40 | $data->fieldClean($f_schema); |
||
| 41 | $f_table = html_entity_decode($_POST['f_table'], ENT_QUOTES); |
||
| 42 | $data->fieldClean($f_table); |
||
| 43 | $f_attname = $fkeynames[$_POST['fattpos'][0]]; |
||
| 44 | $data->fieldClean($f_attname); |
||
| 45 | |||
| 46 | $q = "SELECT * |
||
| 47 | FROM \"{$f_schema}\".\"{$f_table}\" |
||
| 48 | WHERE \"{$f_attname}\"::text LIKE '{$_POST['fvalue']}%' |
||
| 49 | ORDER BY \"{$f_attname}\" LIMIT 12 {$offset};"; |
||
| 50 | |||
| 51 | $res = $data->selectSet($q); |
||
| 52 | |||
| 53 | if (!$res->EOF) { |
||
| 54 | echo '<table class="ac_values">'; |
||
| 55 | echo '<tr>'; |
||
| 56 | foreach (array_keys($res->fields) as $h) { |
||
| 57 | echo '<th>'; |
||
| 58 | |||
| 59 | if (in_array($h, $fkeynames, true)) { |
||
| 60 | echo '<img src="' . $this->misc->icon('ForeignKey') . '" alt="[referenced key]" />'; |
||
| 61 | } |
||
| 62 | |||
| 63 | echo htmlentities($h, ENT_QUOTES, 'UTF-8'), '</th>'; |
||
| 64 | } |
||
| 65 | echo "</tr>\n"; |
||
| 66 | $i = 0; |
||
| 67 | while ((!$res->EOF) && ($i < 11)) { |
||
| 68 | $j = 0; |
||
| 69 | echo '<tr class="acline">'; |
||
| 70 | foreach ($res->fields as $n => $v) { |
||
| 71 | $finfo = $res->fetchField($j++); |
||
| 72 | if (in_array($n, $fkeynames, true)) { |
||
| 73 | echo "<td><a href=\"javascript:void(0)\" class=\"fkval\" name=\"{$keyspos[$n]}\">", |
||
| 74 | $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']), |
||
| 75 | '</a></td>'; |
||
| 76 | } else { |
||
| 77 | echo '<td><a href="javascript:void(0)">', |
||
| 78 | $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']), |
||
| 79 | '</a></td>'; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | echo "</tr>\n"; |
||
| 83 | ++$i; |
||
| 84 | $res->moveNext(); |
||
| 85 | } |
||
| 86 | echo "</table>\n"; |
||
| 87 | |||
| 88 | $page_tests = ''; |
||
| 89 | |||
| 90 | $js = "<script type=\"text/javascript\">\n"; |
||
| 91 | |||
| 92 | if ($_POST['offset']) { |
||
| 93 | echo '<a href="javascript:void(0)" id="fkprev"><< Prev</a>'; |
||
| 94 | $js .= "fkl_hasprev=true;\n"; |
||
| 95 | } else { |
||
| 96 | $js .= "fkl_hasprev=false;\n"; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (12 == $res->recordCount()) { |
||
| 100 | $js .= "fkl_hasnext=true;\n"; |
||
| 101 | echo ' <a href="javascript:void(0)" id="fknext">Next >></a>'; |
||
| 102 | } else { |
||
| 103 | $js .= "fkl_hasnext=false;\n"; |
||
| 104 | } |
||
| 105 | |||
| 106 | echo $js . '</script>'; |
||
| 107 | } else { |
||
| 108 | printf("<p>{$lang['strnofkref']}</p>", "\"{$_POST['f_schema']}\".\"{$_POST['f_table']}\".\"{$fkeynames[$_POST['fattpos']]}\""); |
||
| 109 | |||
| 110 | if ($_POST['offset']) { |
||
| 111 | echo '<a href="javascript:void(0)" class="fkprev">Prev <<</a>'; |
||
| 112 | } |
||
| 116 |