diff --git a/changelog/unreleased/40945 b/changelog/unreleased/40945 new file mode 100644 index 000000000000..e9ba4244ed31 --- /dev/null +++ b/changelog/unreleased/40945 @@ -0,0 +1,6 @@ +Bugfix: fix usort callback functions to return integers + +Calls to the PHP usort function have been refactored so that the callback +function used always correctly returns an integer. + +https://github.com/owncloud/core/pull/40945 diff --git a/core/Command/App/CheckCode.php b/core/Command/App/CheckCode.php index 50eb4f6feffc..c6b7f6c75410 100644 --- a/core/Command/App/CheckCode.php +++ b/core/Command/App/CheckCode.php @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(" {$count} errors"); } \usort($errors, function ($a, $b) { - return $a['line'] >$b['line']; + return $a['line'] - $b['line']; }); foreach ($errors as $p) { diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 340f6383de04..d579173c75dd 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -195,7 +195,7 @@ protected function findMigrations() { $files = \array_keys(\iterator_to_array($iterator)); \uasort($files, function ($a, $b) { - return (\basename($a) < \basename($b)) ? -1 : 1; + return \strcmp(\basename($a), \basename($b)); }); $migrations = []; diff --git a/lib/private/Preview/TXT.php b/lib/private/Preview/TXT.php index 5caa3ac4551b..1764c4dbe3dd 100644 --- a/lib/private/Preview/TXT.php +++ b/lib/private/Preview/TXT.php @@ -146,7 +146,7 @@ private function getFontFile(array $info): string { if ($a === $b) { return 0; } - return ($a < $b) ? 1 : -1; + return ($b - $a); }); // Information is ordered by counted chars, from highest number of counted chars to lowest. foreach ($countInfo as $key => $value) { diff --git a/lib/private/Settings/SettingsManager.php b/lib/private/Settings/SettingsManager.php index f1c79447e23d..cdaaacd173b6 100644 --- a/lib/private/Settings/SettingsManager.php +++ b/lib/private/Settings/SettingsManager.php @@ -475,14 +475,15 @@ protected function loadSection($type, $sectionID) { /** * Sort the array of ISettings or ISections by their priority attribute - * @param array $objects (ISections of ISettings) + * A lower priority number means that the item should appear first. + * @param array $objects (ISections or ISettings) * @return array */ protected function sortOrder($objects) { \usort($objects, function ($a, $b) { /** @var ISection | ISettings $a */ /** @var ISection | ISettings $b */ - return $a->getPriority() < $b->getPriority(); + return $b->getPriority() - $a->getPriority(); }); return $objects; } diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 0eb7992c126c..84c770dbe4c9 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -366,7 +366,7 @@ public function testSearchByTag() { $this->assertCount(2, $results); \usort($results, function ($value1, $value2) { - return $value1['name'] >= $value2['name']; + return \strcmp($value1['name'], $value2['name']); }); $this->assertEquals('folder', $results[0]['name']); @@ -382,7 +382,7 @@ public function testSearchByTag() { $this->assertCount(3, $results); \usort($results, function ($value1, $value2) { - return $value1['name'] >= $value2['name']; + return \strcmp($value1['name'], $value2['name']); }); $this->assertEquals('folder', $results[0]['name']);