Completed
Pull Request — master (#230)
by
unknown
04:14 queued 01:51
created

Components/BlockCookieNotification/Partials/AcceptButton/script.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 40
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 7
mnd 1
bc 9
fnc 5
bpm 1.8
cpm 1.4
noi 2

4 Functions

Rating   Name   Duplication   Size   Complexity  
A script.js ➔ checkCookies 0 9 2
A script.js ➔ getOptions 0 6 1
A script.js ➔ acceptCookies 0 9 1
A script.js ➔ getCookieValue 0 9 2
1
import $ from 'jquery'
2
3
export function getOptions (optionContainer) {
0 ignored issues
show
Unused Code introduced by
The parameter optionContainer is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
4
    return {
5
      expireDays: 7,
6
      cookieName: 'cookies_accepted'
7
    }
8
  }
9
10
export function acceptCookies ($container, cookieName, expireDays) {
11
  return function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12
    const date = new Date()
13
    date.setTime(date.getTime() + (expireDays*24*60*60*1000))
14
    document.cookie = cookieName + "=true; expires=" + date.toGMTString()
15
16
    $container.remove()
17
  }
18
}
19
20
export function checkCookies ($container, cookieName) {
21
    const cookiesAccepted = getCookieValue(cookieName)
22
    
23
    if (!cookiesAccepted) {
24
      $container.addClass('cookieNotification-isVisible')
25
    } else {
26
      $container.remove()
27
    }
28
  }
29
30
31
32
function getCookieValue (cookie) {
33
  const value = "; " + document.cookie
34
  const parts = value.split('; ' + cookie + '=')
35
  if (parts.length == 2) {
36
    return parts.pop().split(';').shift()
37
  } else {
38
    return false
39
  }
40
}
41