| Conditions | 2 |
| Paths | 2 |
| Total Lines | 53 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 34 | public static function getCollection() |
||
| 35 | { |
||
| 36 | $collections = [ |
||
| 37 | JSON_ERROR_NONE => null, |
||
| 38 | JSON_ERROR_DEPTH => [ |
||
| 39 | 'message' => 'Maximum stack depth exceeded', |
||
| 40 | 'error-code' => 1, |
||
| 41 | ], |
||
| 42 | JSON_ERROR_STATE_MISMATCH => [ |
||
| 43 | 'message' => 'Underflow or the modes mismatch', |
||
| 44 | 'error-code' => 2, |
||
| 45 | ], |
||
| 46 | JSON_ERROR_CTRL_CHAR => [ |
||
| 47 | 'message' => 'Unexpected control char found', |
||
| 48 | 'error-code' => 3, |
||
| 49 | ], |
||
| 50 | JSON_ERROR_SYNTAX => [ |
||
| 51 | 'message' => 'Syntax error, malformed JSON', |
||
| 52 | 'error-code' => 4, |
||
| 53 | ], |
||
| 54 | JSON_ERROR_UTF8 => [ |
||
| 55 | 'message' => 'Malformed UTF-8 characters', |
||
| 56 | 'error-code' => 5, |
||
| 57 | ], |
||
| 58 | JSON_ERROR_RECURSION => [ |
||
| 59 | 'message' => 'Recursion error in value to be encoded', |
||
| 60 | 'error-code' => 6, |
||
| 61 | ], |
||
| 62 | JSON_ERROR_INF_OR_NAN => [ |
||
| 63 | 'message' => 'Error NAN/INF in value to be encoded', |
||
| 64 | 'error-code' => 7, |
||
| 65 | ], |
||
| 66 | JSON_ERROR_UNSUPPORTED_TYPE => [ |
||
| 67 | 'message' => 'Type value given cannot be encoded', |
||
| 68 | 'error-code' => 8, |
||
| 69 | ], |
||
| 70 | 'default' => [ |
||
| 71 | 'message' => 'Unknown error', |
||
| 72 | 'error-code' => 999, |
||
| 73 | ], |
||
| 74 | ]; |
||
| 75 | if (version_compare(PHP_VERSION, '7.0.0', '>=')) { |
||
| 76 | $collections[JSON_ERROR_INVALID_PROPERTY_NAME] = [ |
||
| 77 | 'message' => 'Name value given cannot be encoded', |
||
| 78 | 'error-code' => 9, |
||
| 79 | ]; |
||
| 80 | $collections[JSON_ERROR_UTF16] = [ |
||
| 81 | 'message' => 'Malformed UTF-16 characters', |
||
| 82 | 'error-code' => 10, |
||
| 83 | ]; |
||
| 84 | } |
||
| 85 | |||
| 86 | return $collections; |
||
| 87 | } |
||
| 89 |