Conditions | 14 |
Paths | 516 |
Total Lines | 62 |
Code Lines | 32 |
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 |
||
144 | private function generateName(Atomizer $atomizer): string |
||
145 | { |
||
146 | $name = []; |
||
147 | |||
148 | foreach ($atomizer->getTables() as $table) { |
||
149 | if ($table->getStatus() === AbstractTable::STATUS_NEW) { |
||
150 | $name[] = 'create_' . $table->getName(); |
||
151 | continue; |
||
152 | } |
||
153 | |||
154 | if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
||
155 | $name[] = 'drop_' . $table->getName(); |
||
156 | continue; |
||
157 | } |
||
158 | |||
159 | if ($table->getComparator()->isRenamed()) { |
||
160 | $name[] = 'rename_' . $table->getInitialName(); |
||
161 | continue; |
||
162 | } |
||
163 | |||
164 | $name[] = 'change_' . $table->getName(); |
||
165 | |||
166 | $comparator = $table->getComparator(); |
||
167 | |||
168 | foreach ($comparator->addedColumns() as $column) { |
||
169 | $name[] = 'add_' . $column->getName(); |
||
170 | } |
||
171 | |||
172 | foreach ($comparator->droppedColumns() as $column) { |
||
173 | $name[] = 'rm_' . $column->getName(); |
||
174 | } |
||
175 | |||
176 | foreach ($comparator->alteredColumns() as $column) { |
||
177 | $name[] = 'alter_' . $column[0]->getName(); |
||
178 | } |
||
179 | |||
180 | foreach ($comparator->addedIndexes() as $index) { |
||
181 | $name[] = 'add_index_' . $index->getName(); |
||
182 | } |
||
183 | |||
184 | foreach ($comparator->droppedIndexes() as $index) { |
||
185 | $name[] = 'rm_index_' . $index->getName(); |
||
186 | } |
||
187 | |||
188 | foreach ($comparator->alteredIndexes() as $index) { |
||
189 | $name[] = 'alter_index_' . $index[0]->getName(); |
||
190 | } |
||
191 | |||
192 | foreach ($comparator->addedForeignKeys() as $fk) { |
||
193 | $name[] = 'add_fk_' . $fk->getName(); |
||
194 | } |
||
195 | |||
196 | foreach ($comparator->droppedForeignKeys() as $fk) { |
||
197 | $name[] = 'rm_fk_' . $fk->getName(); |
||
198 | } |
||
199 | |||
200 | foreach ($comparator->alteredForeignKeys() as $fk) { |
||
201 | $name[] = 'alter_fk_' . $fk[0]->getName(); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | return join('_', $name); |
||
206 | } |
||
208 |