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