htdocs/themes/reflex/js/cookie.js
Function cookie
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
Open
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
- Read upRead up
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
Open
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
Unexpected spaces found. Open
Open
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
- Exclude checks
Unexpected spaces found. Open
Open
// in the packed version for some reason...
- Exclude checks
Unexpected spaces found. Open
Open
if (document.cookie && document.cookie != '') {
- Exclude checks
Unexpected spaces found. Open
Open
var cookies = document.cookie.split(';');
- Exclude checks
Unexpected spaces found. Open
Open
if (value === null) {
- Exclude checks
Unexpected spaces found. Open
Open
return cookieValue;
- Exclude checks
Unexpected spaces found. Open
Open
// Does this cookie string begin with the name we want?
- Exclude checks
Unexpected spaces found. Open
Open
var path = options.path ? '; path=' + (options.path) : '';
- Exclude checks
Unexpected spaces found. Open
Open
var domain = options.domain ? '; domain=' + (options.domain) : '';
- Exclude checks
Unexpected spaces found. Open
Open
var cookie = jQuery.trim(cookies[i]);
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
var expires = '';
- Exclude checks
Unexpected spaces found. Open
Open
} else {
- Exclude checks
Unexpected spaces found. Open
Open
for (var i = 0; i < cookies.length; i++) {
- Exclude checks
Unexpected spaces found. Open
Open
options = options || {};
- Exclude checks
Unexpected spaces found. Open
Open
var date;
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
value = '';
- Exclude checks
Unexpected spaces found. Open
Open
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
- Exclude checks
Unexpected spaces found. Open
Open
date = new Date();
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
- Exclude checks
Unexpected spaces found. Open
Open
date = options.expires;
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
if (cookie.substring(0, name.length + 1) == (name + '=')) {
- Exclude checks
Unexpected spaces found. Open
Open
// in the following expressions, otherwise they evaluate to undefined
- Exclude checks
Unexpected spaces found. Open
Open
var cookieValue = null;
- Exclude checks
Unexpected spaces found. Open
Open
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
- Exclude checks
Unexpected spaces found. Open
Open
if (typeof value != 'undefined') { // name and value given, set cookie
- Exclude checks
Unexpected spaces found. Open
Open
var secure = options.secure ? '; secure' : '';
- Exclude checks
Unexpected spaces found. Open
Open
options.expires = -1;
- Exclude checks
Unexpected spaces found. Open
Open
break;
- Exclude checks
Unexpected spaces found. Open
Open
}
- Exclude checks
Unexpected spaces found. Open
Open
if (typeof options.expires == 'number') {
- Exclude checks
Unexpected spaces found. Open
Open
// CAUTION: Needed to parenthesize options.path and options.domain
- Exclude checks
Unexpected spaces found. Open
Open
} else { // only name given, get cookie
- Exclude checks