Passed
Pull Request — master (#372)
by Wilmer
03:26
created

AbstractConstraintProvider::getTableConstraints()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 122
Code Lines 90

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 90
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 122
rs 8.2181

How to fix   Long Method   

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 Yiisoft\Db\Tests\Provider;
6
7
use Yiisoft\Db\Constraint\CheckConstraint;
8
use Yiisoft\Db\Constraint\Constraint;
9
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
10
use Yiisoft\Db\Constraint\IndexConstraint;
11
use Yiisoft\Db\Schema\Schema;
12
use Yiisoft\Db\Tests\Support\AnyValue;
13
14
abstract class AbstractConstraintProvider
15
{
16
    protected function getTableConstraints(): array
17
    {
18
        return [
19
            '1: primary key' => [
20
                'T_constraints_1',
21
                Schema::PRIMARY_KEY,
22
                (new Constraint())->name(AnyValue::getInstance())->columnNames(['C_id']),
23
            ],
24
            '1: check' => [
25
                'T_constraints_1',
26
                Schema::CHECKS,
27
                [
28
                    (new CheckConstraint())
29
                        ->name(AnyValue::getInstance())
30
                        ->columnNames(['C_check'])
31
                        ->expression("C_check <> ''"),
32
                ],
33
            ],
34
            '1: unique' => [
35
                'T_constraints_1',
36
                Schema::UNIQUES,
37
                [
38
                    (new Constraint())->name('CN_unique')->columnNames(['C_unique']),
39
                ],
40
            ],
41
            '1: index' => [
42
                'T_constraints_1',
43
                Schema::INDEXES,
44
                [
45
                    (new IndexConstraint())
46
                        ->name(AnyValue::getInstance())
47
                        ->columnNames(['C_id'])
48
                        ->unique(true)
49
                        ->primary(true),
50
                    (new IndexConstraint())
51
                        ->name('CN_unique')
52
                        ->columnNames(['C_unique'])
53
                        ->primary(false)
54
                        ->unique(true),
55
                ],
56
            ],
57
            '1: default' => ['T_constraints_1', Schema::DEFAULT_VALUES, false],
58
59
            '2: primary key' => [
60
                'T_constraints_2',
61
                Schema::PRIMARY_KEY,
62
                (new Constraint())->name('CN_pk')->columnNames(['C_id_1', 'C_id_2']),
63
            ],
64
            '2: unique' => [
65
                'T_constraints_2',
66
                Schema::UNIQUES,
67
                [
68
                    (new Constraint())->name('CN_constraints_2_multi')->columnNames(['C_index_2_1', 'C_index_2_2']),
69
                ],
70
            ],
71
            '2: index' => [
72
                'T_constraints_2',
73
                Schema::INDEXES,
74
                [
75
                    (new IndexConstraint())
76
                        ->name(AnyValue::getInstance())
77
                        ->columnNames(['C_id_1', 'C_id_2'])
78
                        ->unique(true)
79
                        ->primary(true),
80
                    (new IndexConstraint())
81
                        ->name('CN_constraints_2_single')
82
                        ->columnNames(['C_index_1'])
83
                        ->primary(false)
84
                        ->unique(false),
85
                    (new IndexConstraint())
86
                        ->name('CN_constraints_2_multi')
87
                        ->columnNames(['C_index_2_1', 'C_index_2_2'])
88
                        ->primary(false)
89
                        ->unique(true),
90
                ],
91
            ],
92
            '2: check' => ['T_constraints_2', Schema::CHECKS, []],
93
            '2: default' => ['T_constraints_2', Schema::DEFAULT_VALUES, false],
94
95
            '3: primary key' => ['T_constraints_3', Schema::PRIMARY_KEY, null],
96
            '3: foreign key' => [
97
                'T_constraints_3',
98
                Schema::FOREIGN_KEYS,
99
                [
100
                    (new ForeignKeyConstraint())
101
                        ->name('CN_constraints_3')
102
                        ->columnNames(['C_fk_id_1', 'C_fk_id_2'])
103
                        ->foreignTableName('T_constraints_2')
104
                        ->foreignColumnNames(['C_id_1', 'C_id_2'])
105
                        ->onDelete('CASCADE')
106
                        ->onUpdate('CASCADE'),
107
                ],
108
            ],
109
            '3: unique' => ['T_constraints_3', Schema::UNIQUES, []],
110
            '3: index' => [
111
                'T_constraints_3',
112
                Schema::INDEXES,
113
                [
114
                    (new IndexConstraint())
115
                        ->name('CN_constraints_3')
116
                        ->columnNames(['C_fk_id_1', 'C_fk_id_2'])
117
                        ->unique(false)
118
                        ->primary(false),
119
                ],
120
            ],
121
            '3: check' => ['T_constraints_3', Schema::CHECKS, []],
122
            '3: default' => ['T_constraints_3', Schema::DEFAULT_VALUES, false],
123
124
            '4: primary key' => [
125
                'T_constraints_4',
126
                Schema::PRIMARY_KEY,
127
                (new Constraint())->name(AnyValue::getInstance())->columnNames(['C_id']),
128
            ],
129
            '4: unique' => [
130
                'T_constraints_4',
131
                Schema::UNIQUES,
132
                [
133
                    (new Constraint())->name('CN_constraints_4')->columnNames(['C_col_1', 'C_col_2']),
134
                ],
135
            ],
136
            '4: check' => ['T_constraints_4', Schema::CHECKS, []],
137
            '4: default' => ['T_constraints_4', Schema::DEFAULT_VALUES, false],
138
        ];
139
    }
140
}
141