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 |
||
12 | public function generate(Atomizer $atomizer): string |
||
13 | { |
||
14 | $name = []; |
||
15 | |||
16 | foreach ($atomizer->getTables() as $table) { |
||
17 | if ($table->getStatus() === AbstractTable::STATUS_NEW) { |
||
18 | $name[] = 'create_' . $table->getName(); |
||
19 | continue; |
||
20 | } |
||
21 | |||
22 | if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
||
23 | $name[] = 'drop_' . $table->getName(); |
||
24 | continue; |
||
25 | } |
||
26 | |||
27 | if ($table->getComparator()->isRenamed()) { |
||
28 | $name[] = 'rename_' . $table->getInitialName(); |
||
29 | continue; |
||
30 | } |
||
31 | |||
32 | $name[] = 'change_' . $table->getName(); |
||
33 | |||
34 | $comparator = $table->getComparator(); |
||
35 | |||
36 | foreach ($comparator->addedColumns() as $column) { |
||
37 | $name[] = 'add_' . $column->getName(); |
||
38 | } |
||
39 | |||
40 | foreach ($comparator->droppedColumns() as $column) { |
||
41 | $name[] = 'rm_' . $column->getName(); |
||
42 | } |
||
43 | |||
44 | foreach ($comparator->alteredColumns() as $column) { |
||
45 | $name[] = 'alter_' . $column[0]->getName(); |
||
46 | } |
||
47 | |||
48 | foreach ($comparator->addedIndexes() as $index) { |
||
49 | $name[] = 'add_index_' . $index->getName(); |
||
50 | } |
||
51 | |||
52 | foreach ($comparator->droppedIndexes() as $index) { |
||
53 | $name[] = 'rm_index_' . $index->getName(); |
||
54 | } |
||
55 | |||
56 | foreach ($comparator->alteredIndexes() as $index) { |
||
57 | $name[] = 'alter_index_' . $index[0]->getName(); |
||
58 | } |
||
59 | |||
60 | foreach ($comparator->addedForeignKeys() as $fk) { |
||
61 | $name[] = 'add_fk_' . $fk->getName(); |
||
62 | } |
||
63 | |||
64 | foreach ($comparator->droppedForeignKeys() as $fk) { |
||
65 | $name[] = 'rm_fk_' . $fk->getName(); |
||
66 | } |
||
67 | |||
68 | foreach ($comparator->alteredForeignKeys() as $fk) { |
||
69 | $name[] = 'alter_fk_' . $fk[0]->getName(); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return \implode('_', $name); |
||
74 | } |
||
76 |