Conditions | 10 |
Paths | 2 |
Total Lines | 66 |
Code Lines | 44 |
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 |
||
167 | public function getErrorCodes(): array |
||
168 | { |
||
169 | $errors = array(); |
||
170 | |||
171 | if (count($this->errorCodes) > 0) { |
||
172 | foreach ($this->errorCodes as $error) { |
||
173 | switch ($error) { |
||
174 | case 'timeout-or-duplicate': |
||
175 | $errors[] = array( |
||
176 | 'code' => $error, |
||
177 | 'name' => 'Timeout or duplicate.', |
||
178 | ); |
||
179 | break; |
||
180 | |||
181 | case 'missing-input-secret': |
||
182 | $errors[] = array( |
||
183 | 'code' => $error, |
||
184 | 'name' => 'The secret parameter is missing.', |
||
185 | ); |
||
186 | break; |
||
187 | |||
188 | case 'invalid-input-secret': |
||
189 | $errors[] = array( |
||
190 | 'code' => $error, |
||
191 | 'name' => 'The secret parameter is invalid or malformed.', |
||
192 | ); |
||
193 | break; |
||
194 | |||
195 | case 'missing-input-response': |
||
196 | $errors[] = array( |
||
197 | 'code' => $error, |
||
198 | 'name' => 'The response parameter is missing.', |
||
199 | ); |
||
200 | break; |
||
201 | |||
202 | case 'invalid-input-response': |
||
203 | $errors[] = array( |
||
204 | 'code' => $error, |
||
205 | 'name' => 'The response parameter is invalid or malformed.', |
||
206 | ); |
||
207 | break; |
||
208 | |||
209 | case 'bad-request': |
||
210 | $errors[] = array( |
||
211 | 'code' => $error, |
||
212 | 'name' => 'The request is invalid or malformed.', |
||
213 | ); |
||
214 | break; |
||
215 | |||
216 | case 'internal-empty-response': |
||
217 | $errors[] = array( |
||
218 | 'code' => $error, |
||
219 | 'name' => 'The recaptcha response is required.', |
||
220 | ); |
||
221 | break; |
||
222 | |||
223 | default: |
||
224 | $errors[] = array( |
||
225 | 'code' => $error, |
||
226 | 'name' => $error, |
||
227 | ); |
||
228 | } |
||
229 | } |
||
230 | } |
||
231 | |||
232 | return $errors; |
||
233 | } |
||
259 | } |