| Conditions | 25 |
| Paths | 25 |
| Total Lines | 40 |
| Code Lines | 37 |
| 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 |
||
| 28 | public static function validationError($format, $data) |
||
| 29 | { |
||
| 30 | switch ($format) { |
||
| 31 | case 'date-time': |
||
| 32 | return self::dateTimeError($data); |
||
| 33 | case 'date': |
||
| 34 | return preg_match('/^' . self::DATE_REGEX_PART . '$/i', $data) ? null : 'Invalid date'; |
||
| 35 | case 'time': |
||
| 36 | return preg_match('/^' . self::TIME_REGEX_PART . '$/i', $data) ? null : 'Invalid time'; |
||
| 37 | case 'uri': |
||
| 38 | return Uri::validationError($data, Uri::IS_SCHEME_REQUIRED); |
||
| 39 | case 'iri': |
||
| 40 | return Iri::validationError($data); |
||
| 41 | case 'email': |
||
| 42 | return filter_var($data, FILTER_VALIDATE_EMAIL) ? null : 'Invalid email'; |
||
| 43 | case 'idn-email': |
||
| 44 | return count(explode('@', $data, 3)) === 2 ? null : 'Invalid email'; |
||
| 45 | case 'ipv4': |
||
| 46 | return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? null : 'Invalid ipv4'; |
||
| 47 | case 'ipv6': |
||
| 48 | return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? null : 'Invalid ipv6'; |
||
| 49 | case 'hostname': |
||
| 50 | return preg_match(self::HOSTNAME_REGEX, $data) ? null : 'Invalid hostname'; |
||
| 51 | case 'idn-hostname': |
||
| 52 | return IdnHostname::validationError($data); |
||
| 53 | case 'regex': |
||
| 54 | return self::regexError($data); |
||
| 55 | case 'json-pointer': |
||
| 56 | return self::jsonPointerError($data); |
||
| 57 | case 'relative-json-pointer': |
||
| 58 | return self::jsonPointerError($data, true); |
||
| 59 | case 'uri-reference': |
||
| 60 | return Uri::validationError($data, Uri::IS_URI_REFERENCE); |
||
| 61 | case 'iri-reference': |
||
| 62 | return Iri::validationError($data, Uri::IS_URI_REFERENCE); |
||
| 63 | case 'uri-template': |
||
| 64 | return Uri::validationError($data, Uri::IS_URI_TEMPLATE); |
||
| 65 | } |
||
| 66 | return null; |
||
| 67 | } |
||
| 68 | |||
| 107 | } |