1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 09:02:59 +00:00

Add better error reporting for cases where a package conflicts with a replace and not directly a package, fixes #9834

This commit is contained in:
Jordi Boggiano 2021-06-02 10:02:34 +02:00
parent b751156e1c
commit 1f37d1c1d5
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
5 changed files with 206 additions and 1 deletions

View file

@ -211,7 +211,40 @@ abstract class Rule
$package1 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[0]));
$package2 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1]));
return $package2->getPrettyString().' conflicts with '.$package1->getPrettyString().'.';
$conflictTarget = $package1->getPrettyString();
if ($reasonData = $this->getReasonData()) {
// swap literals if they are not in the right order with package2 being the conflicter
if ($reasonData->getSource() === $package1->getName()) {
list($package2, $package1) = array($package1, $package2);
}
// if the conflict is not directly against the package but something it provides/replaces,
// we try to find that link to display a better message
if ($reasonData->getTarget() !== $package1->getName()) {
$provideType = null;
$provided = null;
foreach ($package1->getProvides() as $provide) {
if ($provide->getTarget() === $reasonData->getTarget()) {
$provideType = 'provides';
$provided = $provide->getPrettyConstraint();
break;
}
}
foreach ($package1->getReplaces() as $replace) {
if ($replace->getTarget() === $reasonData->getTarget()) {
$provideType = 'replaces';
$provided = $replace->getPrettyConstraint();
break;
}
}
if (null !== $provideType) {
$conflictTarget = $reasonData->getTarget().' '.$reasonData->getPrettyConstraint().' ('.$package1->getPrettyString().' '.$provideType.' '.$reasonData->getTarget().' '.$provided.')';
}
}
}
return $package2->getPrettyString().' conflicts with '.$conflictTarget.'.';
case self::RULE_PACKAGE_REQUIRES:
$sourceLiteral = array_shift($literals);