1
0
Fork 0

Improve error reporting in require command, fixes invalid case of consistency issue, fixes #10006

pull/10016/head
Jordi Boggiano 2021-07-21 14:38:10 +02:00
parent 79093d664b
commit f5a03b950d
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 18 additions and 8 deletions

View File

@ -842,6 +842,7 @@ EOT
// find the latest version allowed in this repo set // find the latest version allowed in this repo set
$versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability), $platformRepo); $versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability), $platformRepo);
$effectiveMinimumStability = $minimumStability ?: $this->getMinimumStability($input);
$package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs); $package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs);
@ -872,7 +873,7 @@ EOT
throw new \InvalidArgumentException(sprintf( 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.', '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, $name,
$this->getMinimumStability($input) $effectiveMinimumStability
)); ));
} }
// Check whether the required version was the problem // Check whether the required version was the problem
@ -885,16 +886,22 @@ EOT
} }
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(
'Could not find package %s in a version matching %s', 'Could not find package %s in a version matching "%s" and a stability matching "'.$effectiveMinimumStability.'".',
$name, $name,
$requiredVersion $requiredVersion
)); ));
} }
// Check whether the PHP version was the problem for all versions // Check whether the PHP version was the problem for all versions
if (true !== $ignorePlatformReqs && ($candidate = $versionSelector->findBestCandidate($name, null, $preferredStability, true))) { if (true !== $ignorePlatformReqs && ($candidate = $versionSelector->findBestCandidate($name, null, $preferredStability, true, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES))) {
$additional = '';
if (false === $versionSelector->findBestCandidate($name, null, $preferredStability, true)) {
$additional = PHP_EOL.PHP_EOL.'Additionally, the package was only found with a stability of "'.$candidate->getStability().'" while your minimum stability is "'.$effectiveMinimumStability.'".';
}
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(
'Could not find package %s in any version matching your PHP version, PHP extensions and Composer version' . $this->getPlatformExceptionDetails($candidate, $platformRepo), 'Could not find package %s in any version matching your PHP version, PHP extensions and Composer version' . $this->getPlatformExceptionDetails($candidate, $platformRepo) . '%s',
$name $name,
$additional
)); ));
} }
@ -918,7 +925,7 @@ EOT
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(
'Could not find a matching version of package %s. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (%s).', 'Could not find a matching version of package %s. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (%s).',
$name, $name,
$this->getMinimumStability($input) $effectiveMinimumStability
)); ));
} }
@ -936,9 +943,12 @@ EOT
} }
foreach ($candidate->getRequires() as $link) { foreach ($candidate->getRequires() as $link) {
if (!PlatformRepository::isPlatformPackage($link->getTarget())) {
continue;
}
$platformPkg = $platformRepo->findPackage($link->getTarget(), '*'); $platformPkg = $platformRepo->findPackage($link->getTarget(), '*');
if (!$platformPkg) { if (!$platformPkg) {
$details[] = $candidate->getName().' requires '.$link->getTarget().' '.$link->getPrettyConstraint().' but it is not present.'; $details[] = $candidate->getPrettyName().' '.$candidate->getPrettyVersion().' requires '.$link->getTarget().' '.$link->getPrettyConstraint().' but it is not present.';
continue; continue;
} }
if (!$link->getConstraint()->matches(new Constraint('==', $platformPkg->getVersion()))) { if (!$link->getConstraint()->matches(new Constraint('==', $platformPkg->getVersion()))) {
@ -947,7 +957,7 @@ EOT
if (isset($platformExtra['config.platform']) && $platformPkg instanceof CompletePackageInterface) { if (isset($platformExtra['config.platform']) && $platformPkg instanceof CompletePackageInterface) {
$platformPkgVersion .= ' ('.$platformPkg->getDescription().')'; $platformPkgVersion .= ' ('.$platformPkg->getDescription().')';
} }
$details[] = $candidate->getName().' requires '.$link->getTarget().' '.$link->getPrettyConstraint().' which does not match your installed version '.$platformPkgVersion.'.'; $details[] = $candidate->getPrettyName().' '.$candidate->getPrettyVersion().' requires '.$link->getTarget().' '.$link->getPrettyConstraint().' which does not match your installed version '.$platformPkgVersion.'.';
} }
} }