Completed
Push — master ( c8ba67...05deb1 )
by Alejandro
21s queued 12s
created

src/utils/helpers/visits.js   A

Complexity

Total Complexity 9
Complexity/F 3

Size

Lines of Code 59
Function Count 3

Duplication

Duplicated Lines 44
Ratio 74.58 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 9
eloc 41
mnd 6
bc 6
fnc 3
dl 44
loc 59
ccs 24
cts 28
cp 0.8571
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0

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
import { hasValue } from '../utils';
2
3 3
const DEFAULT = 'Others';
4
5 3 View Code Duplication
export const osFromUserAgent = (userAgent) => {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6 632
  if (!hasValue(userAgent)) {
7 591
    return DEFAULT;
8
  }
9
10 41
  const lowerUserAgent = userAgent.toLowerCase();
11
12 41
  switch (true) {
13
    case lowerUserAgent.includes('linux'):
14 3
      return 'Linux';
15
    case lowerUserAgent.includes('windows'):
16 1
      return 'Windows';
17
    case lowerUserAgent.includes('mac'):
18 1
      return 'MacOS';
19
    case lowerUserAgent.includes('mobi'):
20
      return 'Mobile';
21
    default:
22 36
      return DEFAULT;
23
  }
24
};
25
26 3 View Code Duplication
export const browserFromUserAgent = (userAgent) => {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27 632
  if (!hasValue(userAgent)) {
28 591
    return DEFAULT;
29
  }
30
31 41
  const lowerUserAgent = userAgent.toLowerCase();
32
33 41
  switch (true) {
34
    case lowerUserAgent.includes('opera') || lowerUserAgent.includes('opr'):
35 1
      return 'Opera';
36
    case lowerUserAgent.includes('firefox'):
37 2
      return 'Firefox';
38
    case lowerUserAgent.includes('chrome'):
39 2
      return 'Chrome';
40
    case lowerUserAgent.includes('safari'):
41
      return 'Safari';
42
    case lowerUserAgent.includes('edg'):
43
      return 'Microsoft Edge';
44
    case lowerUserAgent.includes('msie'):
45
      return 'Internet Explorer';
46
    default:
47 36
      return DEFAULT;
48
  }
49
};
50
51 3
export const extractDomain = (url) => {
52 632
  if (!hasValue(url)) {
53 548
    return 'Direct';
54
  }
55
56 84
  const domain = url.includes('://') ? url.split('/')[2] : url.split('/')[0];
57
58 84
  return domain.split(':')[0];
59
};
60