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