Passed
Push — 2.x ( f09c73...766c68 )
by Aleksei
39:35 queued 23:36
created

Collector::collect()   F

Complexity

Conditions 14
Paths 516

Size

Total Lines 62
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 32
c 1
b 0
f 0
nc 516
nop 1
dl 0
loc 62
rs 2.7722

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Generator\Migrations\Changes;
6
7
use Cycle\Database\Schema\AbstractTable;
8
use Cycle\Migrations\Atomizer\Atomizer;
9
10
final class Collector
11
{
12
    /**
13
     * @return array<array{ChangeType, non-empty-string}>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array{ChangeType, non-empty-string}> at position 4 could not be parsed: Expected ':' at position 4, but found 'ChangeType'.
Loading history...
14
     */
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
    }
78
}
79