Code Duplication    Length = 44-46 lines in 3 locations

php/jodel-web.php 3 locations

@@ 38-83 (lines=46) @@
35
	}
36
}
37
38
function isTokenFresh(Location $location)
39
{
40
	$db = new DatabaseConnect();  
41
	$result = $db->query("SELECT * FROM accounts WHERE id='1'");
42
	
43
	$access_token;
44
45
	if ($result->num_rows > 0)
46
	{
47
			// output data of each row
48
			while($row = $result->fetch_assoc()) {
49
					//$access_token = $row["access_token"];
50
					$expiration_date = $row["expiration_date"];
51
					$deviceUid = $row["device_uid"];
52
					$access_token = $row["access_token"];
53
			}
54
	}
55
	else
56
	{
57
			echo '0 results';
58
	}
59
60
	if($expiration_date <= time()) {
61
		$accountCreator = new CreateUser();
62
		$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken());
63
		$accountCreator->setDeviceUid($deviceUid);
64
		$accountCreator->setLocation($location);
65
		$data = $accountCreator->execute();
66
67
		$access_token = (string)$data[0]['access_token'];
68
		$expiration_date = $data[0]['expiration_date'];
69
		$device_uid = (string)$data[1];
70
		
71
		$db = new DatabaseConnect();  
72
		$result = $db->query("UPDATE accounts 
73
								SET access_token='" . $access_token . "',
74
									expiration_date='" . $expiration_date . "'
75
								WHERE device_uid='" . $device_uid . "'");
76
77
		if($result === false){
78
				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
79
		}	
80
	}
81
	
82
	return $access_token;
83
}
84
85
function isTokenFreshByAccessToken(Location $location, $accessToken)
86
{
@@ 85-128 (lines=44) @@
82
	return $access_token;
83
}
84
85
function isTokenFreshByAccessToken(Location $location, $accessToken)
86
{
87
	$db = new DatabaseConnect();  
88
	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'");
89
	
90
	if ($result->num_rows > 0)
91
	{
92
			// output data of each row
93
			while($row = $result->fetch_assoc()) {
94
					//$access_token = $row["access_token"];
95
					$expiration_date = $row["expiration_date"];
96
					$deviceUid = $row["device_uid"];
97
					$access_token = $row["access_token"];
98
			}
99
	}
100
	else
101
	{
102
			echo '0 results';
103
	}
104
105
	if($expiration_date <= time()) {
106
		$accountCreator = new CreateUser();
107
		$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken());
108
		$accountCreator->setDeviceUid($deviceUid);
109
		$accountCreator->setLocation($location);
110
		$data = $accountCreator->execute();
111
112
		$access_token = (string)$data[0]['access_token'];
113
		$expiration_date = $data[0]['expiration_date'];
114
		$device_uid = (string)$data[1];
115
		
116
		$db = new DatabaseConnect();  
117
		$result = $db->query("UPDATE accounts 
118
								SET access_token='" . $access_token . "',
119
									expiration_date='" . $expiration_date . "'
120
								WHERE device_uid='" . $device_uid . "'");
121
122
		if($result === false){
123
				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
124
		}	
125
	}
126
	
127
	return $access_token;
128
}
129
130
function isTokenFreshByDeviceUid(Location $location, $deviceUid)
131
{
@@ 130-175 (lines=46) @@
127
	return $access_token;
128
}
129
130
function isTokenFreshByDeviceUid(Location $location, $deviceUid)
131
{
132
	$db = new DatabaseConnect();  
133
	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'");
134
135
	$access_token;
136
137
	if ($result->num_rows > 0)
138
	{
139
			// output data of each row
140
			while($row = $result->fetch_assoc()) {
141
					//$access_token = $row["access_token"];
142
					$expiration_date = $row["expiration_date"];
143
					$deviceUid = $row["device_uid"];
144
					$access_token = $row["access_token"];
145
			}
146
	}
147
	else
148
	{
149
			echo '0 results';
150
	}
151
152
	if($expiration_date <= time()) {
153
		$accountCreator = new CreateUser();
154
		$accountCreator->setAccessToken($access_token);
155
		$accountCreator->setDeviceUid($deviceUid);
156
		$accountCreator->setLocation($location);
157
		$data = $accountCreator->execute();
158
159
		$access_token = (string)$data[0]['access_token'];
160
		$expiration_date = $data[0]['expiration_date'];
161
		$device_uid = (string)$data[1];
162
		
163
		$db = new DatabaseConnect();  
164
		$result = $db->query("UPDATE accounts 
165
								SET access_token='" . $access_token . "',
166
									expiration_date='" . $expiration_date . "'
167
								WHERE device_uid='" . $device_uid . "'");
168
169
		if($result === false){
170
				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
171
		}	
172
	}
173
	
174
	return $access_token;
175
}
176
177
function getLocationByAccessToken($accessToken)
178
{