Conditions | 13 |
Paths | 145 |
Total Lines | 37 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
39 | public function makeField(string $table, array $field, Column $column, bool $useTimestamps): array |
||
40 | { |
||
41 | if ($useTimestamps) { |
||
42 | if ($field['field'] === ColumnName::CREATED_AT) { |
||
43 | return []; |
||
44 | } elseif ($field['field'] === ColumnName::UPDATED_AT) { |
||
45 | $field['type'] = ColumnType::TIMESTAMPS; |
||
46 | $field['field'] = null; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if ($field['field'] === ColumnName::DELETED_AT && !$column->getNotnull()) { |
||
51 | $field['type'] = ColumnType::SOFT_DELETES; |
||
52 | $field['field'] = null; |
||
53 | } |
||
54 | |||
55 | if (isset(FieldGenerator::$fieldTypeMap[$field['type']])) { |
||
56 | $field['type'] = FieldGenerator::$fieldTypeMap[$field['type']]; |
||
57 | } |
||
58 | |||
59 | $length = $this->getLength($table, $column); |
||
60 | if ($length !== null && $length > 0) { |
||
61 | if ($field['type'] === ColumnType::SOFT_DELETES) { |
||
62 | $field['field'] = ColumnName::DELETED_AT; |
||
63 | } |
||
64 | $field['args'][] = $length; |
||
65 | } |
||
66 | |||
67 | if (app(MigrationsGeneratorSetting::class)->getPlatform() === Platform::MYSQL) { |
||
68 | if ($column->getType()->getName() === DBALTypes::TIMESTAMP) { |
||
69 | if ($this->mySQLRepository->useOnUpdateCurrentTimestamp($table, $column->getName())) { |
||
70 | $field['decorators'][] = ColumnModifier::USE_CURRENT_ON_UPDATE; |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | |||
75 | return $field; |
||
76 | } |
||
130 |