node_modules/dns-packet/rcodes.js   A
last analyzed

Complexity

Total Complexity 34
Complexity/F 17

Size

Lines of Code 43
Function Count 2

Duplication

Duplicated Lines 2
Ratio 4.65 %

Importance

Changes 0
Metric Value
cc 0
eloc 38
nc 1
dl 2
loc 43
rs 9.68
c 0
b 0
f 0
wmc 34
mnd 1
bc 2
fnc 2
bpm 1
cpm 17
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
F exports.toRcode 1 21 17

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
/*
2
 * Traditional DNS header RCODEs (4-bits) defined by IANA in
3
 * https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
4
 */
5
6 View Code Duplication
exports.toString = function (rcode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
  switch (rcode) {
8
    case 0: return 'NOERROR'
9
    case 1: return 'FORMERR'
10
    case 2: return 'SERVFAIL'
11
    case 3: return 'NXDOMAIN'
12
    case 4: return 'NOTIMP'
13
    case 5: return 'REFUSED'
14
    case 6: return 'YXDOMAIN'
15
    case 7: return 'YXRRSET'
16
    case 8: return 'NXRRSET'
17
    case 9: return 'NOTAUTH'
18
    case 10: return 'NOTZONE'
19
    case 11: return 'RCODE_11'
20
    case 12: return 'RCODE_12'
21
    case 13: return 'RCODE_13'
22
    case 14: return 'RCODE_14'
23
    case 15: return 'RCODE_15'
24
  }
25
  return 'RCODE_' + rcode
26
}
27
28 View Code Duplication
exports.toRcode = function (code) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
29
  switch (code.toUpperCase()) {
30
    case 'NOERROR': return 0
31
    case 'FORMERR': return 1
32
    case 'SERVFAIL': return 2
33
    case 'NXDOMAIN': return 3
34
    case 'NOTIMP': return 4
35
    case 'REFUSED': return 5
36
    case 'YXDOMAIN': return 6
37
    case 'YXRRSET': return 7
38
    case 'NXRRSET': return 8
39
    case 'NOTAUTH': return 9
40
    case 'NOTZONE': return 10
41
    case 'RCODE_11': return 11
42
    case 'RCODE_12': return 12
43
    case 'RCODE_13': return 13
44
    case 'RCODE_14': return 14
45
    case 'RCODE_15': return 15
46
  }
47
  return 0
48
}
49