Skip to content

Commit 8904e9b

Browse files
authored
Merge pull request #380 from hugopeek/fix-picking-latest-package
Properly compare multiple package versions
2 parents 4648e5b + 52aca05 commit 8904e9b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Command/InstallPackageCommand.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ private function download($packageName, $provider, $options = []) {
356356
'location' => (string) $foundPkg->location,
357357
'signature' => (string) $foundPkg->signature
358358
);
359-
$packageVersions[(string)$foundPkg->version] = [
359+
$packageVersions[(string)$foundPkg->signature] = [
360360
'name' => (string) $foundPkg->name,
361361
'version' => (string) $foundPkg->version,
362362
'release' => (string) $foundPkg->release,
@@ -368,8 +368,25 @@ private function download($packageName, $provider, $options = []) {
368368

369369
// If there are multiple versions of the same package, use the latest
370370
if (count($packageVersions) > 1) {
371-
$packageLatest = max(array_keys($packageVersions));
372-
$packages[$packageName] = $packageVersions[$packageLatest];
371+
$i = 0;
372+
$latest = '';
373+
374+
// Compare versions
375+
foreach (array_keys($packageVersions) as $version) {
376+
if ($i == 0) {
377+
// First iteration
378+
$latest = $version;
379+
} else {
380+
// Replace latest version with current one if it's higher
381+
if (version_compare($version, $latest, '>=')) {
382+
$latest = $version;
383+
}
384+
}
385+
$i++;
386+
}
387+
388+
// Use latest
389+
$packages[$packageName] = $packageVersions[$latest];
373390
}
374391

375392
// If there's still no match, revisit the response and just grab all hits...

0 commit comments

Comments
 (0)