Conditions | 39 |
Paths | 1392 |
Total Lines | 120 |
Code Lines | 89 |
Lines | 0 |
Ratio | 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 |
||
184 | public static function handleApiException($keyID, $charID, $exception) |
||
185 | { |
||
186 | $code = $exception->getCode(); |
||
187 | $message = $exception->getMessage(); |
||
188 | $clearCharacter = false; |
||
189 | $clearAllCharacters = false; |
||
190 | $clearApiEntry = false; |
||
191 | $updateCacheTime = false; |
||
192 | $demoteCharacter = false; |
||
193 | $cacheUntil = 0; |
||
194 | switch ($code) { |
||
195 | case 28: // Timeouts |
||
196 | case 904: // temp ban from ccp's api server |
||
197 | Db::execute("replace into zz_storage values ('ApiStop904', date_add(now(), interval 5 minute))"); |
||
198 | break; |
||
199 | |||
200 | case 403: |
||
201 | case 502: |
||
202 | case 503: // Service Unavailable - try again later |
||
203 | $cacheUntil = time() + 300; |
||
204 | $updateCacheTime = true; |
||
205 | break; |
||
206 | |||
207 | case 119: // Kills exhausted: retry after [{0}] |
||
208 | $cacheUntil = $exception->cached_until; |
||
209 | $updateCacheTime = true; |
||
210 | break; |
||
211 | |||
212 | case 120: // Expected beforeKillID [{0}] but supplied [{1}]: kills previously loaded. |
||
213 | $cacheUntil = $exception->cached_until; |
||
214 | $updateCacheTime = true; |
||
215 | break; |
||
216 | |||
217 | case 221: // Demote toon, illegal page access |
||
218 | $clearAllCharacters = true; |
||
219 | $clearApiEntry = true; |
||
220 | break; |
||
221 | |||
222 | case 220: |
||
223 | case 200: // Current security level not high enough. |
||
224 | // Typically happens when a key isn't a full API Key |
||
225 | $clearAllCharacters = true; |
||
226 | $clearApiEntry = true; |
||
227 | //$code = 203; // Force it to go away, no point in keeping this key |
||
228 | break; |
||
229 | |||
230 | case 522: |
||
231 | case 201: // Character does not belong to account. |
||
232 | // Typically caused by a character transfer |
||
233 | $clearCharacter = true; |
||
234 | break; |
||
235 | case 207: // Not available for NPC corporations. |
||
236 | case 209: |
||
237 | $demoteCharacter = true; |
||
238 | break; |
||
239 | |||
240 | case 222: // account has expired |
||
241 | $clearAllCharacters = true; |
||
242 | $clearApiEntry = true; |
||
243 | $cacheUntil = time() + (7 * 24 * 3600); // Try again in a week |
||
244 | break; |
||
245 | |||
246 | case 403: |
||
247 | case 211: // Login denied by account status |
||
248 | // Remove characters, will revalidate with next doPopulate |
||
249 | $clearAllCharacters = true; |
||
250 | $clearApiEntry = true; |
||
251 | break; |
||
252 | |||
253 | case 202: // API key authentication failure. |
||
254 | case 203: // Authentication failure - API is no good and will never be good again |
||
255 | case 204: // Authentication failure. |
||
256 | case 205: // Authentication failure (final pass). |
||
257 | case 210: // Authentication failure. |
||
258 | case 521: // Invalid username and/or password passed to UserData.LoginWebUser(). |
||
259 | $clearAllCharacters = true; |
||
260 | $clearApiEntry = true; |
||
261 | break; |
||
262 | |||
263 | case 500: // Internal Server Error (More CCP Issues) |
||
264 | case 520: // Unexpected failure accessing database. (More CCP issues) |
||
265 | case 404: // URL Not Found (CCP having issues...) |
||
266 | case 902: // Eve backend database temporarily disabled |
||
267 | $updateCacheTime = true; |
||
268 | $cacheUntil = time() + 3600; // Try again in an hour... |
||
269 | break; |
||
270 | |||
271 | case 0: // API Date could not be read / parsed, original exception (Something is wrong with the XML and it couldn't be parsed) |
||
272 | default: // try again in 5 minutes |
||
273 | Log::log("$keyID - Unhandled error - Code $code - $message"); |
||
274 | //$updateCacheTime = true; |
||
275 | $clearApiEntry = true; |
||
276 | //$cacheUntil = time() + 300; |
||
277 | break; |
||
278 | } |
||
279 | |||
280 | if ($demoteCharacter && $charID != 0) { |
||
281 | if (false === Db::execute("update zz_api_characters set isDirector = 'F' where characterID = :charID", array(":charID" => $charID), false)) { |
||
282 | $clearCharacter = true; |
||
283 | } |
||
284 | } |
||
285 | |||
286 | if ($clearCharacter && $charID != 0) { |
||
287 | Db::execute("delete from zz_api_characters where keyID = :keyID and characterID = :charID", array(":keyID" => $keyID, ":charID" => $charID)); |
||
288 | } |
||
289 | |||
290 | if ($clearAllCharacters) { |
||
291 | Db::execute("delete from zz_api_characters where keyID = :keyID", array(":keyID" => $keyID)); |
||
292 | } |
||
293 | |||
294 | if ($clearApiEntry) { |
||
295 | Db::execute("update zz_api set errorCode = :code where keyID = :keyID", array(":keyID" => $keyID, ":code" => $code)); |
||
296 | } |
||
297 | |||
298 | if ($updateCacheTime && $cacheUntil != 0 && $charID != 0) { |
||
299 | Db::execute("update zz_api_characters set cachedUntil = :cacheUntil where characterID = :charID", |
||
300 | array(":cacheUntil" => $cacheUntil, ":charID" => $charID)); |
||
301 | } |
||
302 | Db::execute("update zz_api_characters set errorCode = :code where keyID = :keyID and characterID = :charID", array(":keyID" => $keyID, ":charID" => $charID, ":code" => $code)); |
||
303 | } |
||
304 | |||
372 |