Conditions | 38 |
Paths | 28 |
Total Lines | 85 |
Code Lines | 56 |
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 |
||
215 | public static function validateOption($name, $value) |
||
216 | { |
||
217 | switch ($name) { |
||
218 | /* Site Options */ |
||
219 | |||
220 | case 'site_url': |
||
221 | if (empty($value) || ! isValidURL($value)) { |
||
222 | throw new InvalidArgumentException(__('Invalid site URL.')); |
||
223 | } |
||
224 | break; |
||
225 | case 'site_name': |
||
226 | if (empty($value) || ! is_string($value)) { |
||
227 | throw new InvalidArgumentException(__('Invalid site name.')); |
||
228 | } |
||
229 | break; |
||
230 | case 'site_slogan': |
||
231 | break; |
||
232 | case 'site_email': |
||
233 | if (empty($value) || ! isValidEmail($value)) { |
||
234 | throw new InvalidArgumentException(__('Invalid site e-mail address.')); |
||
235 | } |
||
236 | break; |
||
237 | case 'site_locale': |
||
238 | if (! empty($value)) { |
||
239 | $locale = Locales::findLocale($value); |
||
240 | if (empty($locale)) { |
||
241 | throw new InvalidArgumentException(__('Could not find the locale.')); |
||
242 | } |
||
243 | } |
||
244 | break; |
||
245 | case 'site_theme': |
||
246 | if (! empty($value)) { |
||
247 | $theme = Themes::findTheme($value); |
||
248 | if (empty($theme)) { |
||
249 | throw new InvalidArgumentException(__('Could not find the theme.')); |
||
250 | } |
||
251 | } |
||
252 | break; |
||
253 | |||
254 | /* Users Options */ |
||
255 | |||
256 | case 'self_registration': |
||
257 | if (empty($value) || ! in_array($value, ['on', 'off'])) { |
||
258 | throw new InvalidArgumentException(__('Invalid self-registration status.')); |
||
259 | } |
||
260 | break; |
||
261 | case 'new_user_role': |
||
262 | if (empty($value)) { |
||
263 | throw new InvalidArgumentException(__('Invalid new user role.')); |
||
264 | } |
||
265 | break; |
||
266 | case 'new_user_status': |
||
267 | if (empty($value) || ! in_array($value, ['pending', 'activated'])) { |
||
268 | throw new InvalidArgumentException(__('Invalid new user status.')); |
||
269 | } |
||
270 | break; |
||
271 | |||
272 | /* Donors Options */ |
||
273 | |||
274 | case 'default_donor_email_visibility': |
||
275 | if (! empty($value) && ! array_key_exists($value, getVisibilities())) { |
||
276 | throw new InvalidArgumentException(__('Invalid donor e-mail address visibility.')); |
||
277 | } |
||
278 | break; |
||
279 | |||
280 | case 'default_donor_phone_visibility': |
||
281 | if (! empty($value) && ! array_key_exists($value, getVisibilities())) { |
||
282 | throw new InvalidArgumentException(__('Invalid donor phone number visibility.')); |
||
283 | } |
||
284 | break; |
||
285 | |||
286 | /* Reading Options */ |
||
287 | |||
288 | case 'site_publication': |
||
289 | if (empty($value) || ! in_array($value, ['on', 'off'])) { |
||
290 | throw new InvalidArgumentException(__('Invalid site publication status.')); |
||
291 | } |
||
292 | break; |
||
293 | case 'entities_per_page': |
||
294 | if (empty($value) || ! isValidInteger($value) || $value < 1) { |
||
295 | throw new InvalidArgumentException(__('Invalid entities per page count.')); |
||
296 | } |
||
297 | break; |
||
298 | } |
||
299 | return true; |
||
300 | } |
||
302 |