mirror of
https://github.com/composer/composer
synced 2025-05-10 17:12:51 +00:00
Avoid some error paths, refs #6678
This commit is contained in:
parent
b94d55d1a9
commit
7c7c91344a
1 changed files with 11 additions and 1 deletions
|
@ -644,6 +644,7 @@ EOT
|
|||
'Could not find package %s at any version matching your PHP version %s', $name, $phpVersion
|
||||
));
|
||||
}
|
||||
|
||||
$similar = $this->findSimilar($name);
|
||||
if ($similar) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
|
@ -652,6 +653,7 @@ EOT
|
|||
implode("\n ", $similar)
|
||||
));
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Could not find package %s at any version for your minimum-stability (%s). Check the package spelling or your minimum-stability',
|
||||
$name,
|
||||
|
@ -664,11 +666,19 @@ EOT
|
|||
|
||||
private function findSimilar($package)
|
||||
{
|
||||
try {
|
||||
$results = $this->repos->search($package);
|
||||
} catch (\Exception $e) {
|
||||
// ignore search errors
|
||||
return array();
|
||||
}
|
||||
$similarPackages = array();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$similarPackages[$result['name']] = levenshtein($package, $result['name']);
|
||||
}
|
||||
asort($similarPackages);
|
||||
|
||||
return array_keys(array_slice($similarPackages, 0, 5));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue