Code Duplication    Length = 22-22 lines in 2 locations

lib/Service/CardService.php 2 locations

@@ 405-426 (lines=22) @@
402
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
403
	 * @throws BadRequestException
404
	 */
405
	public function assignLabel($cardId, $labelId) {
406
407
		if (is_numeric($cardId) === false) {
408
			throw new BadRequestException('card id must be a number');
409
		}
410
411
		if (is_numeric($labelId) === false) {
412
			throw new BadRequestException('label id must be a number');
413
		}
414
415
		$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
416
		if ($this->boardService->isArchived($this->cardMapper, $cardId)) {
417
			throw new StatusException('Operation not allowed. This board is archived.');
418
		}
419
		$card = $this->cardMapper->find($cardId);
420
		if ($card->getArchived()) {
421
			throw new StatusException('Operation not allowed. This card is archived.');
422
		}
423
		$label = $this->labelMapper->find($labelId);
424
		$this->cardMapper->assignLabel($cardId, $labelId);
425
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
426
	}
427
428
	/**
429
	 * @param $cardId
@@ 437-458 (lines=22) @@
434
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
435
	 * @throws BadRequestException
436
	 */
437
	public function removeLabel($cardId, $labelId) {
438
439
		if (is_numeric($cardId) === false) {
440
			throw new BadRequestException('card id must be a number');
441
		}
442
443
		if (is_numeric($labelId) === false) {
444
			throw new BadRequestException('label id must be a number');
445
		}
446
447
		$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
448
		if ($this->boardService->isArchived($this->cardMapper, $cardId)) {
449
			throw new StatusException('Operation not allowed. This board is archived.');
450
		}
451
		$card = $this->cardMapper->find($cardId);
452
		if ($card->getArchived()) {
453
			throw new StatusException('Operation not allowed. This card is archived.');
454
		}
455
		$label = $this->labelMapper->find($labelId);
456
		$this->cardMapper->removeLabel($cardId, $labelId);
457
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]);
458
	}
459
460
	/**
461
	 * @param $cardId