| Conditions | 17 |
| Paths | 384 |
| Total Lines | 57 |
| 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 |
||
| 36 | public function isValid($file, $func, $line) |
||
| 37 | { |
||
| 38 | if (! defined('JSON_ERROR_RECURSION')) { |
||
| 39 | define('JSON_ERROR_RECURSION', 6); |
||
| 40 | } |
||
| 41 | if (! defined('JSON_ERROR_INF_OR_NAN')) { |
||
| 42 | define('JSON_ERROR_INF_OR_NAN', 7); |
||
| 43 | } |
||
| 44 | if (! defined('JSON_ERROR_UNSUPPORTED_TYPE')) { |
||
| 45 | define('JSON_ERROR_UNSUPPORTED_TYPE', 8); |
||
| 46 | } |
||
| 47 | if (! defined('JSON_ERROR_INVALID_PROPERTY_NAME')) { |
||
| 48 | define('JSON_ERROR_INVALID_PROPERTY_NAME', 9); |
||
| 49 | } |
||
| 50 | if (! defined('JSON_ERROR_UTF16')) { |
||
| 51 | define('JSON_ERROR_UTF16', 10); |
||
| 52 | } |
||
| 53 | switch (json_last_error()) { |
||
| 54 | case JSON_ERROR_NONE: |
||
| 55 | return true; |
||
| 56 | case JSON_ERROR_DEPTH: |
||
| 57 | $error = ': Maximum stack depth exceeded'; |
||
| 58 | break; |
||
| 59 | case JSON_ERROR_STATE_MISMATCH: |
||
| 60 | $error = ': Invalid or malformed JSON'; |
||
| 61 | break; |
||
| 62 | case JSON_ERROR_CTRL_CHAR: |
||
| 63 | $error = ': Control character error, possible malformed JSON'; |
||
| 64 | break; |
||
| 65 | case JSON_ERROR_SYNTAX: |
||
| 66 | $error = ': Syntax error, malformed JSON'; |
||
| 67 | break; |
||
| 68 | case JSON_ERROR_UTF8: |
||
| 69 | $error = ': Malformed UTF-8 characters, possible malformed JSON'; |
||
| 70 | break; |
||
| 71 | case JSON_ERROR_RECURSION: |
||
| 72 | $error = ': One or more recursive references in the value to be encoded'; |
||
| 73 | break; |
||
| 74 | case JSON_ERROR_INF_OR_NAN: |
||
| 75 | $error = ': One or more NAN or INF values in the value to be encoded'; |
||
| 76 | break; |
||
| 77 | case JSON_ERROR_UNSUPPORTED_TYPE: |
||
| 78 | $error = ': A value of a type that cannot be encoded was given'; |
||
| 79 | break; |
||
| 80 | case JSON_ERROR_INVALID_PROPERTY_NAME: |
||
| 81 | $error = ': A property name that cannot be encoded was given'; |
||
| 82 | break; |
||
| 83 | case JSON_ERROR_UTF16: |
||
| 84 | $error = ': Malformed UTF-16 characters, possibly incorrectly encoded'; |
||
| 85 | break; |
||
| 86 | default: |
||
| 87 | $error = ': Unknown error'; |
||
| 88 | break; |
||
| 89 | } |
||
| 90 | EE_Error::add_error('JSON decoding failed' . $error, $file, $func, $line); |
||
| 91 | return false; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |