GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 137f54...278f6d )
by Florian
01:11
created

Url.parseMarkers   C

Complexity

Conditions 10
Paths 12

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
c 1
b 0
f 0
nc 12
nop 1
dl 0
loc 51
rs 6

How to fix   Long Method    Complexity   

Long Method

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:

Complexity

Complex classes like Url.parseMarkers often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/*jslint
2
  indent: 4
3
*/
4
/*global
5
  google, window,
6
  App, Coordinates,
7
  alpha2id
8
*/
9
10
var Url = {};
11
12
Url.getParams = function () {
13
    'use strict';
14
15
    var params = {},
16
        splitted = window.location.search.substr(1).split('&'),
17
        i,
18
        p;
19
20
    for (i = 0; i < splitted.length; i += 1) {
21
        p = splitted[i].split('=', 2);
22
        if (p[0] !== "") {
23
            if (p.length === 1) {
24
                params[p[0]] = "";
25
            } else {
26
                params[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
27
            }
28
        }
29
    }
30
31
    return params;
32
};
33
34
Url.parseMarkers = function (urlarg) {
35
    'use strict';
36
37
    if (!urlarg) {
38
        return [];
39
    }
40
41
    var data;
42
43
    // ID:COODRS:R(:NAME)?|ID:COORDS:R(:NAME)?
44
    // COORDS=LAT:LON or DEG or DMMM
45
    if (urlarg.indexOf("*") >= 0) {
46
        data = urlarg.split('*');
47
    } else {
48
        /* sep is '|' */
49
        data = urlarg.split('|');
50
    }
51
52
    return data.map(function (dataitem) {
53
        dataitem = dataitem.split(':');
54
        if (dataitem.length < 3 || dataitem.length > 6) {
55
            return null;
56
        }
57
58
        var m = {
59
                alpha: dataitem[0],
60
                id: alpha2id(dataitem[0]),
61
                name: null,
62
                coords: null,
63
                r: 0,
64
                color: ""
65
            },
66
            index = 1,
67
            lat,
68
            lon;
69
70
        if (m.id < 0) {
71
            return null;
72
        }
73
74
        lat = parseFloat(dataitem[index]);
75
        lon = parseFloat(dataitem[index + 1]);
76
        if (Coordinates.valid(lat, lon)) {
77
            index += 2;
78
            m.coords = new google.maps.LatLng(lat, lon);
79
        } else {
80
            m.coords = Coordinates.fromString(dataitem[index]);
81
            index += 1;
82
        }
83
        if (!m.coords) {
84
            return null;
85
        }
86
87
        m.r = App.repairRadius(parseFloat(dataitem[index]), 0);
88
        index = index + 1;
89
90
        if (index < dataitem.length &&
91
                (/^([a-zA-Z0-9\-_]*)$/).test(dataitem[index])) {
92
            m.name = dataitem[index];
93
        }
94
95
        index = index + 1;
96
        if (index < dataitem.length &&
97
                (/^([a-fA-F0-9]{6})$/).test(dataitem[index])) {
98
            m.color = dataitem[index];
99
        }
100
101
        return m;
102
    }).filter(function (thing) {
103
        return thing !== null;
104
    });
105
};
106
107
108
Url.parseCenter = function (urlarg) {
109
    'use strict';
110
111
    if (!urlarg) {
112
        return null;
113
    }
114
115
    var data = urlarg.split(':');
116
117
    if (data.length === 1) {
118
        return Coordinates.fromString(data[0]);
119
    }
120
121
    if (data.length === 2) {
122
        return Coordinates.toLatLng(parseFloat(data[0]), parseFloat(data[1]));
123
    }
124
125
    return null;
126
};
127
128
129
Url.parseLines = function (urlarg) {
130
    'use strict';
131
132
    if (!urlarg) {
133
        return [];
134
    }
135
136
    /* be backwards compatible */
137
    if (urlarg.length === 3
138
            && alpha2id(urlarg[0]) >= 0
139
            && urlarg[1] === '*'
140
            && alpha2id(urlarg[1]) >= 0) {
141
        urlarg = urlarg[0] + ':' + urlarg[2];
142
    }
143
144
    return urlarg.split('*').map(function (pair_string) {
145
        var pair = pair_string.split(':');
146
        if (pair.length === 2) {
147
            return {source: alpha2id(pair[0]), target: alpha2id(pair[1])};
148
        }
149
        return null;
150
    }).filter(function (thing) {
151
        return (thing !== null);
152
    });
153
};
154