Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly compare multiple package versions #380

Merged
merged 2 commits into from
Oct 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/Command/InstallPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private function download($packageName, $provider, $options = []) {
'location' => (string) $foundPkg->location,
'signature' => (string) $foundPkg->signature
);
$packageVersions[(string)$foundPkg->version] = [
$packageVersions[(string)$foundPkg->signature] = [
'name' => (string) $foundPkg->name,
'version' => (string) $foundPkg->version,
'release' => (string) $foundPkg->release,
Expand All @@ -368,8 +368,25 @@ private function download($packageName, $provider, $options = []) {

// If there are multiple versions of the same package, use the latest
if (count($packageVersions) > 1) {
$packageLatest = max(array_keys($packageVersions));
$packages[$packageName] = $packageVersions[$packageLatest];
$i = 0;
$latest = '';

// Compare versions
foreach (array_keys($packageVersions) as $version) {
if ($i == 0) {
// First iteration
$latest = $version;
} else {
// Replace latest version with current one if it's higher
if (version_compare($version, $latest, '>=')) {
$latest = $version;
}
}
$i++;
}

// Use latest
$packages[$packageName] = $packageVersions[$latest];
}

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