1
0
Fork 0

Fix warnings in composer require to show when repo prio is at fault, refs #9371

pull/9384/head
Jordi Boggiano 2020-10-30 13:55:45 +01:00
parent 41daf69c87
commit ffc0f86fc0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 25 additions and 12 deletions

View File

@ -746,8 +746,30 @@ EOT
$requiredVersion ? ' at version '.$requiredVersion : ''
));
}
// Check whether the minimum stability was the problem but the package exists
if ($package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES)) {
// we must first verify if a valid package would be found in a lower priority repository
if ($allReposPackage = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) {
throw new \InvalidArgumentException(
'Package '.$name.' exists in '.$allReposPackage->getRepository()->getRepoName().' and '.$package->getRepository()->getRepoName().' which has a higher repository priority. The packages with higher priority do not match your minimum-stability and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.'
);
}
throw new \InvalidArgumentException(sprintf(
'Could not find a version of package %s matching your minimum-stability (%s). Require it with an explicit version constraint allowing its desired stability.',
$name,
$this->getMinimumStability($input)
));
}
// Check whether the required version was the problem
if ($requiredVersion && $versionSelector->findBestCandidate($name, null, $preferredStability, $ignorePlatformReqs)) {
if ($requiredVersion && $package = $versionSelector->findBestCandidate($name, null, $preferredStability, $ignorePlatformReqs)) {
// we must first verify if a valid package would be found in a lower priority repository
if ($allReposPackage = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, false, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) {
throw new \InvalidArgumentException(
'Package '.$name.' exists in '.$allReposPackage->getRepository()->getRepoName().' and '.$package->getRepository()->getRepoName().' which has a higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.'
);
}
throw new \InvalidArgumentException(sprintf(
'Could not find package %s in a version matching %s',
$name,
@ -765,15 +787,6 @@ EOT
// Check for similar names/typos
$similar = $this->findSimilar($name);
if ($similar) {
// Check whether the minimum stability was the problem but the package exists
if ($requiredVersion === null && in_array($name, $similar, true)) {
throw new \InvalidArgumentException(sprintf(
'Could not find a version of package %s matching your minimum-stability (%s). Require it with an explicit version constraint allowing its desired stability.',
$name,
$this->getMinimumStability($input)
));
}
throw new \InvalidArgumentException(sprintf(
"Could not find package %s.\n\nDid you mean " . (count($similar) > 1 ? 'one of these' : 'this') . "?\n %s",
$name,

View File

@ -60,7 +60,7 @@ class VersionSelector
* @param bool|array $ignorePlatformReqs
* @return PackageInterface|false
*/
public function findBestCandidate($packageName, $targetPackageVersion = null, $preferredStability = 'stable', $ignorePlatformReqs = false)
public function findBestCandidate($packageName, $targetPackageVersion = null, $preferredStability = 'stable', $ignorePlatformReqs = false, $repoSetFlags = 0)
{
if (!isset(BasePackage::$stabilities[$preferredStability])) {
// If you get this, maybe you are still relying on the Composer 1.x signature where the 3rd arg was the php version
@ -68,7 +68,7 @@ class VersionSelector
}
$constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null;
$candidates = $this->repositorySet->findPackages(strtolower($packageName), $constraint);
$candidates = $this->repositorySet->findPackages(strtolower($packageName), $constraint, $repoSetFlags);
if ($this->platformConstraints && true !== $ignorePlatformReqs) {
$platformConstraints = $this->platformConstraints;