| Conditions | 12 |
| Paths | 109 |
| Total Lines | 33 |
| Code Lines | 19 |
| 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 |
||
| 28 | public function makeField(string $table, array $field, Column $column, bool $useTimestamps): array |
||
| 29 | { |
||
| 30 | if ($useTimestamps) { |
||
| 31 | if ($field['field'] === ColumnName::CREATED_AT) { |
||
| 32 | return []; |
||
| 33 | } elseif ($field['field'] === ColumnName::UPDATED_AT) { |
||
| 34 | $field['type'] = ColumnType::TIMESTAMPS; |
||
| 35 | $field['field'] = null; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($field['field'] === ColumnName::DELETED_AT && !$column->getNotnull()) { |
||
| 40 | $field['type'] = ColumnType::SOFT_DELETES; |
||
| 41 | $field['field'] = null; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (isset(FieldGenerator::$fieldTypeMap[$field['type']])) { |
||
| 45 | $field['type'] = FieldGenerator::$fieldTypeMap[$field['type']]; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($column->getLength() !== null && $column->getLength() > 0) { |
||
| 49 | if ($field['type'] === ColumnType::SOFT_DELETES) { |
||
| 50 | $field['field'] = ColumnName::DELETED_AT; |
||
| 51 | } |
||
| 52 | $field['args'][] = $column->getLength(); |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($column->getType()->getName() === DBALTypes::TIMESTAMP) { |
||
| 56 | if ($this->mySQLRepository->useOnUpdateCurrentTimestamp($table, $column->getName())) { |
||
| 57 | $field['decorators'][] = ColumnModifier::USE_CURRENT_ON_UPDATE; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | return $field; |
||
| 61 | } |
||
| 100 |