Conditions | 47 |
Paths | 6363 |
Total Lines | 167 |
Code Lines | 144 |
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 |
||
181 | private function getDatabaseFields($moduleDirname, $tableMid, $tableId, $tableName, $tableAutoincrement, $fieldsNumb) |
||
182 | { |
||
183 | $helper = Modulebuilder\Helper::getInstance(); |
||
184 | $ret = null; |
||
185 | $j = 0; |
||
186 | $comma = []; |
||
187 | $row = []; |
||
188 | //$type = ''; |
||
189 | $fieldTypeName = ''; |
||
190 | $fields = $this->getTableFields($tableMid, $tableId, 'field_order ASC, field_id'); |
||
191 | foreach (\array_keys($fields) as $f) { |
||
192 | // Creation of database table |
||
193 | $ret = $this->getHeadDatabaseTable($moduleDirname, $tableName, $fieldsNumb); |
||
194 | $fieldName = $fields[$f]->getVar('field_name'); |
||
195 | $fieldType = $fields[$f]->getVar('field_type'); |
||
196 | $fieldValue = \str_replace(''', '', $fields[$f]->getVar('field_value')); //remove single quotes |
||
197 | $fieldAttribute = $fields[$f]->getVar('field_attribute'); |
||
198 | $fieldNull = $fields[$f]->getVar('field_null'); |
||
199 | $fieldDefault = \str_replace(''', '', $fields[$f]->getVar('field_default')); //remove single quotes |
||
200 | $fieldKey = $fields[$f]->getVar('field_key'); |
||
201 | if ($fieldType > 1) { |
||
202 | $fType = $helper->getHandler('Fieldtype')->get($fieldType); |
||
203 | $fieldTypeName = $fType->getVar('fieldtype_name'); |
||
204 | } else { |
||
205 | $fieldType = null; |
||
206 | } |
||
207 | if ($fieldAttribute > 1) { |
||
208 | $fAttribute = $helper->getHandler('Fieldattributes')->get($fieldAttribute); |
||
209 | $fieldAttribute = $fAttribute->getVar('fieldattribute_name'); |
||
210 | } else { |
||
211 | $fieldAttribute = null; |
||
212 | } |
||
213 | if ($fieldNull > 1) { |
||
214 | $fNull = $helper->getHandler('Fieldnull')->get($fieldNull); |
||
215 | $fieldNull = $fNull->getVar('fieldnull_name'); |
||
216 | } else { |
||
217 | $fieldNull = null; |
||
218 | } |
||
219 | if (!empty($fieldName)) { |
||
220 | switch ($fieldType) { |
||
221 | case 2: |
||
222 | case 3: |
||
223 | case 4: |
||
224 | case 5: |
||
225 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
226 | if (empty($fieldDefault)) { |
||
227 | $default = "DEFAULT '0'"; |
||
228 | } else { |
||
229 | $default = "DEFAULT '{$fieldDefault}'"; |
||
230 | } |
||
231 | break; |
||
232 | case 6: |
||
233 | case 7: |
||
234 | case 8: |
||
235 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
236 | if (empty($fieldDefault)) { |
||
237 | $default = "DEFAULT '0'"; // From MySQL 5.7 Manual |
||
238 | } else { |
||
239 | $default = "DEFAULT '{$fieldDefault}'"; |
||
240 | } |
||
241 | break; |
||
242 | case 9: |
||
243 | case 10: |
||
244 | $fValues = \str_replace(',', "', '", \str_replace(' ', '', $fieldValue)); |
||
245 | $type = $fieldTypeName . '(\'' . $fValues . '\')'; // Used with comma separator |
||
246 | $default = "DEFAULT '{$fieldDefault}'"; |
||
247 | break; |
||
248 | case 11: |
||
249 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
250 | if (empty($fieldDefault)) { |
||
251 | $default = "DEFAULT '[email protected]'"; |
||
252 | } else { |
||
253 | $default = "DEFAULT '{$fieldDefault}'"; |
||
254 | } |
||
255 | break; |
||
256 | case 12: |
||
257 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
258 | if (empty($fieldDefault)) { |
||
259 | $default = "DEFAULT 'https:\\'"; |
||
260 | } else { |
||
261 | $default = "DEFAULT '{$fieldDefault}'"; |
||
262 | } |
||
263 | break; |
||
264 | case 13: |
||
265 | case 14: |
||
266 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
267 | $default = "DEFAULT '{$fieldDefault}'"; |
||
268 | break; |
||
269 | case 15: |
||
270 | case 16: |
||
271 | case 17: |
||
272 | case 18: |
||
273 | $type = $fieldTypeName; |
||
274 | $default = null; |
||
275 | break; |
||
276 | case 19: |
||
277 | case 20: |
||
278 | case 21: |
||
279 | case 22: |
||
280 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
281 | $default = "DEFAULT '{$fieldDefault}'"; |
||
282 | break; |
||
283 | case 23: |
||
284 | $type = $fieldTypeName; |
||
285 | if (empty($fieldDefault)) { |
||
286 | $default = "DEFAULT '1970'"; // From MySQL 5.7 Manual |
||
287 | } else { |
||
288 | $default = "DEFAULT '{$fieldDefault}'"; |
||
289 | } |
||
290 | break; |
||
291 | default: |
||
292 | $type = $fieldTypeName . '(' . $fieldValue . ')'; |
||
293 | $default = "DEFAULT '{$fieldDefault}'"; |
||
294 | break; |
||
295 | } |
||
296 | if ((0 == $f) && (1 == $tableAutoincrement)) { |
||
297 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, null, 'AUTO_INCREMENT'); |
||
298 | $comma[$j] = $this->getKey(2, $fieldName); |
||
299 | ++$j; |
||
300 | } elseif ((0 == $f) && (0 == $tableAutoincrement)) { |
||
301 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default); |
||
302 | $comma[$j] = $this->getKey(2, $fieldName); |
||
303 | ++$j; |
||
304 | } else { |
||
305 | if (3 == $fieldKey || 4 == $fieldKey || 5 == $fieldKey || 6 == $fieldKey) { |
||
306 | switch ($fieldKey) { |
||
307 | case 3: |
||
308 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default); |
||
309 | $comma[$j] = $this->getKey(3, $fieldName); |
||
310 | ++$j; |
||
311 | break; |
||
312 | case 4: |
||
313 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default); |
||
314 | $comma[$j] = $this->getKey(4, $fieldName); |
||
315 | ++$j; |
||
316 | break; |
||
317 | case 5: |
||
318 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default); |
||
319 | $comma[$j] = $this->getKey(5, $fieldName); |
||
320 | ++$j; |
||
321 | break; |
||
322 | case 6: |
||
323 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default); |
||
324 | $comma[$j] = $this->getKey(6, $fieldName); |
||
325 | ++$j; |
||
326 | break; |
||
327 | } |
||
328 | } else { |
||
329 | $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default); |
||
330 | } |
||
331 | } |
||
332 | } |
||
333 | } |
||
334 | // ================= COMMA ================= // |
||
335 | for ($i = 0; $i < $j; ++$i) { |
||
336 | if ($i != $j - 1) { |
||
337 | $row[] = $comma[$i] . ','; |
||
338 | } else { |
||
339 | $row[] = $comma[$i]; |
||
340 | } |
||
341 | } |
||
342 | // ================= COMMA CICLE ================= // |
||
343 | $ret .= \implode("\n", $row); |
||
344 | unset($j); |
||
345 | $ret .= $this->getFootDatabaseTable(); |
||
346 | |||
347 | return $ret; |
||
348 | } |
||
470 |