Code Duplication    Length = 21-22 lines in 2 locations

classes/UserAPIToken.php 2 locations

@@ 112-133 (lines=22) @@
109
	 *
110
	 * @throws UserAPIToken_Exception TOKEN_REQUIRED If no token is provided
111
	 **/
112
	public function setToken($token) {
113
		if (empty($token)) {
114
			throw new UserAPIToken_Exception(
115
				'A token is required',
116
				UserAPIToken_Exception::TOKEN_REQUIRED
117
			);
118
		}
119
		if($this->consumerKey && $this->id && $this->sql) {
120
			$_token = $this->sql->real_escape_string($token);
121
			if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `token` = '$_token' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) {
122
				throw new UserAPIToken_Exception(
123
					"Error updating token: {$this->sql->error}",
124
					UserAPIToken_Exception::MYSQLI_ERROR
125
				);
126
			}
127
			$this->token = $token;
128
			
129
			return true;
130
		}
131
		
132
		return false;
133
	}
134
	
135
	/**
136
	 * @return string|boolean The URL of the API for which the user's API token is valid, or FALSE if no token has been acquired
@@ 154-174 (lines=21) @@
151
	 *
152
	 * @throws UserAPITokenException API_URL_REQUIRED If no URL is provided
153
	 **/
154
	public function setAPIUrl($apiUrl) {
155
		if (empty($apiUrl)) {
156
			throw new UserAPIToken_Exception(
157
				'API URL is required',
158
				UserAPIToken_Exception::API_URL_REQUIRED
159
			);
160
		}
161
		
162
		if ($this->consumerKey && $this->id && $this->sql) {
163
			$_apiUrl = $this->sql->real_escape_string($apiUrl);
164
			if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `api_url` = '$_apiUrl' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) {
165
				throw new UserAPIToken_Exception(
166
					"Error updating API URL for user token: {$this->sql->error}",
167
					UserAPIToken_Exception::MYSQLI_ERROR
168
				);
169
			}
170
			$this->apiUrl = $apiUrl;
171
			return true;
172
		}
173
		return false;
174
	}
175
}
176
177
/**