GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( d3dd5e...6ba014 )
by Christian
05:58
created

src/Resources/public/javascript/gdpr.js   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 96
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 54
nc 1
nop 1
dl 0
loc 96
rs 8.5054
c 1
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B $.fn.gdprCookieLawPopup 0 92 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
(function ($) {
2
  "use strict";
3
4
  $.fn.gdprCookieLawPopup = (function () {
5
    var _self = this;
6
7
    _self.params = {
8
      agreementExpiresInDays: 30,
9
      autoAcceptCookiePolicy: false
10
    };
11
12
    _self.vars = {
13
      INITIALISED: false,
14
      COOKIE_NAME: 'GDPR_COOKIE_LAW_CONSENT'
15
    };
16
17
    // Overwrite default parameters if any of those is present
18
    var parseParameters = function (settings) {
19
      if (settings) {
20
        if (typeof settings.agreementExpiresInDays !== 'undefined') {
21
          _self.params.agreementExpiresInDays = settings.agreementExpiresInDays;
22
        }
23
        if (typeof settings.autoAcceptCookiePolicy !== 'undefined') {
24
          _self.params.autoAcceptCookiePolicy = settings.autoAcceptCookiePolicy;
25
        }
26
      }
27
    };
28
29
    // Storing the consent in a cookie
30
    var setUserAcceptsCookies = function (consent) {
31
      var d = new Date();
32
      var expiresInDays = _self.params.agreementExpiresInDays * 24 * 60 * 60 * 1000;
33
      d.setTime(d.getTime() + expiresInDays);
34
      var expires = "expires=" + d.toGMTString();
35
      document.cookie = _self.vars.COOKIE_NAME + '=' + consent + "; " + expires + ";path=/";
36
    };
37
38
    // Let's see if we have a consent cookie already
39
    var userAlreadyAcceptedCookies = function () {
40
      var userAcceptedCookies = false;
41
      var cookies = document.cookie.split(";");
42
      for (var i = 0; i < cookies.length; i++) {
43
        var c = cookies[i].trim();
44
        if (c.indexOf(_self.vars.COOKIE_NAME) == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing c.indexOf(_self.vars.COOKIE_NAME) to 0 using the == operator is not safe. Consider using === instead.
Loading history...
45
          userAcceptedCookies = c.substring(_self.vars.COOKIE_NAME.length + 1, c.length);
46
        }
47
      }
48
49
      return userAcceptedCookies;
50
    };
51
52
    var hideContainer = function () {
53
      $('.gdprpopup-container').animate({
54
        opacity: 0,
55
        height: 0
56
      }, 200, function () {
57
        $('.gdprpopup-container').hide(0);
58
      });
59
    };
60
61
    return {
62
      init: function (settings) {
63
        parseParameters(settings);
64
65
        // No need to display this if user already accepted the policy
66
        if (userAlreadyAcceptedCookies()) {
67
          return;
68
        }
69
70
        // We should initialise only once
71
        if (_self.vars.INITIALISED) {
72
          return;
73
        }
74
        _self.vars.INITIALISED = true;
75
76
        $('.gdprpopup-button-confirm').click(function () {
77
          setUserAcceptsCookies(true);
78
          hideContainer();
79
          return false;
80
        });
81
        $('.gdprpopup-closebutton').click(function () {
82
          hideContainer();
83
          return false;
84
        });
85
86
        // Ready to start!
87
        $('.gdprpopup-container').show();
88
89
        // In case it's alright to just display the message once
90
        if (_self.params.autoAcceptCookiePolicy) {
91
          setUserAcceptsCookies(true);
92
        }
93
      }
94
    };
95
  });
96
}(jQuery));
97
98
99
$(function () {
100
  $(document).gdprCookieLawPopup().init();
101
});
102