| Conditions | 36 |
| Paths | 344 |
| Total Lines | 78 |
| Code Lines | 48 |
| 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 |
||
| 48 | public static function create(InstagramResponse $response) |
||
| 49 | { |
||
| 50 | $data = $response->getDecodedBody(); |
||
| 51 | |||
| 52 | if (!isset($data['error']['code']) && isset($data['code'])) { |
||
| 53 | $data = ['error' => $data]; |
||
| 54 | } |
||
| 55 | |||
| 56 | $code = isset($data['error']['code']) ? $data['error']['code'] : null; |
||
| 57 | $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.'; |
||
| 58 | |||
| 59 | if (isset($data['error']['error_subcode'])) { |
||
| 60 | switch ($data['error']['error_subcode']) { |
||
| 61 | // Other authentication issues |
||
| 62 | case 458: |
||
| 63 | case 459: |
||
| 64 | case 460: |
||
| 65 | case 463: |
||
| 66 | case 464: |
||
| 67 | case 467: |
||
| 68 | return new static($response, new InstagramAuthenticationException($message, $code)); |
||
| 69 | // Video upload resumable error |
||
| 70 | case 1363030: |
||
| 71 | case 1363019: |
||
| 72 | case 1363033: |
||
| 73 | case 1363021: |
||
| 74 | case 1363041: |
||
| 75 | return new static($response, new InstagramResumableUploadException($message, $code)); |
||
| 76 | case 1363037: |
||
| 77 | $previousException = new InstagramResumableUploadException($message, $code); |
||
| 78 | |||
| 79 | $startOffset = isset($data['error']['error_data']['start_offset']) ? (int) $data['error']['error_data']['start_offset'] : null; |
||
| 80 | $previousException->setStartOffset($startOffset); |
||
| 81 | |||
| 82 | $endOffset = isset($data['error']['error_data']['end_offset']) ? (int) $data['error']['error_data']['end_offset'] : null; |
||
| 83 | $previousException->setEndOffset($endOffset); |
||
| 84 | |||
| 85 | return new static($response, $previousException); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | switch ($code) { |
||
| 90 | // Login status or token expired, revoked, or invalid |
||
| 91 | case 100: |
||
| 92 | case 102: |
||
| 93 | case 190: |
||
| 94 | return new static($response, new InstagramAuthenticationException($message, $code)); |
||
| 95 | |||
| 96 | // Server issue, possible downtime |
||
| 97 | case 1: |
||
| 98 | case 2: |
||
| 99 | return new static($response, new InstagramServerException($message, $code)); |
||
| 100 | |||
| 101 | // API Throttling |
||
| 102 | case 4: |
||
| 103 | case 17: |
||
| 104 | case 32: |
||
| 105 | case 341: |
||
| 106 | case 613: |
||
| 107 | return new static($response, new InstagramThrottleException($message, $code)); |
||
| 108 | |||
| 109 | // Duplicate Post |
||
| 110 | case 506: |
||
| 111 | return new static($response, new InstagramClientException($message, $code)); |
||
| 112 | } |
||
| 113 | |||
| 114 | // Missing Permissions |
||
| 115 | if ($code == 10 || ($code >= 200 && $code <= 299)) { |
||
| 116 | return new static($response, new InstagramAuthorizationException($message, $code)); |
||
| 117 | } |
||
| 118 | |||
| 119 | // OAuth authentication error |
||
| 120 | if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') { |
||
| 121 | return new static($response, new InstagramAuthenticationException($message, $code)); |
||
| 122 | } |
||
| 123 | |||
| 124 | // All others |
||
| 125 | return new static($response, new InstagramOtherException($message, $code)); |
||
| 126 | } |
||
| 205 |