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