es/mastery.js   A
last analyzed

Complexity

Total Complexity 19
Complexity/F 1.46

Size

Lines of Code 69
Function Count 13

Duplication

Duplicated Lines 69
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 69
loc 69
rs 10
wmc 19
mnd 2
bc 21
fnc 13
bpm 1.6153
cpm 1.4615
noi 2

6 Functions

Rating   Name   Duplication   Size   Complexity  
B SummonerMastery.champion 27 27 2
A mastery.js ➔ SummonerMastery 5 5 1
A SummonerMastery.top 9 9 2
A SummonerMastery.level 12 12 1
A SummonerMastery.constructor 67 67 1
A SummonerMastery.points 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
import { getJSON, getRegion } from './utils';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
var SummonerMastery = /** @class */ (function () {
3
    function SummonerMastery(APIKEY, region, summonerId) {
4
        this.summonerId = summonerId;
5
        this.APIKEY = APIKEY;
6
        this.region = region;
7
    }
8
    SummonerMastery.prototype.level = function (callback) {
9
        var url = getRegion(this.region) + "/lol/champion-mastery/v3/scores/by-summoner/"
10
            + (this.summonerId + "?api_key=" + this.APIKEY);
11
        getJSON(url, function (res, err) {
12
            if (err) {
13
                callback(null, err);
14
            }
15
            else {
16
                callback(res.data);
17
            }
18
        });
19
    };
20
    SummonerMastery.prototype.points = function (callback) {
21
        var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
22
            + (this.summonerId + "?api_key=" + this.APIKEY);
23
        getJSON(url, function (res) {
24
            var points = 0;
25
            res.data.forEach(function (champion) {
26
                points += champion.championPoints;
27
            });
28
            callback(points);
29
        });
30
    };
31
    SummonerMastery.prototype.top = function (amount, callback) {
32
        if (amount === void 0) { amount = 0; }
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
33
        var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
34
            + (this.summonerId + "?api_key=" + this.APIKEY);
35
        getJSON(url, function (res) {
36
            var slice = amount === 0 ? res.data.length : amount;
37
            callback(res.data.slice(0, slice));
38
        });
39
    };
40
    SummonerMastery.prototype.champion = function (champion, callback) {
41
        if (Array.isArray(champion)) {
42
            var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
43
                + (this.summonerId + "?api_key=" + this.APIKEY);
44
            var returner_1 = [];
45
            getJSON(url, function (res) {
46
                res.data.forEach(function (element) {
47
                    if (champion.indexOf(element.championId) !== -1) {
48
                        returner_1.push(element);
49
                    }
50
                });
51
                callback(returner_1);
52
            });
53
        }
54
        else {
55
            var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable url already seems to be declared on line 42. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
56
                + (this.summonerId + "/by-champion/" + champion + "?api_key=" + this.APIKEY);
57
            getJSON(url, function (res, err) {
58
                if (err) {
59
                    callback(null, err);
60
                }
61
                else {
62
                    callback(res.data);
63
                }
64
            });
65
        }
66
    };
67
    return SummonerMastery;
68
}());
69
export { SummonerMastery };
70
//# sourceMappingURL=mastery.js.map