| Conditions | 1 |
| Paths | 1 |
| Total Lines | 82 |
| Code Lines | 46 |
| 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 Boolean()], $defaultErrors], |
||
| 138 | |||
| 139 | [null, [new Boolean()], $defaultErrors], |
||
| 140 | [[], [new Boolean()], $defaultErrors], |
||
| 141 | |||
| 142 | [true, [new Boolean(strict: true)], $defaultErrors], |
||
| 143 | [false, [new Boolean(strict: true)], $defaultErrors], |
||
| 144 | |||
| 145 | ['0', [new Boolean(trueValue: true, falseValue: false, strict: true)], $booleanErrors], |
||
| 146 | [[], [new Boolean(trueValue: true, falseValue: false, strict: true)], $booleanErrors], |
||
| 147 | |||
| 148 | 'custom scalar message' => [5, [new Boolean(scalarMessage: 'Custom error.')], ['' => ['Custom error.']]], |
||
| 149 | 'custom scalar message with parameters' => [ |
||
| 150 | 5, |
||
| 151 | [ |
||
| 152 | new Boolean( |
||
| 153 | scalarMessage: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
| 154 | ), |
||
| 155 | ], |
||
| 156 | ['' => ['Attribute - , true - 1, false - 0, value - 5.']], |
||
| 157 | ], |
||
| 158 | 'custom scalar message with parameters, custom true and false values, strict' => [ |
||
| 159 | 5, |
||
| 160 | [ |
||
| 161 | new Boolean( |
||
| 162 | trueValue: true, |
||
| 163 | falseValue: false, |
||
| 164 | strict: true, |
||
| 165 | scalarMessage: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
| 166 | ), |
||
| 167 | ], |
||
| 168 | ['' => ['Attribute - , true - true, false - false, value - 5.']], |
||
| 169 | ], |
||
| 170 | 'custom scalar message with parameters, attribute set' => [ |
||
| 171 | ['data' => 5], |
||
| 172 | [ |
||
| 173 | 'data' => new Boolean( |
||
| 174 | scalarMessage: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
| 175 | ), |
||
| 176 | ], |
||
| 177 | ['data' => ['Attribute - data, true - 1, false - 0, value - 5.']], |
||
| 178 | ], |
||
| 179 | 'custom non-scalar message' => [ |
||
| 180 | [], |
||
| 181 | [new Boolean(nonScalarMessage: 'Custom error.')], |
||
| 182 | ['' => ['Custom error.']], |
||
| 183 | ], |
||
| 184 | 'custom non-scalar message with parameters' => [ |
||
| 185 | [], |
||
| 186 | [ |
||
| 187 | new Boolean( |
||
| 188 | nonScalarMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 189 | ), |
||
| 190 | ], |
||
| 191 | ['' => ['Attribute - , true - 1, false - 0, type - array.']], |
||
| 192 | ], |
||
| 193 | 'custom non-scalar message with parameters, custom true and false values, strict' => [ |
||
| 194 | [], |
||
| 195 | [ |
||
| 196 | new Boolean( |
||
| 197 | trueValue: true, |
||
| 198 | falseValue: false, |
||
| 199 | strict: true, |
||
| 200 | nonScalarMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 201 | ), |
||
| 202 | ], |
||
| 203 | ['' => ['Attribute - , true - true, false - false, type - array.']], |
||
| 204 | ], |
||
| 205 | 'custom non-scalar message with parameters, attribute set' => [ |
||
| 206 | ['data' => []], |
||
| 207 | [ |
||
| 208 | 'data' => new Boolean( |
||
| 209 | nonScalarMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
| 210 | ), |
||
| 211 | ], |
||
| 212 | ['data' => ['Attribute - data, true - 1, false - 0, type - array.']], |
||
| 213 | ], |
||
| 233 |