| 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 |
||
| 15 | public function collect(Atomizer $atomizer): array |
||
| 16 | { |
||
| 17 | $result = []; |
||
| 18 | |||
| 19 | foreach ($atomizer->getTables() as $table) { |
||
| 20 | if ($table->getStatus() === AbstractTable::STATUS_NEW) { |
||
| 21 | $result[] = [ChangeType::CreateTable, $table->getName()]; |
||
| 22 | continue; |
||
| 23 | } |
||
| 24 | |||
| 25 | if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
||
| 26 | $result[] = [ChangeType::DropTable, $table->getName()]; |
||
| 27 | continue; |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($table->getComparator()->isRenamed()) { |
||
| 31 | $result[] = [ChangeType::RenameTable, $table->getInitialName()]; |
||
| 32 | continue; |
||
| 33 | } |
||
| 34 | |||
| 35 | $result[] = [ChangeType::ChangeTable, $table->getName()]; |
||
| 36 | |||
| 37 | $comparator = $table->getComparator(); |
||
| 38 | |||
| 39 | foreach ($comparator->addedColumns() as $column) { |
||
| 40 | $result[] = [ChangeType::AddColumn, $column->getName()]; |
||
| 41 | } |
||
| 42 | |||
| 43 | foreach ($comparator->droppedColumns() as $column) { |
||
| 44 | $result[] = [ChangeType::DropColumn, $column->getName()]; |
||
| 45 | } |
||
| 46 | |||
| 47 | foreach ($comparator->alteredColumns() as $column) { |
||
| 48 | $result[] = [ChangeType::AlterColumn, $column[0]->getName()]; |
||
| 49 | } |
||
| 50 | |||
| 51 | foreach ($comparator->addedIndexes() as $index) { |
||
| 52 | $result[] = [ChangeType::AddIndex, $index->getName()]; |
||
| 53 | } |
||
| 54 | |||
| 55 | foreach ($comparator->droppedIndexes() as $index) { |
||
| 56 | $result[] = [ChangeType::DropIndex, $index->getName()]; |
||
| 57 | } |
||
| 58 | |||
| 59 | foreach ($comparator->alteredIndexes() as $index) { |
||
| 60 | $result[] = [ChangeType::AlterIndex, $index[0]->getName()]; |
||
| 61 | } |
||
| 62 | |||
| 63 | foreach ($comparator->addedForeignKeys() as $fk) { |
||
| 64 | $result[] = [ChangeType::AddFk, $fk->getName()]; |
||
| 65 | } |
||
| 66 | |||
| 67 | foreach ($comparator->droppedForeignKeys() as $fk) { |
||
| 68 | $result[] = [ChangeType::DropFk, $fk->getName()]; |
||
| 69 | } |
||
| 70 | |||
| 71 | foreach ($comparator->alteredForeignKeys() as $fk) { |
||
| 72 | $result[] = [ChangeType::AlterFk, $fk[0]->getName()]; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | return $result; |
||
| 77 | } |
||
| 79 |