Code Duplication    Length = 6-7 lines in 7 locations

lib/private/Share/Share.php 7 locations

@@ 356-361 (lines=6) @@
353
			$itemName = $path;
354
355
			// verify that the file exists before we try to share it
356
			if (!$path) {
357
				$message = 'Sharing %s failed, because the file does not exist';
358
				$message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName));
359
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
360
				throw new \Exception($message_t);
361
			}
362
			// verify that the user has share permission
363
			if (!\OC\Files\Filesystem::isSharable($path) || \OCP\Util::isSharingDisabledForUser()) {
364
				$message = 'You are not allowed to share %s';
@@ 408-413 (lines=6) @@
405
406
		// Verify share type and sharing conditions are met
407
		if ($shareType === self::SHARE_TYPE_USER) {
408
			if ($shareWith == $uidOwner) {
409
				$message = 'Sharing %s failed, because you can not share with yourself';
410
				$message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]);
411
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
412
				throw new \Exception($message_t);
413
			}
414
			if (!\OC::$server->getUserManager()->userExists($shareWith)) {
415
				$message = 'Sharing %s failed, because the user %s does not exist';
416
				$message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
@@ 633-639 (lines=7) @@
630
			}
631
632
			return $send;
633
		} else {
634
			// Future share types need to include their own conditions
635
			$message = 'Share type %s is not valid for %s';
636
			$message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource));
637
			\OCP\Util::writeLog('OCP\Share', sprintf($message, $shareType, $itemSource), \OCP\Util::DEBUG);
638
			throw new \Exception($message_t);
639
		}
640
641
		// Put the item into the database
642
		$result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate);
@@ 748-753 (lines=6) @@
745
			}
746
		}
747
748
		if ($date < $today) {
749
			$message = 'Cannot set expiration date. Expiration date is in the past';
750
			$message_t = $l->t('Cannot set expiration date. Expiration date is in the past');
751
			\OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::WARN);
752
			throw new \Exception($message_t);
753
		}
754
755
		return $date;
756
	}
@@ 856-861 (lines=6) @@
853
					throw new \Exception($message_t);
854
				}
855
				return self::$backends[$itemType];
856
			} else {
857
				$message = 'Sharing backend %s not found';
858
				$message_t = $l->t('Sharing backend %s not found', array($class));
859
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), \OCP\Util::ERROR);
860
				throw new \Exception($message_t);
861
			}
862
		}
863
		$message = 'Sharing backend for %s not found';
864
		$message_t = $l->t('Sharing backend for %s not found', array($itemType));
@@ 1709-1715 (lines=7) @@
1706
						$result['fileSource'] = ($backend instanceof \OCP\Share_Backend_File_Dependent) ? $itemSource : null;
1707
					}
1708
				}
1709
			} else {
1710
				$message = 'Sharing %s failed, because resharing is not allowed';
1711
				$message_t = $l->t('Sharing %s failed, because resharing is not allowed', array($itemSourceName));
1712
1713
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
1714
				throw new \Exception($message_t);
1715
			}
1716
		} else {
1717
			$result['parent'] = null;
1718
			$result['suggestedItemTarget'] = null;
@@ 1737-1743 (lines=7) @@
1734
					$meta = \OC\Files\Filesystem::getFileInfo($result['filePath']);
1735
					$result['fileSource'] = $meta['fileid'];
1736
				}
1737
				if ($result['fileSource'] == -1) {
1738
					$message = 'Sharing %s failed, because the file could not be found in the file cache';
1739
					$message_t = $l->t('Sharing %s failed, because the file could not be found in the file cache', array($itemSource));
1740
1741
					\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSource), \OCP\Util::DEBUG);
1742
					throw new \Exception($message_t);
1743
				}
1744
			} else {
1745
				$result['filePath'] = null;
1746
				$result['fileSource'] = null;