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 |
||
131 | public function dataValidationFailed(): array |
||
132 | { |
||
133 | $incorrectInputErrors = ['' => ['The value must have a string type.']]; |
||
134 | $errors = ['' => ['This value is not a valid URL.']]; |
||
135 | $longUrl = 'http://' . str_repeat('u', 1990) . '.de'; |
||
136 | |||
137 | return [ |
||
138 | 'incorrect input, integer' => [1, [new Url()], $incorrectInputErrors], |
||
139 | 'incorrect input, string in array' => [['yiiframework.com'], [new Url()], $incorrectInputErrors], |
||
140 | 'incorrect input, object' => [new stdClass(), [new Url()], $incorrectInputErrors], |
||
141 | 'custom incorrect input message' => [ |
||
142 | 1, |
||
143 | [new Url(incorrectInputMessage: 'Custom incorrect input message.')], |
||
144 | ['' => ['Custom incorrect input message.']], |
||
145 | ], |
||
146 | 'custom incorrect input message with parameters' => [ |
||
147 | 1, |
||
148 | [new Url(incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
149 | ['' => ['Attribute - , type - int.']], |
||
150 | ], |
||
151 | 'custom incorrect input message with parameters, attribute set' => [ |
||
152 | ['attribute' => 1], |
||
153 | ['attribute' => [new Url(incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')]], |
||
154 | ['attribute' => ['Attribute - attribute, type - int.']], |
||
155 | ], |
||
156 | |||
157 | ['google.de', [new Url()], $errors], |
||
158 | ['htp://yiiframework.com', [new Url()], $errors], |
||
159 | ['ftp://ftp.ruhr-uni-bochum.de/', [new Url()], $errors], |
||
160 | ['http://invalid,domain', [new Url()], $errors], |
||
161 | ['http://example.com,', [new Url()], $errors], |
||
162 | ['http://example.com*12', [new Url()], $errors], |
||
163 | ['http://example.com,?test', [new Url()], $errors], |
||
164 | ['http://example.com:?test', [new Url()], $errors], |
||
165 | ['http://example.com:test', [new Url()], $errors], |
||
166 | ['http://example.com:123456/test', [new Url()], $errors], |
||
167 | ['http://äüö?=!"§$%&/()=}][{³²€.edu', [new Url()], $errors], |
||
168 | |||
169 | |||
170 | ['htp://yiiframework.com', [new Url(validSchemes: ['http', 'https', 'ftp', 'ftps'])], $errors], |
||
171 | // Relative URLs are not supported |
||
172 | ['//yiiframework.com', [new Url(validSchemes: ['http', 'https', 'ftp', 'ftps'])], $errors], |
||
173 | |||
174 | ['', [new Url(enableIDN: true)], $errors], |
||
175 | [$longUrl, [new Url(enableIDN: true)], $errors], |
||
176 | [$longUrl, [new Url()], $errors], |
||
177 | |||
178 | 'custom message' => [ |
||
179 | '', |
||
180 | [new Url(enableIDN: true, message: 'Custom message.')], |
||
181 | ['' => ['Custom message.']], |
||
182 | ], |
||
183 | 'custom message with parameters' => [ |
||
184 | 'not a url', |
||
185 | [new Url(enableIDN: true, message: 'Attribute - {attribute}, value - {value}.')], |
||
186 | ['' => ['Attribute - , value - not a url.']], |
||
187 | ], |
||
188 | 'custom message with parameters, attribute set' => [ |
||
189 | ['attribute' => 'not a url'], |
||
190 | ['attribute' => new Url(enableIDN: true, message: 'Attribute - {attribute}, value - {value}.')], |
||
191 | ['attribute' => ['Attribute - attribute, value - not a url.']], |
||
192 | ], |
||
196 |