Code Duplication    Length = 6-7 lines in 6 locations

lib/private/share/share.php 6 locations

@@ 548-553 (lines=6) @@
545
		$backend = self::getBackend($itemType);
546
		$l = \OC::$server->getL10N('lib');
547
548
		if ($backend->isShareTypeAllowed($shareType) === false) {
549
			$message = 'Sharing %s failed, because the backend does not allow shares from type %i';
550
			$message_t = $l->t('Sharing %s failed, because the backend does not allow shares from type %i', array($itemSourceName, $shareType));
551
			\OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareType), \OC_Log::ERROR);
552
			throw new \Exception($message_t);
553
		}
554
555
		$uidOwner = \OC_User::getUser();
556
		$shareWithinGroupOnly = self::shareWithGroupMembersOnly();
@@ 603-608 (lines=6) @@
600
601
		// Verify share type and sharing conditions are met
602
		if ($shareType === self::SHARE_TYPE_USER) {
603
			if ($shareWith == $uidOwner) {
604
				$message = 'Sharing %s failed, because the user %s is the item owner';
605
				$message_t = $l->t('Sharing %s failed, because the user %s is the item owner', array($itemSourceName, $shareWith));
606
				\OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
607
				throw new \Exception($message_t);
608
			}
609
			if (!\OC_User::userExists($shareWith)) {
610
				$message = 'Sharing %s failed, because the user %s does not exist';
611
				$message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
@@ 609-614 (lines=6) @@
606
				\OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
607
				throw new \Exception($message_t);
608
			}
609
			if (!\OC_User::userExists($shareWith)) {
610
				$message = 'Sharing %s failed, because the user %s does not exist';
611
				$message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
612
				\OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
613
				throw new \Exception($message_t);
614
			}
615
			if ($shareWithinGroupOnly) {
616
				$inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
617
				if (empty($inGroup)) {
@@ 617-623 (lines=7) @@
614
			}
615
			if ($shareWithinGroupOnly) {
616
				$inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
617
				if (empty($inGroup)) {
618
					$message = 'Sharing %s failed, because the user '
619
						.'%s is not a member of any groups that %s is a member of';
620
					$message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemSourceName, $shareWith, $uidOwner));
621
					\OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareWith, $uidOwner), \OC_Log::ERROR);
622
					throw new \Exception($message_t);
623
				}
624
			}
625
			// Check if the item source is already shared with the user, either from the same owner or a different user
626
			if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups,
@@ 639-644 (lines=6) @@
636
				}
637
			}
638
		} else if ($shareType === self::SHARE_TYPE_GROUP) {
639
			if (!\OC_Group::groupExists($shareWith)) {
640
				$message = 'Sharing %s failed, because the group %s does not exist';
641
				$message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith));
642
				\OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
643
				throw new \Exception($message_t);
644
			}
645
			if ($shareWithinGroupOnly && !\OC_Group::inGroup($uidOwner, $shareWith)) {
646
				$message = 'Sharing %s failed, because '
647
					.'%s is not a member of the group %s';
@@ 2131-2137 (lines=7) @@
2128
			$result['suggestedFileTarget'] = null;
2129
			$result['itemSource'] = $itemSource;
2130
			$result['expirationDate'] = $expirationDate;
2131
			if (!$backend->isValidSource($itemSource, $uidOwner)) {
2132
				$message = 'Sharing %s failed, because the sharing backend for '
2133
					.'%s could not find its source';
2134
				$message_t = $l->t('Sharing %s failed, because the sharing backend for %s could not find its source', array($itemSource, $itemType));
2135
				\OC_Log::write('OCP\Share', sprintf($message, $itemSource, $itemType), \OC_Log::ERROR);
2136
				throw new \Exception($message_t);
2137
			}
2138
			if ($backend instanceof \OCP\Share_Backend_File_Dependent) {
2139
				$result['filePath'] = $backend->getFilePath($itemSource, $uidOwner);
2140
				if ($itemType == 'file' || $itemType == 'folder') {