Completed
Push — master ( f08fdc...55ae08 )
by Yannick
29:19
created

js/script.js   A

Complexity

Total Complexity 21
Complexity/F 2.1

Size

Lines of Code 108
Function Count 10

Duplication

Duplicated Lines 40
Ratio 37.04 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 40
loc 108
rs 10
c 0
b 0
f 0
wmc 21
mnd 4
bc 21
fnc 10
bpm 2.1
cpm 2.1
noi 6

6 Functions

Rating   Name   Duplication   Size   Complexity  
A script.js ➔ language 0 6 1
A script.js ➔ showSearchContainers 0 4 1
D script.js ➔ populate 1 20 1
A script.js ➔ showSubMenu 0 4 1
B script.js ➔ statsairlinechange 20 21 6
B script.js ➔ statsdatechange 19 19 5

How to fix   Duplicated Code   

Duplicated Code

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
/** global: navigator */
2
3
$( document ).ready(function() {
4
/*	
5
	//gets the current date information to be used in the datepicker
6
	var date = new Date();
7
	var currentMonth = date.getMonth();
8
	var currentDate = date.getDate();
9
	var currentYear = date.getFullYear();
10
11
  $( "#start_date" ).datetimepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: new Date(2014, 04 - 1, 12), maxDate: new Date(currentYear, currentMonth, currentDate, 23, 59) });
12
  $( "#end_date" ).datetimepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: new Date(2014, 04 - 1, 12), maxDate: new Date(currentYear, currentMonth, currentDate, 23, 59) });
13
  $( "#date" ).datepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: new Date(2014, 04 - 1, 12), maxDate: new Date(currentYear, currentMonth, currentDate) });
14
*/  
15
  //custom select boxes
16
  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
17
    $('.selectpicker').selectpicker('mobile');
18
	} else {
19
	  $('.selectpicker').selectpicker();
20
	}
21
  
22
  //search
23
  $("body.page-search .sub-menu input[type=text]").click(function(){
24
	    this.select();
25
	});
26
    
27
  //bootstrap popover
28
  $('[data-toggle="popover"]').popover({
29
    trigger: 'hover',
30
    'placement': 'bottom'
31
  });
32
  
33
  
34
});
35
36
function showSearchContainers(){
37
	$(".search-explore").hide();
38
	$(".search-containers").slideDown();
39
}
40
41
function showSubMenu(){
42
	$(".sub-menu-statistic").hide();
43
	$(".sub-menu-container").slideDown();
44
}
45
function language(selectObj) {
46
    var idx = selectObj.selectedIndex;
47
    var lang = selectObj.options[idx].value;
48
    document.cookie =  'language='+lang+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
49
    window.location.reload();
50
}
51
function populate(obj,str,selected) {
52
	//console.log('populate');
53
	$.ajax({
54
		url:'search-ajax.php',
55
		type:'GET',
56
		data: 'ask=' + str,
57
		dataType: 'json',
58
		success: function( json ) {
59
			var options = "";
60
			$.each(json, function(i, item){
61
				if ($.inArray(item.id,selected) != -1) {
62
					options += "<option value="+item.id+" selected>"+item.value+"</option>";
63
				} else {
64
					options += "<option value="+item.id+">"+item.value+"</option>";
65
				}
66
			});
67
			obj.append(options);
68
		}
69
	});
70 View Code Duplication
}
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
71
function statsdatechange(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...
72
	var form = document.getElementById('changedate');
73
	var yearmonth = form.date.value.split("-");
74
	var pagename = location.pathname;
75
	pagename = pagename.split('/');
76
	var i = 0;
77
	var page = '';
78
	for (i = 0; i < pagename.length; i++) {
79
		if (pagename[i] != '') {
80
			if (isNaN(pagename[i])) page = page +'/'+ pagename[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
81
		}
82
	}
83
	if (typeof yearmonth[1] != 'undefined') {
84
		form.action = page+'/'+yearmonth[0]+'/'+yearmonth[1];
85
	} else {
86
		form.action = page;
87
	}
88
	form.submit();
89 View Code Duplication
}
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
90
function statsairlinechange(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...
91
	var form = document.getElementById('changeairline');
92
	var airline = form.airline.value;
93
	var pagename = location.pathname;
94
	pagename = pagename.split('/');
95
	var i = 0;
96
	var page = '';
97
	var add = false;
98
	for (i = 0; i < pagename.length; i++) {
99
		if (pagename[i] != '') {
100
			if (pagename[i].length != 3) page = page+'/'+pagename[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
101
			else {
102
				add = true;
103
				if (airline != 'all') page = page+'/'+airline;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
104
			}
105
		}
106
	}
107
	if (add === false) page = page+'/'+airline;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
108
	form.action = page;
109
	form.submit();
110
}
111