app/js/main/bw/auxiliary.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 43
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 24
mnd 2
bc 2
fnc 1
dl 0
loc 43
rs 10
bpm 2
cpm 3
noi 2
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A auxiliary.js ➔ resetUiCounters 0 30 3
1
// jshint esversion: 8
2
3
var debug = require('debug')('main.bw.auxiliary');
4
5
/*
6
  resetUiCounters
7
    Reset bulk whois UI counters to their initial values
8
  parameters
9
    event (object) - renderer object
10
 */
11
function resetUiCounters(event) {
12
  var {
13
    sender
14
  } = event;
15
16
  debug("Resetting bulk whois UI counters");
17
18
  var baseValues = {
19
      integer: 0,
20
      string: '-'
21
    },
22
    events = {
23
      integer: [
24
        'time.current', 'time.remaining', // Timers
25
        'laststatus.available', 'laststatus.unavailable', 'laststatus.error' // Last domain status
26
      ],
27
      string: [
28
        'domains.total', 'domains.waiting', 'domains.sent', 'domains.processed', // Domains
29
        'reqtimes.maximum', 'reqtimes.minimum', 'reqtimes.last', 'reqtimes.average', // Request times
30
        'status.available', 'status.unavailable', 'status.error' // Number stats
31
      ]
32
    },
33
    channel = 'bw:status.update';
34
35
  // Loop through events and send default values
36
  for (var eventType in events)
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
37
    for (var listedEvent in events[eventType])
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
38
      sender.send(channel, events[eventType][listedEvent], baseValues[eventType]);
39
40
}
41
42
module.exports = {
43
  resetUiCounters: resetUiCounters,
44
  rstUiCntrs: resetUiCounters
45
};
46