| Conditions | 1 |
| Paths | 1 |
| Total Lines | 83 |
| Code Lines | 53 |
| 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 |
||
| 129 | public function dataValidationFailed(): array |
||
| 130 | { |
||
| 131 | $errors = ['' => ['This value is not in the list of acceptable values.']]; |
||
| 132 | |||
| 133 | return [ |
||
| 134 | [0, [new In(range(1, 10))], $errors], |
||
| 135 | [11, [new In(range(1, 10))], $errors], |
||
| 136 | [5.5, [new In(range(1, 10))], $errors], |
||
| 137 | |||
| 138 | [null, [new In(range(1, 10))], $errors], |
||
| 139 | ['0', [new In(range(1, 10))], $errors], |
||
| 140 | [0, [new In(range(1, 10))], $errors], |
||
| 141 | ['', [new In(range(1, 10))], $errors], |
||
| 142 | |||
| 143 | ['1', [new In(range(1, 10), strict: true)], $errors], |
||
| 144 | ['10', [new In(range(1, 10), strict: true)], $errors], |
||
| 145 | ['5.5', [new In(range(1, 10), strict: true)], $errors], |
||
| 146 | [['1', '2', '3', '4', '5', '6'], [new In(range(1, 10), strict: true)], $errors], |
||
| 147 | [['1', '2', '3', 4, 5, 6], [new In(range(1, 10), strict: true)], $errors], |
||
| 148 | |||
| 149 | [1, [new In(range(1, 10), not: true)], $errors], |
||
| 150 | [10, [new In(range(1, 10), not: true)], $errors], |
||
| 151 | ['10', [new In(range(1, 10), not: true)], $errors], |
||
| 152 | ['5', [new In(range(1, 10), not: true)], $errors], |
||
| 153 | |||
| 154 | 'arrays, non-strict equality (partially), strict mode' => [ |
||
| 155 | ['1', 2], |
||
| 156 | [new In([[1, 2], [3, 4]], strict: true)], |
||
| 157 | $errors, |
||
| 158 | ], |
||
| 159 | 'arrays, non-strict equality (fully), strict mode' => [ |
||
| 160 | ['1', '2'], |
||
| 161 | [new In([[1, 2], [3, 4]], strict: true)], |
||
| 162 | $errors, |
||
| 163 | ], |
||
| 164 | 'arrays, items are not from acceptable list' => [[5, 6], [new In([[1, 2], [3, 4]])], $errors], |
||
| 165 | 'arrays, items from acceptable list but not as a unit' => [[2, 3], [new In([[1, 2], [3, 4]])], $errors], |
||
| 166 | 'arrays, reversed order' => [[2, 1], [new In([[1, 2], [3, 4]])], $errors], |
||
| 167 | 'arrays, nested, items are not from acceptable list' => [ |
||
| 168 | ['data' => ['value' => [5, 6]]], |
||
| 169 | [ |
||
| 170 | new In([ |
||
| 171 | ['data' => ['value' => [1, 2]]], |
||
| 172 | ['data' => ['value' => [3, 4]]], |
||
| 173 | ]), |
||
| 174 | ], |
||
| 175 | $errors, |
||
| 176 | ], |
||
| 177 | 'arrays, nested, reversed order of values in lists' => [ |
||
| 178 | [ |
||
| 179 | 'data2' => ['value2' => [8, 7], 'value1' => [6, 5]], |
||
| 180 | 'data1' => ['value2' => [4, 3], 'value1' => [2, 1]], |
||
| 181 | ], |
||
| 182 | [ |
||
| 183 | new In([ |
||
| 184 | [ |
||
| 185 | 'data1' => ['value1' => [1, 2], 'value2' => [3, 4]], |
||
| 186 | 'data2' => ['value1' => [5, 6], 'value2' => [7, 8]], |
||
| 187 | ], |
||
| 188 | [ |
||
| 189 | 'data1' => ['value1' => [9, 10], 'value2' => [11, 12]], |
||
| 190 | 'data2' => ['value1' => [13, 14], 'value2' => [15, 16]], |
||
| 191 | ], |
||
| 192 | ]), |
||
| 193 | ], |
||
| 194 | $errors, |
||
| 195 | ], |
||
| 196 | 'attempt to use a a subset' => [ |
||
| 197 | [ |
||
| 198 | ['data' => ['value' => [1, 2]]], |
||
| 199 | ['data' => ['value' => [3, 4]]], |
||
| 200 | ], |
||
| 201 | [ |
||
| 202 | new In([ |
||
| 203 | ['data' => ['value' => [1, 2]]], |
||
| 204 | ['data' => ['value' => [3, 4]]], |
||
| 205 | ['data' => ['value' => [5, 6]]], |
||
| 206 | ]), |
||
| 207 | ], |
||
| 208 | $errors, |
||
| 209 | ], |
||
| 210 | |||
| 211 | 'custom error' => [15, [new In(range(1, 10), message: 'Custom error')], ['' => ['Custom error']]], |
||
| 212 | ]; |
||
| 231 |