Total Complexity | 8 |
Complexity/F | 1.14 |
Lines of Code | 43 |
Function Count | 7 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /* eslint-disable unicorn/filename-case */ |
||
2 | import BaseAPI from 'base-api-client'; |
||
3 | |||
4 | export default class TelegraphAPI extends BaseAPI { |
||
5 | constructor(token) { |
||
6 | super('https://api.telegra.ph'); |
||
7 | this.token = token; |
||
8 | } |
||
9 | |||
10 | onResponse(res) { |
||
11 | return res.data.result; |
||
12 | } |
||
13 | |||
14 | setToken(token) { |
||
15 | this.token = token; |
||
16 | } |
||
17 | |||
18 | _axios(opts) { |
||
19 | // eslint-disable-next-line no-param-reassign |
||
20 | if (opts.method === 'GET') delete opts.data; |
||
|
|||
21 | |||
22 | return super._axios(opts); |
||
23 | } |
||
24 | |||
25 | createAccount(name) { |
||
26 | return this.get('createAccount', { |
||
27 | 'short_name' : name |
||
28 | }); |
||
29 | } |
||
30 | |||
31 | getAccountInfo() { |
||
32 | return this.get('getAccountInfo', { |
||
33 | 'access_token' : this.token |
||
34 | }); |
||
35 | } |
||
36 | |||
37 | createPage(title, content) { |
||
38 | return this.post('createPage', { |
||
39 | 'access_token' : this.token, |
||
40 | title, |
||
41 | content |
||
42 | }); |
||
43 | } |
||
44 | } |
||
45 |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.