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