Fixed version filtering and sorting in PackagistRepository
This commit is contained in:
parent
5e173b7cc0
commit
272fc8524e
1 changed files with 5 additions and 7 deletions
|
@ -163,23 +163,21 @@
|
||||||
{
|
{
|
||||||
$versions = self::getVersions($repository, $vendor, $project);
|
$versions = self::getVersions($repository, $vendor, $project);
|
||||||
|
|
||||||
/** @noinspection KeysFragmentationWithArrayFunctionsInspection */
|
// Filter out pre-release versions such as alpha, beta, rc, dev
|
||||||
$versions = array_filter($versions, static function($version)
|
$versions = array_filter($versions, static function($version)
|
||||||
{
|
{
|
||||||
return !preg_match('/-alpha|-beta|-rc|dev/i', $version);
|
return !preg_match('/-alpha|-beta|-rc|dev/i', $version);
|
||||||
});
|
});
|
||||||
|
|
||||||
usort($versions, static function($a, $b)
|
// Sort versions in descending order using Semver::rsort
|
||||||
{
|
$versions = Semver::rsort($versions);
|
||||||
return Comparator::lessThanOrEqualTo($a, $b) ? 1 : -1;
|
|
||||||
});
|
|
||||||
|
|
||||||
if($versions[0] === null)
|
if (!isset($versions[0]))
|
||||||
{
|
{
|
||||||
throw new NetworkException(sprintf('Failed to resolve latest version for %s/%s', $vendor, $project));
|
throw new NetworkException(sprintf('Failed to resolve latest version for %s/%s', $vendor, $project));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $versions[0];
|
return $versions[0]; // The first version in the sorted array is the latest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue