Code Duplication    Length = 44-46 lines in 3 locations

php/jodel-web.php 3 locations

@@ 236-281 (lines=46) @@
233
	}
234
}
235
236
function isTokenFresh(Location $location)
237
{
238
	$db = new DatabaseConnect();  
239
	$result = $db->query("SELECT * FROM accounts WHERE id='1'");
240
	
241
	$access_token;
242
243
	if ($result->num_rows > 0)
244
	{
245
			// output data of each row
246
			while($row = $result->fetch_assoc()) {
247
					//$access_token = $row["access_token"];
248
					$expiration_date = $row["expiration_date"];
249
					$deviceUid = $row["device_uid"];
250
					$access_token = $row["access_token"];
251
			}
252
	}
253
	else
254
	{
255
			echo '0 results';
256
	}
257
258
	if($expiration_date <= time()) {
259
		$accountCreator = new CreateUser();
260
		$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken());
261
		$accountCreator->setDeviceUid($deviceUid);
262
		$accountCreator->setLocation($location);
263
		$data = $accountCreator->execute();
264
265
		$access_token = (string)$data[0]['access_token'];
266
		$expiration_date = $data[0]['expiration_date'];
267
		$device_uid = (string)$data[1];
268
		
269
		$db = new DatabaseConnect();  
270
		$result = $db->query("UPDATE accounts 
271
								SET access_token='" . $access_token . "',
272
									expiration_date='" . $expiration_date . "'
273
								WHERE device_uid='" . $device_uid . "'");
274
275
		if($result === false){
276
				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
277
		}	
278
	}
279
	
280
	return $access_token;
281
}
282
283
function isTokenFreshByAccessToken(Location $location, $accessToken)
284
{
@@ 283-326 (lines=44) @@
280
	return $access_token;
281
}
282
283
function isTokenFreshByAccessToken(Location $location, $accessToken)
284
{
285
	$db = new DatabaseConnect();  
286
	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'");
287
	
288
	if ($result->num_rows > 0)
289
	{
290
			// output data of each row
291
			while($row = $result->fetch_assoc()) {
292
					//$access_token = $row["access_token"];
293
					$expiration_date = $row["expiration_date"];
294
					$deviceUid = $row["device_uid"];
295
					$access_token = $row["access_token"];
296
			}
297
	}
298
	else
299
	{
300
			echo '0 results';
301
	}
302
303
	if($expiration_date <= time()) {
304
		$accountCreator = new CreateUser();
305
		$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken());
306
		$accountCreator->setDeviceUid($deviceUid);
307
		$accountCreator->setLocation($location);
308
		$data = $accountCreator->execute();
309
310
		$access_token = (string)$data[0]['access_token'];
311
		$expiration_date = $data[0]['expiration_date'];
312
		$device_uid = (string)$data[1];
313
		
314
		$db = new DatabaseConnect();  
315
		$result = $db->query("UPDATE accounts 
316
								SET access_token='" . $access_token . "',
317
									expiration_date='" . $expiration_date . "'
318
								WHERE device_uid='" . $device_uid . "'");
319
320
		if($result === false){
321
				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
322
		}	
323
	}
324
	
325
	return $access_token;
326
}
327
328
function isTokenFreshByDeviceUid(Location $location, $deviceUid)
329
{
@@ 328-373 (lines=46) @@
325
	return $access_token;
326
}
327
328
function isTokenFreshByDeviceUid(Location $location, $deviceUid)
329
{
330
	$db = new DatabaseConnect();  
331
	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'");
332
333
	$access_token;
334
335
	if ($result->num_rows > 0)
336
	{
337
			// output data of each row
338
			while($row = $result->fetch_assoc()) {
339
					//$access_token = $row["access_token"];
340
					$expiration_date = $row["expiration_date"];
341
					$deviceUid = $row["device_uid"];
342
					$access_token = $row["access_token"];
343
			}
344
	}
345
	else
346
	{
347
			echo '0 results';
348
	}
349
350
	if($expiration_date <= time()) {
351
		$accountCreator = new CreateUser();
352
		$accountCreator->setAccessToken($access_token);
353
		$accountCreator->setDeviceUid($deviceUid);
354
		$accountCreator->setLocation($location);
355
		$data = $accountCreator->execute();
356
357
		$access_token = (string)$data[0]['access_token'];
358
		$expiration_date = $data[0]['expiration_date'];
359
		$device_uid = (string)$data[1];
360
		
361
		$db = new DatabaseConnect();  
362
		$result = $db->query("UPDATE accounts 
363
								SET access_token='" . $access_token . "',
364
									expiration_date='" . $expiration_date . "'
365
								WHERE device_uid='" . $device_uid . "'");
366
367
		if($result === false){
368
				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
369
		}	
370
	}
371
	
372
	return $access_token;
373
}
374
375
function getLocationByAccessToken($accessToken)
376
{