Conditions | 36 |
Paths | 344 |
Total Lines | 78 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
69 | public static function create(FacebookResponse $response) |
||
70 | { |
||
71 | $data = $response->getDecodedBody(); |
||
72 | |||
73 | if (!isset($data['error']['code']) && isset($data['code'])) { |
||
74 | $data = ['error' => $data]; |
||
75 | } |
||
76 | |||
77 | $code = isset($data['error']['code']) ? $data['error']['code'] : null; |
||
78 | $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.'; |
||
79 | |||
80 | if (isset($data['error']['error_subcode'])) { |
||
81 | switch ($data['error']['error_subcode']) { |
||
82 | // Other authentication issues |
||
83 | case 458: |
||
84 | case 459: |
||
85 | case 460: |
||
86 | case 463: |
||
87 | case 464: |
||
88 | case 467: |
||
89 | return new static($response, new FacebookAuthenticationException($message, $code)); |
||
90 | // Video upload resumable error |
||
91 | case 1363030: |
||
92 | case 1363019: |
||
93 | case 1363033: |
||
94 | case 1363021: |
||
95 | case 1363041: |
||
96 | return new static($response, new FacebookResumableUploadException($message, $code)); |
||
97 | case 1363037: |
||
98 | $previousException = new FacebookResumableUploadException($message, $code); |
||
99 | |||
100 | $startOffset = isset($data['error']['error_data']['start_offset']) ? (int) $data['error']['error_data']['start_offset'] : null; |
||
101 | $previousException->setStartOffset($startOffset); |
||
102 | |||
103 | $endOffset = isset($data['error']['error_data']['end_offset']) ? (int) $data['error']['error_data']['end_offset'] : null; |
||
104 | $previousException->setEndOffset($endOffset); |
||
105 | |||
106 | return new static($response, $previousException); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | switch ($code) { |
||
111 | // Login status or token expired, revoked, or invalid |
||
112 | case 100: |
||
113 | case 102: |
||
114 | case 190: |
||
115 | return new static($response, new FacebookAuthenticationException($message, $code)); |
||
116 | |||
117 | // Server issue, possible downtime |
||
118 | case 1: |
||
119 | case 2: |
||
120 | return new static($response, new FacebookServerException($message, $code)); |
||
121 | |||
122 | // API Throttling |
||
123 | case 4: |
||
124 | case 17: |
||
125 | case 32: |
||
126 | case 341: |
||
127 | case 613: |
||
128 | return new static($response, new FacebookThrottleException($message, $code)); |
||
129 | |||
130 | // Duplicate Post |
||
131 | case 506: |
||
132 | return new static($response, new FacebookClientException($message, $code)); |
||
133 | } |
||
134 | |||
135 | // Missing Permissions |
||
136 | if ($code == 10 || ($code >= 200 && $code <= 299)) { |
||
137 | return new static($response, new FacebookAuthorizationException($message, $code)); |
||
138 | } |
||
139 | |||
140 | // OAuth authentication error |
||
141 | if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') { |
||
142 | return new static($response, new FacebookAuthenticationException($message, $code)); |
||
143 | } |
||
144 | |||
145 | // All others |
||
146 | return new static($response, new FacebookOtherException($message, $code)); |
||
147 | } |
||
226 |