1
0
Fork 0

Fix package sorting logic, fixes #11287

pull/11292/head
Jordi Boggiano 2023-02-03 22:48:18 +01:00
parent 50cded331c
commit 2f2d6c9de7
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 12 additions and 11 deletions

View File

@ -28,21 +28,22 @@ class PackageSorter
*/
public static function getMostCurrentVersion(array $packages): ?PackageInterface
{
return array_reduce($packages, static function ($carry, $pkg) {
if ($carry === null) {
return $pkg;
if (count($packages) === 0) {
return null;
}
$highest = reset($packages);
foreach ($packages as $candidate) {
if ($candidate->isDefaultBranch()) {
return $candidate;
}
if ($pkg->isDefaultBranch()) {
return $pkg;
if (version_compare($highest->getVersion(), $candidate->getVersion(), '<')) {
$highest = $candidate;
}
}
if (!$carry->isDefaultBranch() && version_compare($carry->getVersion(), $pkg->getVersion(), '<')) {
return $pkg;
}
return $carry;
});
return $highest;
}
/**