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 ( 63b87e...4f9b41 )
by Florian
01:14
created

js/markers.js   B

Complexity

Total Complexity 52
Complexity/F 1.41

Size

Lines of Code 357
Function Count 37

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
cc 0
c 5
b 1
f 1
nc 2
dl 0
loc 357
rs 7.9487
wmc 52
mnd 2
bc 51
fnc 37
bpm 1.3783
cpm 1.4054
noi 0

29 Functions

Rating   Name   Duplication   Size   Complexity  
A Markers.update 0 9 1
A Marker.getPosition 0 5 1
A Marker.setNamePositionRadius 0 9 1
A Marker.isFree 0 5 1
A Markers.getById 0 9 3
A Marker.toString 0 5 1
A Marker.clear 0 18 2
A Markers.center 0 10 2
A Markers.saveMarkersList 0 13 1
A Markers.getUsedMarkers 0 11 1
A Marker.getId 0 5 1
A Marker.getRadius 0 5 1
A Markers.getFreeMarkers 0 5 1
A Markers.removeById 0 5 1
A Markers.handleMarkerCleared 0 9 2
A Marker.setPosition 0 7 1
B Marker.initialize 0 40 1
A Marker.setName 0 6 1
A Marker.update 0 22 2
A Markers.getNextUsedId 0 12 3
A Markers.goto 0 10 2
A Marker.setRadius 0 6 1
A Marker.getName 0 5 1
A Markers.deleteAll 0 9 1
A Markers.getSize 0 5 1
A Markers.toString 0 13 1
A markers.js ➔ Markers 0 11 2
A Markers.getFreeId 0 12 3
A Marker.getAlpha 0 5 1

How to fix   Complexity   

Complexity

