Code Duplication    Length = 23-23 lines in 2 locations

apps/comments/lib/Collaboration/CommentersSorter.php 1 location

@@ 56-78 (lines=23) @@
53
			return;
54
		}
55
56
		foreach ($sortArray as $type => &$byType) {
57
			if(!isset($commenters[$type])) {
58
				continue;
59
			}
60
61
			// at least on PHP 5.6 usort turned out to be not stable. So we add
62
			// the current index to the value and compare it on a draw
63
			$i = 0;
64
			$workArray = array_map(function($element) use (&$i) {
65
				return [$i++, $element];
66
			}, $byType);
67
68
			usort($workArray, function ($a, $b) use ($commenters, $type) {
69
				$r = $this->compare($a[1], $b[1], $commenters[$type]);
70
				if($r === 0) {
71
					$r = $a[0] - $b[0];
72
				}
73
				return $r;
74
			});
75
76
			// and remove the index values again
77
			$byType = array_column($workArray, 1);
78
		}
79
	}
80
81
	/**

apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php 1 location

@@ 70-92 (lines=23) @@
67
		}
68
		$al = $this->shareManager->getAccessList($nodes[0]);
69
70
		foreach ($sortArray as $type => &$byType) {
71
			if(!isset($al[$type]) || !is_array($al[$type])) {
72
				continue;
73
			}
74
75
			// at least on PHP 5.6 usort turned out to be not stable. So we add
76
			// the current index to the value and compare it on a draw
77
			$i = 0;
78
			$workArray = array_map(function($element) use (&$i) {
79
				return [$i++, $element];
80
			}, $byType);
81
82
			usort($workArray, function ($a, $b) use ($al, $type) {
83
				$result = $this->compare($a[1], $b[1], $al[$type]);
84
				if($result === 0) {
85
					$result = $a[0] - $b[0];
86
				}
87
				return $result;
88
			});
89
90
			// and remove the index values again
91
			$byType = array_column($workArray, 1);
92
		}
93
	}
94
95
	/**