Total Complexity | 9 |
Complexity/F | 3 |
Lines of Code | 59 |
Function Count | 3 |
Duplicated Lines | 44 |
Ratio | 74.58 % |
Coverage | 85.71% |
Changes | 0 |
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) => { |
|
|||
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) => { |
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 |