Conditions | 1 |
Paths | 1 |
Total Lines | 116 |
Code Lines | 90 |
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 |
||
31 | public function constraints(): array |
||
32 | { |
||
33 | return [ |
||
34 | '1: primary key' => [ |
||
35 | 'T_constraints_1', |
||
36 | Schema::PRIMARY_KEY, |
||
37 | (new Constraint())->name(AnyValue::getInstance())->columnNames(['C_id']), |
||
38 | ], |
||
39 | '1: check' => [ |
||
40 | 'T_constraints_1', |
||
41 | Schema::CHECKS, |
||
42 | [ |
||
43 | (new CheckConstraint()) |
||
44 | ->name(AnyValue::getInstance()) |
||
45 | ->columnNames(['C_check']) |
||
46 | ->expression("C_check <> ''"), |
||
47 | ], |
||
48 | ], |
||
49 | '1: unique' => [ |
||
50 | 'T_constraints_1', |
||
51 | Schema::UNIQUES, |
||
52 | [(new Constraint())->name('CN_unique')->columnNames(['C_unique'])], |
||
53 | ], |
||
54 | '1: index' => [ |
||
55 | 'T_constraints_1', |
||
56 | Schema::INDEXES, |
||
57 | [ |
||
58 | (new IndexConstraint()) |
||
59 | ->name(AnyValue::getInstance()) |
||
60 | ->columnNames(['C_id']) |
||
61 | ->unique(true) |
||
62 | ->primary(true), |
||
63 | (new IndexConstraint()) |
||
64 | ->name('CN_unique') |
||
65 | ->columnNames(['C_unique']) |
||
66 | ->primary(false) |
||
67 | ->unique(true), |
||
68 | ], |
||
69 | ], |
||
70 | '1: default' => ['T_constraints_1', Schema::DEFAULT_VALUES, false], |
||
71 | |||
72 | '2: primary key' => [ |
||
73 | 'T_constraints_2', |
||
74 | Schema::PRIMARY_KEY, |
||
75 | (new Constraint())->name('CN_pk')->columnNames(['C_id_1', 'C_id_2']), |
||
76 | ], |
||
77 | '2: unique' => [ |
||
78 | 'T_constraints_2', |
||
79 | Schema::UNIQUES, |
||
80 | [(new Constraint())->name('CN_constraints_2_multi')->columnNames(['C_index_2_1', 'C_index_2_2'])], |
||
81 | ], |
||
82 | '2: index' => [ |
||
83 | 'T_constraints_2', |
||
84 | Schema::INDEXES, |
||
85 | [ |
||
86 | (new IndexConstraint()) |
||
87 | ->name(AnyValue::getInstance()) |
||
88 | ->columnNames(['C_id_1', 'C_id_2']) |
||
89 | ->unique(true) |
||
90 | ->primary(true), |
||
91 | (new IndexConstraint()) |
||
92 | ->name('CN_constraints_2_single') |
||
93 | ->columnNames(['C_index_1']) |
||
94 | ->primary(false) |
||
95 | ->unique(false), |
||
96 | (new IndexConstraint()) |
||
97 | ->name('CN_constraints_2_multi') |
||
98 | ->columnNames(['C_index_2_1', 'C_index_2_2']) |
||
99 | ->primary(false) |
||
100 | ->unique(true), |
||
101 | ], |
||
102 | ], |
||
103 | '2: check' => ['T_constraints_2', Schema::CHECKS, []], |
||
104 | '2: default' => ['T_constraints_2', Schema::DEFAULT_VALUES, false], |
||
105 | |||
106 | '3: primary key' => ['T_constraints_3', Schema::PRIMARY_KEY, null], |
||
107 | '3: foreign key' => [ |
||
108 | 'T_constraints_3', |
||
109 | Schema::FOREIGN_KEYS, |
||
110 | [ |
||
111 | (new ForeignKeyConstraint()) |
||
112 | ->name('CN_constraints_3') |
||
113 | ->columnNames(['C_fk_id_1', 'C_fk_id_2']) |
||
114 | ->foreignTableName('T_constraints_2') |
||
115 | ->foreignColumnNames(['C_id_1', 'C_id_2']) |
||
116 | ->onDelete('CASCADE') |
||
117 | ->onUpdate('CASCADE'), |
||
118 | ], |
||
119 | ], |
||
120 | '3: unique' => ['T_constraints_3', Schema::UNIQUES, []], |
||
121 | '3: index' => [ |
||
122 | 'T_constraints_3', |
||
123 | Schema::INDEXES, |
||
124 | [ |
||
125 | (new IndexConstraint()) |
||
126 | ->name('CN_constraints_3') |
||
127 | ->columnNames(['C_fk_id_1', 'C_fk_id_2']) |
||
128 | ->unique(false) |
||
129 | ->primary(false), |
||
130 | ], |
||
131 | ], |
||
132 | '3: check' => ['T_constraints_3', Schema::CHECKS, []], |
||
133 | '3: default' => ['T_constraints_3', Schema::DEFAULT_VALUES, false], |
||
134 | |||
135 | '4: primary key' => [ |
||
136 | 'T_constraints_4', |
||
137 | Schema::PRIMARY_KEY, |
||
138 | (new Constraint())->name(AnyValue::getInstance())->columnNames(['C_id']), |
||
139 | ], |
||
140 | '4: unique' => [ |
||
141 | 'T_constraints_4', |
||
142 | Schema::UNIQUES, |
||
143 | [(new Constraint())->name('CN_constraints_4')->columnNames(['C_col_1', 'C_col_2'])], |
||
144 | ], |
||
145 | '4: check' => ['T_constraints_4', Schema::CHECKS, []], |
||
146 | '4: default' => ['T_constraints_4', Schema::DEFAULT_VALUES, false], |
||
147 | ]; |
||
198 |