| Conditions | 1 |
| Paths | 1 |
| Total Lines | 99 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 108 | public function dataValidationFailed(): array |
||
| 109 | { |
||
| 110 | $errors = ['' => ['This value is not a subset of acceptable values.']]; |
||
| 111 | |||
| 112 | return [ |
||
| 113 | 'non-iterable' => [ |
||
| 114 | 1, |
||
| 115 | [new Subset([1, 2, 3])], |
||
| 116 | ['' => ['Value must be iterable.']], |
||
| 117 | ], |
||
| 118 | 'custom incorrect input message' => [ |
||
| 119 | 1, |
||
| 120 | [new Subset([1, 2, 3], incorrectInputMessage: 'Custom non-iterable message.')], |
||
| 121 | ['' => ['Custom non-iterable message.']], |
||
| 122 | ], |
||
| 123 | 'custom incorrect input message with parameters' => [ |
||
| 124 | 1, |
||
| 125 | [new Subset([1, 2, 3], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 126 | ['' => ['Attribute - , type - int.']], |
||
| 127 | ], |
||
| 128 | 'custom incorrect input message with parameters, attribute set' => [ |
||
| 129 | ['data' => 1], |
||
| 130 | ['data' => new Subset([1, 2, 3], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 131 | ['data' => ['Attribute - data, type - int.']], |
||
| 132 | ], |
||
| 133 | [ |
||
| 134 | [0, 1, 2], |
||
| 135 | [new Subset(range(1, 10))], |
||
| 136 | $errors, |
||
| 137 | ], |
||
| 138 | [ |
||
| 139 | [10, 11, 12], |
||
| 140 | [new Subset(range(1, 10))], |
||
| 141 | $errors, |
||
| 142 | ], |
||
| 143 | 'iterator as a value' => [ |
||
| 144 | new SingleValueDataSet(new ArrayObject(['c', 'd'])), |
||
| 145 | [new Subset(new ArrayObject(['a', 'b', 'c']))], |
||
| 146 | $errors, |
||
| 147 | ], |
||
| 148 | |||
| 149 | [[['1', 2], ['3', 4]], [new Subset([[1, 2], [3, 4], [5, 6]], strict: true)], $errors], |
||
| 150 | [[['1', '2'], ['3', '4']], [new Subset([[1, 2], [3, 4], [5, 6]], strict: true)], $errors], |
||
| 151 | [[[7, 8], [9, 10]], [new Subset([[1, 2], [3, 4], [5, 6]], strict: true)], $errors], |
||
| 152 | [[[2, 3], [4, 5]], [new Subset([[1, 2], [3, 4], [5, 6]], strict: true)], $errors], |
||
| 153 | [ |
||
| 154 | [ |
||
| 155 | ['data' => ['value' => [3, 4]]], |
||
| 156 | ['data' => ['value' => [5, 7]]], |
||
| 157 | ], |
||
| 158 | [ |
||
| 159 | new Subset([ |
||
| 160 | ['data' => ['value' => [1, 2]]], |
||
| 161 | ['data' => ['value' => [3, 4]]], |
||
| 162 | ['data' => ['value' => [5, 6]]], |
||
| 163 | ]), |
||
| 164 | ], |
||
| 165 | $errors, |
||
| 166 | ], |
||
| 167 | [ |
||
| 168 | [ |
||
| 169 | [ |
||
| 170 | 'data2' => ['value2' => [8, 7], 'value1' => [6, 5]], |
||
| 171 | 'data1' => ['value2' => [4, 3], 'value1' => [2, 1]], |
||
| 172 | ], |
||
| 173 | [ |
||
| 174 | 'data2' => ['value2' => [16, 15], 'value1' => [14, 13]], |
||
| 175 | 'data1' => ['value2' => [12, 11], 'value1' => [10, 9]], |
||
| 176 | ], |
||
| 177 | ], |
||
| 178 | [ |
||
| 179 | new Subset([ |
||
| 180 | [ |
||
| 181 | 'data1' => ['value1' => [1, 2], 'value2' => [3, 4]], |
||
| 182 | 'data2' => ['value1' => [5, 6], 'value2' => [7, 8]], |
||
| 183 | ], |
||
| 184 | [ |
||
| 185 | 'data1' => ['value1' => [9, 10], 'value2' => [11, 12]], |
||
| 186 | 'data2' => ['value1' => [13, 14], 'value2' => [15, 16]], |
||
| 187 | ], |
||
| 188 | ]), |
||
| 189 | ], |
||
| 190 | $errors, |
||
| 191 | ], |
||
| 192 | |||
| 193 | 'custom message' => [ |
||
| 194 | ['' => ['c']], |
||
| 195 | ['' => new Subset(['a', 'b'], message: 'Custom message.')], |
||
| 196 | ['' => ['Custom message.']], |
||
| 197 | ], |
||
| 198 | 'custom message with parameters' => [ |
||
| 199 | ['' => ['c']], |
||
| 200 | ['' => new Subset(['a', 'b'], message: 'Attribute - {attribute}.')], |
||
| 201 | ['' => ['Attribute - .']], |
||
| 202 | ], |
||
| 203 | 'custom message with parameters, attribute set' => [ |
||
| 204 | ['data' => ['c']], |
||
| 205 | ['data' => new Subset(['a', 'b'], message: 'Attribute - {attribute}.')], |
||
| 206 | ['data' => ['Attribute - data.']], |
||
| 207 | ], |
||
| 227 |