Complex classes like js/markers.js 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
5
/*global
6
  $, Lines, google, Cookies, Coordinates, trackMarker,
7
  id2alpha, alpha2id
8
*/
9
10
/// Marker
11
12
function Marker(parent, id) {
13
    'use strict';
14
15
    this.m_parent = parent;
16
    this.m_id = id;
17
    this.m_alpha = id2alpha(id);
18
    this.m_free = true;
19
    this.m_name = "";
20
    this.m_marker = null;
21
    this.m_circle = null;
22
}
23
24
25
Marker.prototype.toString = function () {
26
    'use strict';
27
28
    return this.getAlpha() + ":" + this.getPosition().lat().toFixed(6) + ":" + this.getPosition().lng().toFixed(6) + ":" + this.getRadius() + ":" + this.getName();
29
};
30
31
32
Marker.prototype.isFree = function () {
33
    'use strict';
34
35
    return this.m_free;
36
};
37
38
39
Marker.prototype.clear = function () {
40
    'use strict';
41
42
    if (this.m_free) {
43
        return;
44
    }
45
46
    this.m_free = true;
47
    this.m_marker.setMap(null);
48
    this.m_marker = null;
49
    this.m_circle.setMap(null);
50
    this.m_circle = null;
51
52
    $('#dyn' + this.m_id).remove();
53
54
    Lines.updateLinesMarkerRemoved(this.m_id);
55
    this.m_parent.handleMarkerCleared();
56
};
57
58
59
Marker.prototype.getId = function () {
60
    'use strict';
61
62
    return this.m_id;
63
};
64
65
66
Marker.prototype.getAlpha = function () {
67
    'use strict';
68
69
    return this.m_alpha;
70
};
71
72
73
Marker.prototype.getName = function () {
74
    'use strict';
75
76
    return this.m_name;
77
};
78
79
80
Marker.prototype.setName = function (name) {
81
    'use strict';
82
83
    this.m_name = name;
84
    this.update();
85
};
86
87
88
Marker.prototype.setPosition = function (position) {
89
    'use strict';
90
91
    this.m_marker.setPosition(position);
92
    this.m_circle.setCenter(position);
93
    this.update();
94
};
95
96
97
Marker.prototype.getPosition = function () {
98
    'use strict';
99
100
    return this.m_marker.getPosition();
101
};
102
103
104
Marker.prototype.setRadius = function (radius) {
105
    'use strict';
106
107
    this.m_circle.setRadius(radius);
108
    this.update();
109
};
110
111
112
Marker.prototype.getRadius = function () {
113
    'use strict';
114
115
    return this.m_circle.getRadius();
116
};
117
118
119
Marker.prototype.setNamePositionRadius = function (name, position, radius) {
120
    'use strict';
121
122
    this.m_name = name;
123
    this.m_marker.setPosition(position);
124
    this.m_circle.setCenter(position);
125
    this.m_circle.setRadius(radius);
126
    this.update();
127
};
128
129
130
Marker.prototype.initialize = function (map, name, position, radius) {
131
    'use strict';
132
133
    this.m_free = false;
134
    this.m_name = name;
135
136
    // marker.png is 26x10 icons (each: 33px x 37px)
137
    var self = this,
138
        iconw = 33,
139
        iconh = 37,
140
        offsetx = (this.m_id % 26) * iconw,
141
        offsety = Math.floor(this.m_id / 26) * iconh,
142
        color = "#0090ff";
143
144
    this.m_marker = new google.maps.Marker({
145
        position: position,
146
        map: map,
147
        icon: new google.maps.MarkerImage(
148
            "img/markers.png",
149
            new google.maps.Size(iconw, iconh),
150
            new google.maps.Point(offsetx, offsety),
151
            new google.maps.Point(0.5 * iconw, iconh - 1)
152
        ),
153
        draggable: true
154
    });
155
156
    google.maps.event.addListener(this.m_marker, "drag", function () { self.update(); });
157
    google.maps.event.addListener(this.m_marker, "dragend", function () { self.update(); });
158
159
    this.m_circle = new google.maps.Circle({
160
        center: position,
161
        map: map,
162
        strokeColor: color,
163
        strokeOpacity: 1,
164
        fillColor: color,
165
        fillOpacity: 0.25,
166
        strokeWeight: 1,
167
        radius: radius
168
    });
169
};
170
171
172
Marker.prototype.update = function () {
173
    'use strict';
174
175
    if (this.m_free) {
176
        return;
177
    }
178
179
    var pos = this.m_marker.getPosition(),
180
        radius = this.m_circle.getRadius();
181
182
    this.m_circle.setCenter(pos);
183
184
    Cookies.set('marker' + this.m_id, pos.lat().toFixed(6) + ":" + pos.lng().toFixed(6) + ":" + radius + ":" + this.m_name, {expires: 30});
185
    $('#view_name' + this.m_alpha).html(this.m_name);
186
    $('#view_coordinates' + this.m_alpha).html(Coordinates.toString(pos));
187
    $('#view_circle' + this.m_alpha).html(radius);
188
    $('#edit_name' + this.m_alpha).val(this.m_name);
189
    $('#edit_coordinates' + this.m_alpha).val(Coordinates.toString(pos));
190
    $('#edit_circle' + this.m_alpha).val(radius);
191
192
    Lines.updateLinesMarkerMoved(this.m_id);
193
};
194
195
196
/// Markers
197
198
var Markers = function () {
199
    'use strict';
200
201
    var id;
202
203
    this.m_markers = new Array(26 * 10);
204
205
    for (id = 0; id !== this.m_markers.length; id = id + 1) {
206
        this.m_markers[id] = new Marker(this, id);
207
    }
208
};
209
210
211
Markers.prototype.getSize = function () {
212
    'use strict';
213
214
    return this.m_markers.length;
215
};
216
217
218
Markers.prototype.getById = function (id) {
219
    'use strict';
220
221
    if (id < 0 || id >= this.m_markers.length) {
222
        return null;
223
    }
224
225
    return this.m_markers[id];
226
};
227
228
229
Markers.prototype.getUsedMarkers = function () {
230
    'use strict';
231
232
    var count = 0;
233
    this.m_markers.map(function (m) {
234
        if (!m.isFree()) {
235
            count = count + 1;
236
        }
237
    });
238
    return count;
239
};
240
241
242
Markers.prototype.getFreeMarkers = function () {
243
    'use strict';
244
245
    return this.getSize() - this.getUsedMarkers();
246
};
247
248
249
Markers.prototype.getFreeId = function () {
250
    'use strict';
251
252
    var id;
253
254
    for (id = 0; id < this.m_markers.length; id = id + 1) {
255
        if (this.m_markers[id].isFree()) {
256
            return id;
257
        }
258
    }
259
    return -1;
260
};
261
262
263
Markers.prototype.getNextUsedId = function (id) {
264
    'use strict';
265
266
    var i;
267
268
    for (i = id + 1; i < this.m_markers.length; i = i + 1) {
269
        if (!this.m_markers[i].isFree()) {
270
            return i;
271
        }
272
    }
273
    return -1;
274
};
275
276
277
Markers.prototype.removeById = function (id) {
278
    'use strict';
279
280
    this.m_markers[id].clear();
281
};
282
283
284
Markers.prototype.deleteAll = function () {
285
    'use strict';
286
287
    this.m_markers.map(
288
        function (m) {
289
            m.clear();
290
        }
291
    );
292
};
293
294
295
Markers.prototype.saveMarkersList = function () {
296
    'use strict';
297
298
    var ids = [];
299
    this.m_markers.map(
300
        function (m) {
301
            if (!m.isFree()) {
302
                ids.push(m.getId());
303
            }
304
        }
305
    );
306
    Cookies.set('markers', ids.join(":"), {expires: 30});
307
};
308
309
310
Markers.prototype.toString = function () {
311
    'use strict';
312
313
    var parts = [];
314
    this.m_markers.map(
315
        function (m) {
316
            if (!m.isFree()) {
317
                parts.push(m.toString());
318
            }
319
        }
320
    );
321
    return parts.join("*");
322
};
323
324
325
Markers.prototype.update = function () {
326
    'use strict';
327
328
    this.m_markers.map(
329
        function (m) {
330
            m.update();
331
        }
332
    );
333
};
334
335
336
Markers.prototype.handleMarkerCleared = function () {
337
    'use strict';
338
339
    if (this.getUsedMarkers() === 0) {
340
        $('#btnmarkers2').hide();
341
    }
342
343
    this.saveMarkersList();
344
};
345
346
347
Markers.prototype.goto = function (id) {
348
    'use strict';
349
350
    trackMarker('goto');
351
352
    var m = this.getById(id);
353
    if (m) {
354
        this.m_map.setCenter(m.getPosition());
355
    }
356
};
357
358
359
Markers.prototype.center = function (id) {
360
    'use strict';
361
362
    trackMarker('center');
363
364
    var m = this.getById(id);
365
    if (m) {
366
        m.setPosition(this.m_map.getCenter());
367
    }
368
};
369