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