From 80be9a2c981373c77af2c37edfbb546816d3413f Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 15 Mar 2016 20:46:00 +0100 Subject: [PATCH 1/3] Add deprecated notice to show command --- src/Composer/Command/ShowCommand.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 1c2a3e9ea..4cc611963 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -294,6 +294,22 @@ EOT $path = strtok(realpath($composer->getInstallationManager()->getInstallPath($package)), "\r\n"); $io->write(' ' . $path, false); } + + if ($showLatest && $package->isAbandoned()) { + $replacement = (is_string($package->getReplacementPackage())) + ? 'Use ' . $package->getReplacementPackage() . ' instead' + : 'No replacement was suggested'; + + $io->write(''); + $io->write( + sprintf( + "Package %s is abandoned, you should avoid using it. %s.", + $package->getPrettyName(), + $replacement + ), + false + ); + } } else { $io->write($indent . $package, false); } From 54d86ebfc9e5eeda56d193bf4ba0dbf3c2beff20 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 16 Mar 2016 10:19:38 +0100 Subject: [PATCH 2/3] Use latest package for deprecations, cache latest packages --- src/Composer/Command/ShowCommand.php | 51 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 4cc611963..6d6871b3b 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -154,11 +154,11 @@ EOT if ($input->getOption('tree')) { $this->displayPackageTree($package, $installedRepo, $repos); } else { - $latestVersion = null; + $latestPackage = null; if ($input->getOption('latest')) { - $latestVersion = $this->findBestVersionForPackage($package->getName(), null); + $latestPackage = $this->findLatestPackages($package->getName()); } - $this->printMeta($package, $versions, $installedRepo, $latestVersion); + $this->printMeta($package, $versions, $installedRepo, $latestPackage); $this->printLinks($package, 'requires'); $this->printLinks($package, 'devRequires', 'requires (dev)'); if ($package->getSuggests()) { @@ -231,6 +231,7 @@ EOT $showAllTypes = $input->getOption('all'); $showLatest = $input->getOption('latest'); $indent = $showAllTypes ? ' ' : ''; + $latestPackages = array(); foreach (array('platform:' => true, 'available:' => false, 'installed:' => true) as $type => $showVersion) { if (isset($packages[$type])) { if ($showAllTypes) { @@ -243,6 +244,11 @@ EOT if (is_object($package)) { $nameLength = max($nameLength, strlen($package->getPrettyName())); $versionLength = max($versionLength, strlen($package->getFullPrettyVersion())); + if ($showLatest) { + $latestPackage = $this->findLatestPackages($package->getName()); + $latestPackages[$package->getPrettyName()] = $latestPackage; + $latestLength = max($latestLength, strlen($latestPackage->getFullPrettyVersion())); + } } else { $nameLength = max($nameLength, $package); } @@ -262,7 +268,6 @@ EOT $input->setOption('path', false); } - $latestLength = $versionLength; $writePath = !$input->getOption('name-only') && $input->getOption('path'); $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width); $writeLatest = !$input->getOption('name-only') && !$input->getOption('path') && $showLatest && ($nameLength + ($showVersion ? $versionLength : 0) + $latestLength + 3 <= $width); @@ -275,8 +280,13 @@ EOT $io->write(' ' . str_pad($package->getFullPrettyVersion(), $versionLength, ' '), false); } - if ($writeLatest) { - $latestVersion = $this->findBestVersionForPackage($package->getName()); + $latestPackackage = null; + if ($showLatest && isset($latestPackages[$package->getPrettyName()])) { + $latestPackackage = $latestPackages[$package->getPrettyName()]; + } + + if ($writeLatest && $latestPackackage) { + $latestVersion = $latestPackackage->getFullPrettyVersion(); $type = $latestVersion == $package->getFullPrettyVersion() ? 'info' : 'comment'; $io->write(' <'.$type.'>' . str_pad($latestVersion, $latestLength, ' ') . '', false); } @@ -295,9 +305,9 @@ EOT $io->write(' ' . $path, false); } - if ($showLatest && $package->isAbandoned()) { - $replacement = (is_string($package->getReplacementPackage())) - ? 'Use ' . $package->getReplacementPackage() . ' instead' + if ($latestPackackage && $latestPackackage->isAbandoned()) { + $replacement = (is_string($latestPackackage->getReplacementPackage())) + ? 'Use ' . $latestPackackage->getReplacementPackage() . ' instead' : 'No replacement was suggested'; $io->write(''); @@ -371,15 +381,17 @@ EOT /** * prints package meta data */ - protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, $latestVersion = null) + protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, PackageInterface $latestPackage = null) { $io = $this->getIO(); $io->write('name : ' . $package->getPrettyName()); $io->write('descrip. : ' . $package->getDescription()); $io->write('keywords : ' . join(', ', $package->getKeywords() ?: array())); $this->printVersions($package, $versions, $installedRepo); - if ($latestVersion) { - $io->write('latest : ' . $latestVersion); + if ($latestPackage) { + $io->write('latest : ' . $latestPackage->getPrettyVersion()); + } else { + $latestPackage = $package; } $io->write('type : ' . $package->getType()); $this->printLicenses($package); @@ -387,9 +399,9 @@ EOT $io->write('dist : ' . sprintf('[%s] %s %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference())); $io->write('names : ' . implode(', ', $package->getNames())); - if ($package->isAbandoned()) { - $replacement = ($package->getReplacementPackage() !== null) - ? ' The author suggests using the ' . $package->getReplacementPackage(). ' package instead.' + if ($latestPackage->isAbandoned()) { + $replacement = ($latestPackage->getReplacementPackage() !== null) + ? ' The author suggests using the ' . $latestPackage->getReplacementPackage(). ' package instead.' : null; $io->writeError( @@ -618,17 +630,14 @@ EOT * * @param string $name * @throws \InvalidArgumentException - * @return string|null + * @return PackageInterface|null */ - private function findBestVersionForPackage($name) + private function findLatestPackages($name) { // find the latest version allowed in this pool $versionSelector = new VersionSelector($this->getPool()); - $package = $versionSelector->findBestCandidate($name); - if ($package) { - return $package->getPrettyVersion(); - } + return $versionSelector->findBestCandidate($name); } protected function getRepos() From fd46c7e4bae9ff10a2fbf8956bba38354be5f816 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 16 Mar 2016 11:04:37 +0100 Subject: [PATCH 3/3] Reduce line length --- src/Composer/Command/ShowCommand.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 6d6871b3b..fff5a77ad 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -243,11 +243,13 @@ EOT foreach ($packages[$type] as $package) { if (is_object($package)) { $nameLength = max($nameLength, strlen($package->getPrettyName())); - $versionLength = max($versionLength, strlen($package->getFullPrettyVersion())); - if ($showLatest) { - $latestPackage = $this->findLatestPackages($package->getName()); - $latestPackages[$package->getPrettyName()] = $latestPackage; - $latestLength = max($latestLength, strlen($latestPackage->getFullPrettyVersion())); + if ($showVersion) { + $versionLength = max($versionLength, strlen($package->getFullPrettyVersion())); + if ($showLatest) { + $latestPackage = $this->findLatestPackages($package->getName()); + $latestPackages[$package->getPrettyName()] = $latestPackage; + $latestLength = max($latestLength, strlen($latestPackage->getFullPrettyVersion())); + } } } else { $nameLength = max($nameLength, $package); @@ -270,8 +272,8 @@ EOT $writePath = !$input->getOption('name-only') && $input->getOption('path'); $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width); - $writeLatest = !$input->getOption('name-only') && !$input->getOption('path') && $showLatest && ($nameLength + ($showVersion ? $versionLength : 0) + $latestLength + 3 <= $width); - $writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + ($showVersion ? $versionLength : 0) + ($showLatest ? $latestLength : 0) + 24 <= $width); + $writeLatest = $writeVersion && $showLatest && ($nameLength + $versionLength + $latestLength + 3 <= $width); + $writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + $versionLength + $latestLength + 24 <= $width); foreach ($packages[$type] as $package) { if (is_object($package)) { $io->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false); @@ -293,7 +295,10 @@ EOT if ($writeDescription) { $description = strtok($package->getDescription(), "\r\n"); - $remaining = $width - $nameLength - $versionLength - ($writeLatest ? $latestLength : 0) - 4; + $remaining = $width - $nameLength - $versionLength - 4; + if ($writeLatest) { + $remaining -= $latestLength; + } if (strlen($description) > $remaining) { $description = substr($description, 0, $remaining - 3) . '...'; }