Code Duplication    Length = 5-8 lines in 7 locations

mod/gc_api/lib/profile.php 7 locations

@@ 304-308 (lines=5) @@
301
		return $response;
302
	}
303
304
	if ($data == '') {
305
		$response['error'] = 2;
306
		$response['message'] = 'data must be a string representing a JSON object.';
307
		return $response;
308
	}
309
	$userDataObj = json_decode($data, true);
310
	if (json_last_error() !== 0) {
311
		$response['error'] = 2;
@@ 310-315 (lines=6) @@
307
		return $response;
308
	}
309
	$userDataObj = json_decode($data, true);
310
	if (json_last_error() !== 0) {
311
		$response['error'] = 2;
312
		$response['message'] = 'invalid JSON - data was unable to be parsed';
313
		return $response;
314
	}
315
316
	foreach ($userDataObj as $field => $value) {
317
		switch ($field) {
318
			case 'name':
@@ 556-563 (lines=8) @@
553
				}
554
555
556
				if ($resulting_error !== "") {
557
					$response['error'] = 3;
558
					$response['message'] = 'invalid email or email domain - must be a valid Government of Canada email address';
559
					return $response;
560
				}
561
				$user_entity->set('email', $value);
562
				$user_entity->save();
563
564
				elgg_set_ignore_access(false);
565
				break;
566
			case 'secondLanguage':
@@ 588-592 (lines=5) @@
585
	// create account
586
	// send password reset email
587
	// fill in profile data
588
	if ($data == '') {
589
		$response['error'] = 2;
590
		$response['message'] = 'data must be a string representing a JSON object.';
591
		return $response;
592
	}
593
	$userDataObj = json_decode($data, true);
594
	if (json_last_error() !== 0) {
595
		$response['error'] = 2;
@@ 594-599 (lines=6) @@
591
		return $response;
592
	}
593
	$userDataObj = json_decode($data, true);
594
	if (json_last_error() !== 0) {
595
		$response['error'] = 2;
596
		$response['message'] = 'invalid JSON - data was unable to be parsed';
597
		return $response;
598
	}
599
600
	///////////////////////////////////////////////////////////////////
601
	//error check data field
602
	///////////////////////////////////////////////////////////////////
@@ 802-809 (lines=8) @@
799
					}
800
				}
801
802
				if ($resulting_error !== "") {
803
					$response['error'] = 3;
804
					$response['message'] = 'invalid email or email domain - must be a valid Government of Canada email address';
805
					return $response;
806
				}
807
				break;
808
		}
809
	}
810
811
	//check for existing email
812
	$email = $userDataObj['email'];
@@ 840-844 (lines=5) @@
837
838
	//register user using data passed
839
	$userGUID = register_user($username, $tempPass, $name, $userDataObj['email']);
840
	if ($userGUID==false) {
841
		$response['error'] = 1;
842
		$response['message'] = 'Failed creating account';
843
		return $response;
844
	}
845
846
	$user_entity = get_user($userGUID);
847