Compare commits

...

3 commits

Author SHA1 Message Date
Matt Friedman
0a20edf6b4
[ticket/17336] Fix usage of a leaked loop-scoped variable
PHPBB-17336

Signed-off-by: Matt Friedman <maf675@gmail.com>
2024-06-11 11:54:49 -07:00
Matt Friedman
5229813c47
[ticket/17336] Optimize version sorting
PHPBB-17336

Signed-off-by: Matt Friedman <maf675@gmail.com>
2024-06-11 11:54:49 -07:00
Matt Friedman
d8aa3f05e5
[ticket/17336] Correctly handle aliased packages
PHPBB-17336

Signed-off-by: Matt Friedman <maf675@gmail.com>
2024-06-11 07:06:08 -07:00

View file

@ -22,6 +22,7 @@ use Composer\IO\NullIO;
use Composer\Json\JsonFile;
use Composer\Json\JsonValidationException;
use Composer\Package\BasePackage;
use Composer\Package\CompleteAliasPackage;
use Composer\Package\CompletePackage;
use Composer\PartialComposer;
use Composer\Repository\ComposerRepository;
@ -390,20 +391,25 @@ class installer
foreach ($compatible_packages as $name => $versions)
{
// Determine the highest version of the package
/** @var CompletePackage $highest_version */
/** @var CompletePackage|CompleteAliasPackage $highest_version */
$highest_version = null;
/** @var CompletePackage $version */
foreach ($versions as $version)
// Sort the versions array in descending order
usort($versions, function ($a, $b)
{
if (strpos($version->getVersion(), '9999999') === 0)
{
continue;
}
return version_compare($b->getVersion(), $a->getVersion());
});
if (!$highest_version || version_compare($version->getVersion(), $highest_version->getVersion(), '>'))
// The first element in the sorted array is the highest version
if (!empty($versions))
{
$highest_version = $versions[0];
// If highest version is a non-numeric dev branch, it's an instance of CompleteAliasPackage,
// so we need to get the package being aliased in order to show the true non-numeric version.
if ($highest_version instanceof CompleteAliasPackage)
{
$highest_version = $version;
$highest_version = $highest_version->getAliasOf();
}
}
@ -414,7 +420,7 @@ class installer
$available[$name]['composer_name'] = $highest_version->getName();
$available[$name]['version'] = $highest_version->getPrettyVersion();
if ($version instanceof CompletePackage)
if ($highest_version instanceof CompletePackage)
{
$available[$name]['description'] = $highest_version->getDescription();
$available[$name]['url'] = $highest_version->getHomepage();