| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 45 |
| 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 |
||
| 160 | public function dataValidationFailed(): array |
||
| 161 | { |
||
| 162 | $incorrectInputErrors = ['' => ['The value must be a string.']]; |
||
| 163 | $errors = ['' => ['This value is not a valid URL.']]; |
||
| 164 | $longUrl = 'http://' . str_repeat('u', 1990) . '.de'; |
||
| 165 | |||
| 166 | return [ |
||
| 167 | 'incorrect input, integer' => [1, [new Url()], $incorrectInputErrors], |
||
| 168 | 'incorrect input, string in array' => [['yiiframework.com'], [new Url()], $incorrectInputErrors], |
||
| 169 | 'incorrect input, object' => [new stdClass(), [new Url()], $incorrectInputErrors], |
||
| 170 | 'custom incorrect input message' => [ |
||
| 171 | 1, |
||
| 172 | [new Url(incorrectInputMessage: 'Custom incorrect input message.')], |
||
| 173 | ['' => ['Custom incorrect input message.']], |
||
| 174 | ], |
||
| 175 | 'custom incorrect input message with parameters' => [ |
||
| 176 | 1, |
||
| 177 | [new Url(incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 178 | ['' => ['Attribute - , type - int.']], |
||
| 179 | ], |
||
| 180 | 'custom incorrect input message with parameters, attribute set' => [ |
||
| 181 | ['attribute' => 1], |
||
| 182 | ['attribute' => [new Url(incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')]], |
||
| 183 | ['attribute' => ['Attribute - attribute, type - int.']], |
||
| 184 | ], |
||
| 185 | |||
| 186 | ['google.de', [new Url()], $errors], |
||
| 187 | ['htp://yiiframework.com', [new Url()], $errors], |
||
| 188 | ['ftp://ftp.ruhr-uni-bochum.de/', [new Url()], $errors], |
||
| 189 | ['http://invalid,domain', [new Url()], $errors], |
||
| 190 | ['http://example.com,', [new Url()], $errors], |
||
| 191 | ['http://example.com*12', [new Url()], $errors], |
||
| 192 | ['http://example.com,?test', [new Url()], $errors], |
||
| 193 | ['http://example.com:?test', [new Url()], $errors], |
||
| 194 | ['http://example.com:test', [new Url()], $errors], |
||
| 195 | ['http://example.com:123456/test', [new Url()], $errors], |
||
| 196 | ['http://äüö?=!"§$%&/()=}][{³²€.edu', [new Url()], $errors], |
||
| 197 | |||
| 198 | |||
| 199 | ['htp://yiiframework.com', [new Url(validSchemes: ['http', 'https', 'ftp', 'ftps'])], $errors], |
||
| 200 | // Relative URLs are not supported |
||
| 201 | ['//yiiframework.com', [new Url(validSchemes: ['http', 'https', 'ftp', 'ftps'])], $errors], |
||
| 202 | |||
| 203 | ['', [new Url(enableIdn: true)], $errors], |
||
| 204 | [$longUrl, [new Url(enableIdn: true)], $errors], |
||
| 205 | [$longUrl, [new Url()], $errors], |
||
| 206 | |||
| 207 | 'custom message' => [ |
||
| 208 | '', |
||
| 209 | [new Url(enableIdn: true, message: 'Custom message.')], |
||
| 210 | ['' => ['Custom message.']], |
||
| 211 | ], |
||
| 212 | 'custom message with parameters' => [ |
||
| 213 | 'not a url', |
||
| 214 | [new Url(enableIdn: true, message: 'Attribute - {attribute}, value - {value}.')], |
||
| 215 | ['' => ['Attribute - , value - not a url.']], |
||
| 216 | ], |
||
| 217 | 'custom message with parameters, attribute set' => [ |
||
| 218 | ['attribute' => 'not a url'], |
||
| 219 | ['attribute' => new Url(enableIdn: true, message: 'Attribute - {attribute}, value - {value}.')], |
||
| 220 | ['attribute' => ['Attribute - attribute, value - not a url.']], |
||
| 221 | ], |
||
| 241 |