Conditions | 7 |
Paths | 7 |
Total Lines | 57 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Tests | 47 |
CRAP Score | 7.0004 |
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 |
||
21 | 2 | public static function validate($value, $parameter, $pointer = null) |
|
22 | { |
||
23 | switch ($parameter) { |
||
24 | 2 | case 'date-time': |
|
25 | 2 | return self::validateRegex( |
|
26 | 2 | $parameter, |
|
27 | 2 | $value, |
|
28 | 2 | self::DATE_TIME_PATTERN, |
|
29 | 2 | ErrorCode::INVALID_DATE_TIME, |
|
30 | $pointer |
||
31 | 2 | ); |
|
32 | 2 | case 'uri': |
|
33 | 2 | return self::validateFilter( |
|
34 | 2 | $parameter, |
|
35 | 2 | $value, |
|
36 | 2 | FILTER_VALIDATE_URL, |
|
37 | 2 | null, |
|
38 | 2 | ErrorCode::INVALID_URI, |
|
39 | $pointer |
||
40 | 2 | ); |
|
41 | 2 | case 'email': |
|
42 | 2 | return self::validateFilter( |
|
43 | 2 | $parameter, |
|
44 | 2 | $value, |
|
45 | 2 | FILTER_VALIDATE_EMAIL, |
|
46 | 2 | null, |
|
47 | 2 | ErrorCode::INVALID_EMAIL, |
|
48 | $pointer |
||
49 | 2 | ); |
|
50 | 2 | case 'ipv4': |
|
51 | 2 | return self::validateFilter( |
|
52 | 2 | $parameter, |
|
53 | 2 | $value, |
|
54 | 2 | FILTER_VALIDATE_IP, |
|
55 | 2 | FILTER_FLAG_IPV4, |
|
56 | 2 | ErrorCode::INVALID_IPV4, |
|
57 | $pointer |
||
58 | 2 | ); |
|
59 | 2 | case 'ipv6': |
|
60 | 2 | return self::validateFilter( |
|
61 | 2 | $parameter, |
|
62 | 2 | $value, |
|
63 | 2 | FILTER_VALIDATE_IP, |
|
64 | 2 | FILTER_FLAG_IPV6, |
|
65 | 2 | ErrorCode::INVALID_IPV6, |
|
66 | $pointer |
||
67 | 2 | ); |
|
68 | 2 | case 'hostname': |
|
69 | 2 | return self::validateRegex( |
|
70 | 2 | $parameter, |
|
71 | 2 | $value, |
|
72 | 2 | self::HOST_NAME_PATTERN, |
|
73 | 2 | ErrorCode::INVALID_HOST_NAME, |
|
74 | $pointer |
||
75 | 2 | ); |
|
76 | } |
||
77 | } |
||
78 | |||
127 |