Completed
Pull Request — master (#244)
by Alejandro
12:02
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 71.43%

Importance

Changes 0
Metric Value
wmc 9
eloc 41
mnd 6
bc 6
fnc 3
dl 44
loc 59
ccs 20
cts 28
cp 0.7143
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 1
const DEFAULT = 'Others';
4
5 1 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 10
  if (!hasValue(userAgent)) {
7
    return DEFAULT;
8
  }
9
10 10
  const lowerUserAgent = userAgent.toLowerCase();
11
12 10
  switch (true) {
13
    case lowerUserAgent.includes('linux'):
14 6
      return 'Linux';
15
    case lowerUserAgent.includes('windows'):
16 2
      return 'Windows';
17
    case lowerUserAgent.includes('mac'):
18 2
      return 'MacOS';
19
    case lowerUserAgent.includes('mobi'):
20
      return 'Mobile';
21
    default:
22
      return DEFAULT;
23
  }
24
};
25
26 1 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 10
  if (!hasValue(userAgent)) {
28
    return DEFAULT;
29
  }
30
31 10
  const lowerUserAgent = userAgent.toLowerCase();
32
33 10
  switch (true) {
34
    case lowerUserAgent.includes('opera') || lowerUserAgent.includes('opr'):
35 2
      return 'Opera';
36
    case lowerUserAgent.includes('firefox'):
37 4
      return 'Firefox';
38
    case lowerUserAgent.includes('chrome'):
39 4
      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
      return DEFAULT;
48
  }
49
};
50
51 1
export const extractDomain = (url) => {
52 10
  if (!hasValue(url)) {
53 4
    return 'Direct';
54
  }
55
56 6
  const domain = url.includes('://') ? url.split('/')[2] : url.split('/')[0];
57
58 6
  return domain.split(':')[0];
59
};
60