| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 131 | public function dataValidationFailed(): array |
||
| 132 | { |
||
| 133 | $defaultErrors = ['' => ['Value must be either "1" or "0".']]; |
||
| 134 | $booleanErrors = ['' => ['Value must be either "true" or "false".']]; |
||
| 135 | |||
| 136 | return [ |
||
| 137 | ['5', [new BoolValue()], $defaultErrors], |
||
| 138 | |||
| 139 | [null, [new BoolValue()], $defaultErrors], |
||
| 140 | [[], [new BoolValue()], $defaultErrors], |
||
| 141 | |||
| 142 | [true, [new BoolValue(strict: true)], $defaultErrors], |
||
| 143 | [false, [new BoolValue(strict: true)], $defaultErrors], |
||
| 144 | |||
| 145 | ['0', [new BoolValue(trueValue: true, falseValue: false, strict: true)], $booleanErrors], |
||
| 146 | [[], [new BoolValue(trueValue: true, falseValue: false, strict: true)], $booleanErrors], |
||
| 147 | |||
| 148 | 'custom message' => [ |
||
| 149 | 5, |
||
| 150 | [new BoolValue(message: 'Custom error.')], |
||
| 151 | ['' => ['Custom error.']], |
||
| 152 | ], |
||
| 153 | 'custom message with parameters' => [ |
||
| 154 | 5, |
||
| 155 | [ |
||
| 156 | new BoolValue( |
||
| 157 | message: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
| 158 | ), |
||
| 159 | ], |
||
| 160 | ['' => ['Attribute - , true - 1, false - 0, value - 5.']], |
||
| 161 | ], |
||
| 162 | 'custom message with parameters, custom true and false values, strict' => [ |
||
| 163 | 5, |
||
| 164 | [ |
||
| 165 | new BoolValue( |
||
| 166 | trueValue: true, |
||
| 167 | falseValue: false, |
||
| 168 | strict: true, |
||
| 169 | message: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
| 170 | ), |
||
| 171 | ], |
||
| 172 | ['' => ['Attribute - , true - true, false - false, value - 5.']], |
||
| 173 | ], |
||
| 174 | 'custom message with parameters, attribute set' => [ |
||
| 175 | ['data' => 5], |
||
| 176 | [ |
||
| 177 | 'data' => new BoolValue( |
||
| 178 | message: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
| 179 | ), |
||
| 180 | ], |
||
| 181 | ['data' => ['Attribute - data, true - 1, false - 0, value - 5.']], |
||
| 182 | ], |
||
| 183 | 'custom incorrect input message' => [ |
||
| 184 | [], |
||
| 185 | [new BoolValue(incorrectInputMessage: 'Custom error.')], |
||
| 186 | ['' => ['Custom error.']], |
||
| 187 | ], |
||
| 188 | 'custom incorrect input message with parameters' => [ |
||
| 189 | [], |
||
| 190 | [ |
||
| 191 | new BoolValue( |
||
| 192 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 193 | ), |
||
| 194 | ], |
||
| 195 | ['' => ['Attribute - , true - 1, false - 0, type - array.']], |
||
| 196 | ], |
||
| 197 | 'custom incorrect input message with parameters, custom true and false values, strict' => [ |
||
| 198 | [], |
||
| 199 | [ |
||
| 200 | new BoolValue( |
||
| 201 | trueValue: true, |
||
| 202 | falseValue: false, |
||
| 203 | strict: true, |
||
| 204 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 205 | ), |
||
| 206 | ], |
||
| 207 | ['' => ['Attribute - , true - true, false - false, type - array.']], |
||
| 208 | ], |
||
| 209 | 'custom incorrect input message with parameters, attribute set' => [ |
||
| 210 | ['data' => []], |
||
| 211 | [ |
||
| 212 | 'data' => new BoolValue( |
||
| 213 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 214 | ), |
||
| 215 | ], |
||
| 216 | ['data' => ['Attribute - data, true - 1, false - 0, type - array.']], |
||
| 217 | ], |
||
| 218 | 'custom incorrect input message, null' => [ |
||
| 219 | null, |
||
| 220 | [ |
||
| 221 | new BoolValue( |
||
| 222 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 223 | ), |
||
| 224 | ], |
||
| 225 | ['' => ['Attribute - , true - 1, false - 0, type - null.']], |
||
| 226 | ], |
||
| 246 |