Conditions | 13 |
Paths | 99 |
Total Lines | 66 |
Code Lines | 31 |
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 |
||
86 | public function generate(string $table, $columns, Collection $indexes): array |
||
87 | { |
||
88 | if (count($columns) === 0) { |
||
89 | return []; |
||
90 | } |
||
91 | |||
92 | $useTimestamps = $this->datetimeField->isUseTimestamps($columns); |
||
93 | |||
94 | $fields = []; |
||
95 | |||
96 | foreach ($columns as $column) { |
||
97 | /** |
||
98 | * return [ |
||
99 | * field : Field name, |
||
100 | * type : Migration type method, eg: increments, string |
||
101 | * args : Migration type arguments, |
||
102 | * eg: decimal('amount', 8, 2) => decimal('amount', args[0], args[1]) |
||
103 | * decorators |
||
104 | * ] |
||
105 | */ |
||
106 | $dbalType = $column->getType()->getName(); |
||
107 | |||
108 | $field = [ |
||
109 | 'field' => $this->decorator->addSlash($column->getName()), |
||
110 | 'type' => $dbalType, |
||
111 | 'args' => [], |
||
112 | 'decorators' => [] |
||
113 | ]; |
||
114 | |||
115 | $field = $this->makeLaravelFieldTypeMethod($table, $field, $column, $indexes, $useTimestamps); |
||
116 | |||
117 | if (empty($field)) { |
||
118 | continue; |
||
119 | } |
||
120 | |||
121 | if (!$column->getNotnull()) { |
||
122 | if ($this->nullableModifier->shouldAddNullableModifier($field['type'])) { |
||
123 | $field['decorators'][] = ColumnModifier::NULLABLE; |
||
124 | } |
||
125 | } |
||
126 | |||
127 | if ($column->getDefault() !== null) { |
||
128 | $field['decorators'][] = $this->defaultModifier->generate($dbalType, $column); |
||
129 | } |
||
130 | |||
131 | if ($indexes->has($field['field'])) { |
||
132 | $field['decorators'][] = $this->indexModifier->generate($indexes->get($field['field'])); |
||
133 | } |
||
134 | |||
135 | if ($column->getComment() !== null) { |
||
136 | $field['decorators'][] = $this->commentModifier->generate($column->getComment()); |
||
137 | } |
||
138 | |||
139 | if (!$this->atLeastLaravel8()) { |
||
140 | if ($field['type'] === DBALTypes::TIMESTAMP) { |
||
141 | if (($key1 = array_search(ColumnModifier::USE_CURRENT, $field['decorators'])) !== false && |
||
142 | ($key2 = array_search(ColumnModifier::USE_CURRENT_ON_UPDATE, $field['decorators'])) !== false) { |
||
143 | unset($field['decorators'][$key1]); |
||
144 | unset($field['decorators'][$key2]); |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | |||
149 | $fields[] = $field; |
||
150 | } |
||
151 | return $fields; |
||
152 | } |
||
197 |