Code Duplication    Length = 15-16 lines in 2 locations

lib/Controller/PushController.php 2 locations

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