Code Duplication    Length = 6-7 lines in 5 locations

lib/private/legacy/json.php 5 locations

@@ 58-64 (lines=7) @@
55
	 * @param string $app
56
	 * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled.
57
	 */
58
	public static function checkAppEnabled($app) {
59
		if (!OC_App::isEnabled($app)) {
60
			$l = \OC::$server->getL10N('lib');
61
			self::error(['data' => ['message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled']]);
62
			exit();
63
		}
64
	}
65
66
	private static function sendErrorAndExit() {
67
		$l = \OC::$server->getL10N('lib');
@@ 66-71 (lines=6) @@
63
		}
64
	}
65
66
	private static function sendErrorAndExit() {
67
		$l = \OC::$server->getL10N('lib');
68
		\http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
69
		self::error(['data' => ['message' => $l->t('Authentication error'), 'error' => 'authentication_error']]);
70
		exit();
71
	}
72
73
	/**
74
	 * Check if the user is logged in, send json error msg if not
@@ 102-108 (lines=7) @@
99
	 * Check an ajax get/post call if the request token is valid, send json error msg if not.
100
	 * @deprecated Use annotation based CSRF checks from the AppFramework instead
101
	 */
102
	public static function callCheck() {
103
		if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
104
			$l = \OC::$server->getL10N('lib');
105
			self::error(['data' => ['message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired']]);
106
			exit();
107
		}
108
	}
109
110
	/**
111
	 * Check if the user is a admin, send json error msg if not.
@@ 114-120 (lines=7) @@
111
	 * Check if the user is a admin, send json error msg if not.
112
	 * @deprecated Use annotation based ACLs from the AppFramework instead
113
	 */
114
	public static function checkAdminUser() {
115
		if (!OC_User::isAdminUser(OC_User::getUser())) {
116
			$l = \OC::$server->getL10N('lib');
117
			self::error(['data' => ['message' => $l->t('Authentication error'), 'error' => 'authentication_error']]);
118
			exit();
119
		}
120
	}
121
122
	/**
123
	 * Check is a given user exists - send json error msg if not
@@ 127-133 (lines=7) @@
124
	 * @param string $user
125
	 * @deprecated Use a AppFramework JSONResponse instead
126
	 */
127
	public static function checkUserExists($user) {
128
		if (!OCP\User::userExists($user)) {
129
			$l = \OC::$server->getL10N('lib');
130
			OCP\JSON::error(['data' => ['message' => $l->t('Unknown user'), 'error' => 'unknown_user']]);
131
			exit;
132
		}
133
	}
134
135
	/**
136
	 * Check if the user has administration privileges, send json error msg if not