Code Duplication    Length = 6-7 lines in 7 locations

lib/private/Share/Share.php 7 locations

@@ 668-673 (lines=6) @@
665
			$itemName = $path;
666
667
			// verify that the file exists before we try to share it
668
			if (!$path) {
669
				$message = 'Sharing %s failed, because the file does not exist';
670
				$message_t = $l->t('Sharing %s failed, because the file does not exist', [$itemSourceName]);
671
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
672
				throw new \Exception($message_t);
673
			}
674
			// verify that the user has share permission
675
			if (!\OC\Files\Filesystem::isSharable($path) || \OCP\Util::isSharingDisabledForUser()) {
676
				$message = 'You are not allowed to share %s';
@@ 720-725 (lines=6) @@
717
718
		// Verify share type and sharing conditions are met
719
		if ($shareType === self::SHARE_TYPE_USER) {
720
			if ($shareWith == $uidOwner) {
721
				$message = 'Sharing %s failed, because you can not share with yourself';
722
				$message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]);
723
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
724
				throw new \Exception($message_t);
725
			}
726
			if (!\OC_User::userExists($shareWith)) {
727
				$message = 'Sharing %s failed, because the user %s does not exist';
728
				$message_t = $l->t('Sharing %s failed, because the user %s does not exist', [$itemSourceName, $shareWith]);
@@ 923-929 (lines=7) @@
920
			}
921
922
			return $send;
923
		} else {
924
			// Future share types need to include their own conditions
925
			$message = 'Share type %s is not valid for %s';
926
			$message_t = $l->t('Share type %s is not valid for %s', [$shareType, $itemSource]);
927
			\OCP\Util::writeLog('OCP\Share', sprintf($message, $shareType, $itemSource), \OCP\Util::DEBUG);
928
			throw new \Exception($message_t);
929
		}
930
931
		// Put the item into the database
932
		$result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate);
@@ 1341-1346 (lines=6) @@
1338
			}
1339
		}
1340
1341
		if ($date < $today) {
1342
			$message = 'Cannot set expiration date. Expiration date is in the past';
1343
			$message_t = $l->t('Cannot set expiration date. Expiration date is in the past');
1344
			\OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::WARN);
1345
			throw new \Exception($message_t);
1346
		}
1347
1348
		return $date;
1349
	}
@@ 1567-1572 (lines=6) @@
1564
					throw new \Exception($message_t);
1565
				}
1566
				return self::$backends[$itemType];
1567
			} else {
1568
				$message = 'Sharing backend %s not found';
1569
				$message_t = $l->t('Sharing backend %s not found', [$class]);
1570
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), \OCP\Util::ERROR);
1571
				throw new \Exception($message_t);
1572
			}
1573
		}
1574
		$message = 'Sharing backend for %s not found';
1575
		$message_t = $l->t('Sharing backend for %s not found', [$itemType]);
@@ 2405-2411 (lines=7) @@
2402
						$result['fileSource'] = ($backend instanceof \OCP\Share_Backend_File_Dependent) ? $itemSource : null;
2403
					}
2404
				}
2405
			} else {
2406
				$message = 'Sharing %s failed, because resharing is not allowed';
2407
				$message_t = $l->t('Sharing %s failed, because resharing is not allowed', [$itemSourceName]);
2408
2409
				\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
2410
				throw new \Exception($message_t);
2411
			}
2412
		} else {
2413
			$result['parent'] = null;
2414
			$result['suggestedItemTarget'] = null;
@@ 2433-2439 (lines=7) @@
2430
					$meta = \OC\Files\Filesystem::getFileInfo($result['filePath']);
2431
					$result['fileSource'] = $meta['fileid'];
2432
				}
2433
				if ($result['fileSource'] == -1) {
2434
					$message = 'Sharing %s failed, because the file could not be found in the file cache';
2435
					$message_t = $l->t('Sharing %s failed, because the file could not be found in the file cache', [$itemSource]);
2436
2437
					\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSource), \OCP\Util::DEBUG);
2438
					throw new \Exception($message_t);
2439
				}
2440
			} else {
2441
				$result['filePath'] = null;
2442
				$result['fileSource'] = null;