Code Duplication    Length = 15-16 lines in 2 locations

lib/Controller/PushController.php 2 locations

@@ 219-234 (lines=16) @@
216
	 * @return bool If the entry was updated
217
	 * @throws \BadMethodCallException
218
	 */
219
	protected function updatePushToken(IUser $user, IToken $token, $devicePublicKey, $pushTokenHash) {
220
		$devicePublicKeyHash = hash('sha512', $devicePublicKey);
221
222
		$query = $this->db->getQueryBuilder();
223
		$query->update('notifications_pushtokens')
224
			->set('pushtokenhash', $query->createNamedParameter($pushTokenHash))
225
			->where($query->expr()->eq('uid', $query->createNamedParameter($user->getUID())))
226
			->andWhere($query->expr()->eq('token', $query->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT)))
227
			->andWhere($query->expr()->eq('devicepublickeyhash', $query->createNamedParameter($devicePublicKeyHash)));
228
229
		if ($query->execute() !== 0) {
230
			throw new \BadMethodCallException();
231
		}
232
233
		return true;
234
	}
235
236
	/**
237
	 * @param IUser $user
@@ 243-257 (lines=15) @@
240
	 * @return bool If the entry was deleted
241
	 * @throws \BadMethodCallException
242
	 */
243
	protected function deletePushToken(IUser $user, IToken $token, $devicePublicKey) {
244
		$devicePublicKeyHash = hash('sha512', $devicePublicKey);
245
246
		$query = $this->db->getQueryBuilder();
247
		$query->delete('notifications_pushtokens')
248
			->where($query->expr()->eq('uid', $query->createNamedParameter($user->getUID())))
249
			->andWhere($query->expr()->eq('token', $query->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT)))
250
			->andWhere($query->expr()->eq('devicepublickeyhash', $query->createNamedParameter($devicePublicKeyHash)));
251
252
		if ($query->execute() !== 0) {
253
			throw new \BadMethodCallException();
254
		}
255
256
		return true;
257
	}
258
}
259