| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Lines | 57 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | 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 | /** |
||
| 59 | let test = function test(exercise, test, language, bundle) { |
||
| 60 | return new Promise(function(resolve, reject) { |
||
| 61 | let options = { |
||
| 62 | "method": `POST`, |
||
| 63 | "baseUrl": `https://www.codingame.com`, |
||
| 64 | "uri": `/services/TestSessionRemoteService/play`, |
||
| 65 | "headers": { |
||
| 66 | "Accept": `application/json`, |
||
| 67 | "Content-Type": `application/json;charset=utf-8` |
||
| 68 | }, |
||
| 69 | "body": [ |
||
| 70 | exercise, |
||
| 71 | { |
||
| 72 | "code": bundle, |
||
| 73 | "programmingLanguageId": language, |
||
| 74 | "multipleLanguages": { |
||
| 75 | "testIndex": test |
||
| 76 | } |
||
| 77 | } |
||
| 78 | ], |
||
| 79 | "jar": true, |
||
| 80 | "json": true |
||
| 81 | }; |
||
| 82 | request(options, function(error, response, body) { |
||
| 83 | if (response.statusCode >= 400) { |
||
| 84 | reject(error); |
||
| 85 | } else { |
||
| 86 | let meta = { |
||
| 87 | "exercise": exercise, |
||
| 88 | "test": test, |
||
| 89 | "language": language, |
||
| 90 | "bundle": bundle |
||
| 91 | }; |
||
| 92 | let error = new Error(`Codingame may have changed its API, contact owner of this application.`); |
||
| 93 | Object.assign(error, meta); |
||
| 94 | if (body.success !== undefined) { |
||
| 95 | if (body.success.comparison !== undefined) { |
||
| 96 | if(body.success.comparison.success) { |
||
| 97 | Object.assign(body.success, meta); |
||
| 98 | resolve(body.success); |
||
| 99 | } else { |
||
| 100 | let error = new Error(`Expected <${body.success.comparison.expected}> but found <${body.success.comparison.found}>`); |
||
| 101 | Object.assign(error, meta); |
||
| 102 | reject(error); |
||
| 103 | } |
||
| 104 | } else if (body.success.error !== undefined) { |
||
| 105 | Object.assign(body.success.error, meta); |
||
| 106 | reject(body.success.error); |
||
| 107 | } else { |
||
| 108 | reject(error); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | reject(error); |
||
| 112 | } |
||
| 113 | }); |
||
| 114 | }); |
||
| 115 | }; |
||
| 116 | |||
| 121 |