Code Duplication    Length = 44-46 lines in 3 locations

php/jodel-web.php 3 locations

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