From 9452a94e30d32bd4a3b8bf260c8fadf29ace967c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Dec 2011 16:37:41 +0100 Subject: [PATCH] Fix regression in previous merge --- src/Composer/Command/ShowCommand.php | 43 +++++++++++++--------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 07a70d7fb..0cc7abe89 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -70,14 +70,31 @@ EOT return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version')); } - // we only have a name, so search for the highest package where the name matches + // check if we have a local installation so we can grab the right package/version + $localRepo = $composer->getRepositoryManager()->getLocalRepository(); + foreach ($localRepo->getPackages() as $package) { + if ($package->getName() === $input->getArgument('package')) { + return $package; + } + } + + // we only have a name, so search for the highest version of the given package + $highestVersion = null; $repos = array_merge( array($composer->getRepositoryManager()->getLocalRepository()), $composer->getRepositoryManager()->getRepositories() ); - if ($package = $this->getHighestVersion($repos, $input->getArgument('package'))) { - return $package; + foreach ($repos as $repository) { + foreach ($repository->getPackages() as $package) { + if ($packageName === $package->getName()) { + if (null === $highestVersion || version_compare($package->getVersion(), $highestVersion->getVersion(), '>=')) { + $highestVersion = $package; + } + } + } } + + return $highestVersion; } /** @@ -150,24 +167,4 @@ EOT } } } - - /** - * get highest matching package name from an array of repositories - */ - protected function getHighestVersion(array $repos, $packageName) - { - $highest = null; - - foreach ($repos as $repository) { - foreach ($repository->getPackages() as $package) { - if ($packageName === $package->getName()) { - if (null === $highest || version_compare($package->getVersion(), $highest->getVersion(), '>=')) { - $highest = $package; - } - } - } - } - - return $highest; - } } \ No newline at end of file