| Conditions | 32 |
| Paths | 288 |
| Total Lines | 67 |
| Code Lines | 40 |
| 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 |
||
| 68 | public static function create(Response $response) |
||
| 69 | { |
||
| 70 | $data = $response->getDecodedBody(); |
||
| 71 | |||
| 72 | if (!isset($data['error']['code']) && isset($data['code'])) { |
||
| 73 | $data = ['error' => $data]; |
||
| 74 | } |
||
| 75 | |||
| 76 | $code = isset($data['error']['code']) ? $data['error']['code'] : null; |
||
| 77 | $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.'; |
||
| 78 | |||
| 79 | if (isset($data['error']['error_subcode'])) { |
||
| 80 | switch ($data['error']['error_subcode']) { |
||
| 81 | // Other authentication issues |
||
| 82 | case 458: |
||
| 83 | case 459: |
||
| 84 | case 460: |
||
| 85 | case 463: |
||
| 86 | case 464: |
||
| 87 | case 467: |
||
| 88 | return new static($response, new AuthenticationException($message, $code)); |
||
| 89 | // Video upload resumable error |
||
| 90 | case 1363030: |
||
| 91 | case 1363019: |
||
| 92 | case 1363037: |
||
| 93 | case 1363033: |
||
| 94 | case 1363021: |
||
| 95 | case 1363041: |
||
| 96 | return new static($response, new ResumableUploadException($message, $code)); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | switch ($code) { |
||
| 101 | // Login status or token expired, revoked, or invalid |
||
| 102 | case 100: |
||
| 103 | case 102: |
||
| 104 | case 190: |
||
| 105 | return new static($response, new AuthenticationException($message, $code)); |
||
| 106 | |||
| 107 | // Server issue, possible downtime |
||
| 108 | case 1: |
||
| 109 | case 2: |
||
| 110 | return new static($response, new ServerException($message, $code)); |
||
| 111 | |||
| 112 | // API Throttling |
||
| 113 | case 4: |
||
| 114 | case 17: |
||
| 115 | case 341: |
||
| 116 | return new static($response, new ThrottleException($message, $code)); |
||
| 117 | |||
| 118 | // Duplicate Post |
||
| 119 | case 506: |
||
| 120 | return new static($response, new ClientException($message, $code)); |
||
| 121 | } |
||
| 122 | |||
| 123 | // Missing Permissions |
||
| 124 | if ($code == 10 || ($code >= 200 && $code <= 299)) { |
||
| 125 | return new static($response, new AuthorizationException($message, $code)); |
||
| 126 | } |
||
| 127 | |||
| 128 | // OAuth authentication error |
||
| 129 | if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') { |
||
| 130 | return new static($response, new AuthenticationException($message, $code)); |
||
| 131 | } |
||
| 132 | |||
| 133 | // All others |
||
| 134 | return new static($response, new OtherException($message, $code)); |
||
| 135 | } |
||
| 214 |