ImpressCMS/impresscms

View on GitHub
htdocs/themes/reflex/js/cookie.js

Summary

Maintainability
B
5 hrs
Test Coverage

Function cookie has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
Severity: Minor
Found in htdocs/themes/reflex/js/cookie.js - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function cookie has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
Severity: Minor
Found in htdocs/themes/reflex/js/cookie.js - About 1 hr to fix

    Unexpected spaces found.
    Open

                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE

    Unexpected spaces found.
    Open

            // in the packed version for some reason...

    Unexpected spaces found.
    Open

            if (document.cookie && document.cookie != '') {

    Unexpected spaces found.
    Open

                var cookies = document.cookie.split(';');

    Unexpected spaces found.
    Open

            if (value === null) {

    Unexpected spaces found.
    Open

            return cookieValue;

    Unexpected spaces found.
    Open

                    // Does this cookie string begin with the name we want?

    Unexpected spaces found.
    Open

            var path = options.path ? '; path=' + (options.path) : '';

    Unexpected spaces found.
    Open

            var domain = options.domain ? '; domain=' + (options.domain) : '';

    Unexpected spaces found.
    Open

                    var cookie = jQuery.trim(cookies[i]);

    Unexpected spaces found.
    Open

        }

    Unexpected spaces found.
    Open

            var expires = '';

    Unexpected spaces found.
    Open

                } else {

    Unexpected spaces found.
    Open

                for (var i = 0; i < cookies.length; i++) {

    Unexpected spaces found.
    Open

            options = options || {};

    Unexpected spaces found.
    Open

                var date;

    Unexpected spaces found.
    Open

                }

    Unexpected spaces found.
    Open

                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));

    Unexpected spaces found.
    Open

                    }

    Unexpected spaces found.
    Open

                }

    Unexpected spaces found.
    Open

                value = '';

    Unexpected spaces found.
    Open

            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {

    Unexpected spaces found.
    Open

                    date = new Date();

    Unexpected spaces found.
    Open

            }

    Unexpected spaces found.
    Open

                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));

    Unexpected spaces found.
    Open

                    date = options.expires;

    Unexpected spaces found.
    Open

            }

    Unexpected spaces found.
    Open

                    if (cookie.substring(0, name.length + 1) == (name + '=')) {

    Unexpected spaces found.
    Open

            // in the following expressions, otherwise they evaluate to undefined

    Unexpected spaces found.
    Open

            var cookieValue = null;

    Unexpected spaces found.
    Open

            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');

    Unexpected spaces found.
    Open

        if (typeof value != 'undefined') { // name and value given, set cookie

    Unexpected spaces found.
    Open

            var secure = options.secure ? '; secure' : '';

    Unexpected spaces found.
    Open

                options.expires = -1;

    Unexpected spaces found.
    Open

                        break;

    Unexpected spaces found.
    Open

            }

    Unexpected spaces found.
    Open

                if (typeof options.expires == 'number') {

    Unexpected spaces found.
    Open

            // CAUTION: Needed to parenthesize options.path and options.domain

    Unexpected spaces found.
    Open

        } else { // only name given, get cookie

    There are no issues that match your filters.

    Category
    Status