| Conditions | 10 |
| Paths | 61 |
| Total Lines | 86 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 48 | public function getAutocompleteFKProperties($table) |
||
| 49 | { |
||
| 50 | $data = $this->misc->getDatabaseAccessor(); |
||
| 51 | |||
| 52 | $fksprops = [ |
||
| 53 | 'byconstr' => [], |
||
| 54 | 'byfield' => [], |
||
| 55 | 'code' => '', |
||
| 56 | ]; |
||
| 57 | |||
| 58 | $constrs = $data->getConstraintsWithFields($table); |
||
| 59 | |||
| 60 | if (!$constrs->EOF) { |
||
| 61 | //$conrelid = $constrs->fields['conrelid']; |
||
| 62 | while (!$constrs->EOF) { |
||
| 63 | if ('f' === $constrs->fields['contype']) { |
||
| 64 | if (!isset($fksprops['byconstr'][$constrs->fields['conid']])) { |
||
| 65 | $fksprops['byconstr'][$constrs->fields['conid']] = [ |
||
| 66 | 'confrelid' => $constrs->fields['confrelid'], |
||
| 67 | 'f_table' => $constrs->fields['f_table'], |
||
| 68 | 'f_schema' => $constrs->fields['f_schema'], |
||
| 69 | 'pattnums' => [], |
||
| 70 | 'pattnames' => [], |
||
| 71 | 'fattnames' => [], |
||
| 72 | ]; |
||
| 73 | } |
||
| 74 | |||
| 75 | $fksprops['byconstr'][$constrs->fields['conid']]['pattnums'][] = $constrs->fields['p_attnum']; |
||
| 76 | $fksprops['byconstr'][$constrs->fields['conid']]['pattnames'][] = $constrs->fields['p_field']; |
||
| 77 | $fksprops['byconstr'][$constrs->fields['conid']]['fattnames'][] = $constrs->fields['f_field']; |
||
| 78 | |||
| 79 | if (!isset($fksprops['byfield'][$constrs->fields['p_attnum']])) { |
||
| 80 | $fksprops['byfield'][$constrs->fields['p_attnum']] = []; |
||
| 81 | } |
||
| 82 | |||
| 83 | $fksprops['byfield'][$constrs->fields['p_attnum']][] = $constrs->fields['conid']; |
||
| 84 | } |
||
| 85 | $constrs->moveNext(); |
||
| 86 | } |
||
| 87 | |||
| 88 | $fksprops['code'] = '<script type="text/javascript">' . \PHP_EOL; |
||
| 89 | $fksprops['code'] .= "var constrs = {};\n"; |
||
| 90 | |||
| 91 | foreach ($fksprops['byconstr'] as $conid => $props) { |
||
| 92 | $fksprops['code'] .= "constrs.constr_{$conid} = {\n"; |
||
| 93 | $fksprops['code'] .= 'pattnums: [' . \implode(',', $props['pattnums']) . "],\n"; |
||
| 94 | $fksprops['code'] .= "f_table:'" . \addslashes(\htmlentities($props['f_table'], \ENT_QUOTES, 'UTF-8')) . "',\n"; |
||
| 95 | $fksprops['code'] .= "f_schema:'" . \addslashes(\htmlentities($props['f_schema'], \ENT_QUOTES, 'UTF-8')) . "',\n"; |
||
| 96 | $_ = ''; |
||
| 97 | |||
| 98 | foreach ($props['pattnames'] as $n) { |
||
| 99 | $_ .= ",'" . \htmlentities($n, \ENT_QUOTES, 'UTF-8') . "'"; |
||
| 100 | } |
||
| 101 | $fksprops['code'] .= 'pattnames: [' . \mb_substr($_, 1) . "],\n"; |
||
| 102 | |||
| 103 | $_ = ''; |
||
| 104 | |||
| 105 | foreach ($props['fattnames'] as $n) { |
||
| 106 | $_ .= ",'" . \htmlentities($n, \ENT_QUOTES, 'UTF-8') . "'"; |
||
| 107 | } |
||
| 108 | |||
| 109 | $fksprops['code'] .= 'fattnames: [' . \mb_substr($_, 1) . "]\n"; |
||
| 110 | $fksprops['code'] .= "};\n"; |
||
| 111 | } |
||
| 112 | |||
| 113 | $fksprops['code'] .= "var attrs = {};\n"; |
||
| 114 | |||
| 115 | foreach ($fksprops['byfield'] as $attnum => $cstrs) { |
||
| 116 | $fksprops['code'] .= "attrs.attr_{$attnum} = [" . \implode(',', $fksprops['byfield'][$attnum]) . "];\n"; |
||
| 117 | } |
||
| 118 | |||
| 119 | $fksprops['code'] .= "var table='" . \addslashes(\htmlentities($table, \ENT_QUOTES, 'UTF-8')) . "';"; |
||
| 120 | $fksprops['code'] .= "var server='" . \htmlentities($_REQUEST['server'], \ENT_QUOTES, 'UTF-8') . "';"; |
||
| 121 | $fksprops['code'] .= "var database='" . \addslashes(\htmlentities($_REQUEST['database'], \ENT_QUOTES, 'UTF-8')) . "';"; |
||
| 122 | $fksprops['code'] .= "var subfolder='" . \containerInstance()->subFolder . "';"; |
||
| 123 | $fksprops['code'] .= '</script>' . \PHP_EOL; |
||
| 124 | |||
| 125 | $fksprops['code'] .= '<div id="fkbg"></div>'; |
||
| 126 | $fksprops['code'] .= '<div id="fklist"></div>'; |
||
| 127 | $fksprops['code'] .= '<script src="' . \containerInstance()->subFolder . '/assets/js/ac_insert_row.js" type="text/javascript"></script>'; |
||
| 128 | } else { |
||
| 129 | /* we have no foreign keys on this table */ |
||
| 130 | return false; |
||
| 131 | } |
||
| 132 | |||
| 133 | return $fksprops; |
||
| 134 | } |
||
| 151 |