diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php index 3956423a50b0a..8d40ce30f43e7 100644 --- a/apps/comments/lib/Collaboration/CommentersSorter.php +++ b/apps/comments/lib/Collaboration/CommentersSorter.php @@ -22,11 +22,8 @@ public function getId(): string { } /** - * Sorts people who commented on the given item atop (descelating) of the - * others - * - * @param array &$sortArray - * @param array $context + * Sorts people who commented on the given item ahead of others, in + * descending order */ #[\Override] public function sort(array &$sortArray, array $context): void { @@ -35,7 +32,7 @@ public function sort(array &$sortArray, array $context): void { } $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); - if (count($commenters) === 0) { + if ($commenters === []) { return; } @@ -44,23 +41,9 @@ public function sort(array &$sortArray, array $context): void { continue; } - // at least on PHP 5.6 usort turned out to be not stable. So we add - // the current index to the value and compare it on a draw - $i = 0; - $workArray = array_map(function ($element) use (&$i) { - return [$i++, $element]; - }, $byType); - - usort($workArray, function ($a, $b) use ($commenters, $type) { - $r = $this->compare($a[1], $b[1], $commenters[$type]); - if ($r === 0) { - $r = $a[0] - $b[0]; - } - return $r; + usort($byType, function ($a, $b) use ($commenters, $type) { + return $this->compare($a, $b, $commenters[$type]); }); - - // and remove the index values again - $byType = array_column($workArray, 1); } } diff --git a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php index 9395b0600c69d..207b09a99968b 100644 --- a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php +++ b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php @@ -28,7 +28,7 @@ public function getId(): string { } #[\Override] - public function sort(array &$sortArray, array $context) { + public function sort(array &$sortArray, array $context): void { // let's be tolerant. Comments uses "files" by default, other usages are often singular if ($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { return; @@ -50,33 +50,13 @@ public function sort(array &$sortArray, array $context) { continue; } - // at least on PHP 5.6 usort turned out to be not stable. So we add - // the current index to the value and compare it on a draw - $i = 0; - $workArray = array_map(function ($element) use (&$i) { - return [$i++, $element]; - }, $byType); - - usort($workArray, function ($a, $b) use ($al, $type) { - $result = $this->compare($a[1], $b[1], $al[$type]); - if ($result === 0) { - $result = $a[0] - $b[0]; - } - return $result; + usort($byType, function ($a, $b) use ($al, $type) { + return $this->compare($a, $b, $al[$type]); }); - - // and remove the index values again - $byType = array_column($workArray, 1); } } - /** - * @param array $a - * @param array $b - * @param array $al - * @return int - */ - protected function compare(array $a, array $b, array $al) { + protected function compare(array $a, array $b, array $al): int { $a = $a['value']['shareWith']; $b = $b['value']['shareWith'];