From c033644f8be083df6d72bf9a3d79dab2db22a704 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 10 Mar 2020 16:08:40 +0100 Subject: [PATCH] Present lock changes alphabetically, with uninstalls first, then all install/updates mixed --- src/Composer/Installer.php | 49 +++++++++++++------ .../installer/install-funding-notice.test | 2 +- .../Fixtures/installer/suggest-replaced.test | 2 +- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 71b0f8262..880840785 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -435,39 +435,60 @@ class Installer $platformReqs = $this->extractPlatformRequirements($this->package->getRequires()); $platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires()); + $installsUpdates = $uninstalls = array(); if ($lockTransaction->getOperations()) { - $installs = $updates = $uninstalls = array(); + $installNames = $updateNames = $uninstallNames = array(); foreach ($lockTransaction->getOperations() as $operation) { if ($operation instanceof InstallOperation) { - $installs[] = $operation->getPackage()->getPrettyName().':'.$operation->getPackage()->getFullPrettyVersion(); + $installsUpdates[] = $operation; + $installNames[] = $operation->getPackage()->getPrettyName().':'.$operation->getPackage()->getFullPrettyVersion(); } elseif ($operation instanceof UpdateOperation) { - $updates[] = $operation->getTargetPackage()->getPrettyName().':'.$operation->getTargetPackage()->getFullPrettyVersion(); + $installsUpdates[] = $operation; + $updateNames[] = $operation->getTargetPackage()->getPrettyName().':'.$operation->getTargetPackage()->getFullPrettyVersion(); } elseif ($operation instanceof UninstallOperation) { - $uninstalls[] = $operation->getPackage()->getPrettyName(); + $uninstalls[] = $operation; + $uninstallNames[] = $operation->getPackage()->getPrettyName(); } } $this->io->writeError(sprintf( "Lock file operations: %d install%s, %d update%s, %d removal%s", - count($installs), - 1 === count($installs) ? '' : 's', - count($updates), - 1 === count($updates) ? '' : 's', + count($installNames), + 1 === count($installNames) ? '' : 's', + count($updateNames), + 1 === count($updateNames) ? '' : 's', count($uninstalls), 1 === count($uninstalls) ? '' : 's' )); - if ($installs) { - $this->io->writeError("Installs: ".implode(', ', $installs), true, IOInterface::VERBOSE); + if ($installNames) { + $this->io->writeError("Installs: ".implode(', ', $installNames), true, IOInterface::VERBOSE); } - if ($updates) { - $this->io->writeError("Updates: ".implode(', ', $updates), true, IOInterface::VERBOSE); + if ($updateNames) { + $this->io->writeError("Updates: ".implode(', ', $updateNames), true, IOInterface::VERBOSE); } if ($uninstalls) { - $this->io->writeError("Removals: ".implode(', ', $uninstalls), true, IOInterface::VERBOSE); + $this->io->writeError("Removals: ".implode(', ', $uninstallNames), true, IOInterface::VERBOSE); } } - foreach ($lockTransaction->getOperations() as $operation) { + $sortByName = function ($a, $b) { + if ($a instanceof UpdateOperation) { + $a = $a->getTargetPackage()->getName(); + } else { + $a = $a->getPackage()->getName(); + } + if ($b instanceof UpdateOperation) { + $b = $b->getTargetPackage()->getName(); + } else { + $b = $b->getPackage()->getName(); + } + + return strcmp($a, $b); + }; + usort($uninstalls, $sortByName); + usort($installsUpdates, $sortByName); + + foreach (array_merge($uninstalls, $installsUpdates) as $operation) { // collect suggestions if ($operation instanceof InstallOperation) { $this->suggestedPackagesReporter->addSuggestionsFromPackage($operation->getPackage()); diff --git a/tests/Composer/Test/Fixtures/installer/install-funding-notice.test b/tests/Composer/Test/Fixtures/installer/install-funding-notice.test index bfac55518..7d10cc844 100644 --- a/tests/Composer/Test/Fixtures/installer/install-funding-notice.test +++ b/tests/Composer/Test/Fixtures/installer/install-funding-notice.test @@ -45,9 +45,9 @@ install Loading composer repositories with package information Updating dependencies Lock file operations: 3 installs, 0 updates, 0 removals + - Locking a/a (1.0.0) - Locking b/b (1.0.0) - Locking d/d (1.0.0) - - Locking a/a (1.0.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 3 installs, 0 updates, 0 removals diff --git a/tests/Composer/Test/Fixtures/installer/suggest-replaced.test b/tests/Composer/Test/Fixtures/installer/suggest-replaced.test index e56af5093..a0e90332e 100644 --- a/tests/Composer/Test/Fixtures/installer/suggest-replaced.test +++ b/tests/Composer/Test/Fixtures/installer/suggest-replaced.test @@ -22,8 +22,8 @@ update Loading composer repositories with package information Updating dependencies Lock file operations: 2 installs, 0 updates, 0 removals - - Locking c/c (1.0.0) - Locking a/a (1.0.0) + - Locking c/c (1.0.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 2 installs, 0 updates, 0 removals