1
0
Fork 0

Merge remote-tracking branch 'xy2z/has-package-name'

pull/8538/head
Jordi Boggiano 2020-01-14 14:33:01 +01:00
commit c0714e5ff8
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 35 additions and 0 deletions

View File

@ -438,11 +438,40 @@ EOT
}
$versionParser = new VersionParser();
$composer = $this->getComposer(false);
$installedRepo = ($composer) ? $composer->getRepositoryManager()->getLocalRepository() : null;
$io = $this->getIO();
while (null !== $package = $io->ask('Search for a package: ')) {
$matches = $this->findPackages($package);
if (count($matches)) {
// Exclude existing packages
$existingPackages = [];
foreach ($matches as $position => $foundPackage) {
if ($installedRepo && $installedRepo->findPackage($foundPackage['name'], '*')) {
$existingPackages[] = $position;
continue;
}
foreach ($requires as $requiredPackage) {
$existingPackageName = substr($requiredPackage, 0, strpos($requiredPackage, ' '));
if ($foundPackage['name'] == $existingPackageName) {
$existingPackages[] = $position;
break;
}
}
}
// Remove existing packages from search results.
if (!empty($existingPackages)) {
foreach ($existingPackages as $position) {
unset($matches[$position]);
}
$matches = array_values($matches);
}
$exactMatch = null;
$choices = array();
foreach ($matches as $position => $foundPackage) {
@ -794,7 +823,13 @@ EOT
}
$similarPackages = array();
$installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
foreach ($results as $result) {
if ($installedRepo->findPackage($result['name'], '*')) {
// Ignore installed package
continue;
}
$similarPackages[$result['name']] = levenshtein($package, $result['name']);
}
asort($similarPackages);