1
0
Fork 0

Ensure multi conflict rules are only used for 3+ literals

Implements the equals method correctly on multi conflict rules. If there
are fewer literals a regular Rule2Literals is enough to represent the
basic conflict rule.
pull/8424/head
Nils Adermann 2019-11-12 22:19:32 +01:00
parent ed300b9f22
commit dc0f2e7e46
2 changed files with 12 additions and 1 deletions

View File

@ -34,6 +34,10 @@ class MultiConflictRule extends Rule
{
parent::__construct($reason, $reasonData, $job);
if (count($literals) < 3) {
throw new \RuntimeException("multi conflict rule requires at least 3 literals");
}
// sort all packages ascending by id
sort($literals);
@ -62,7 +66,10 @@ class MultiConflictRule extends Rule
*/
public function equals(Rule $rule)
{
return $this->literals === $rule->getLiterals();
if ($rule instanceof MultiConflictRule) {
return $this->literals === $rule->getLiterals();
}
return false;
}
public function isAssertion()

View File

@ -136,6 +136,10 @@ class RuleSetGenerator
$literals[] = -$package->id;
}
if (count($literals) == 2) {
return new Rule2Literals($literals[0], $literals[1], $reason, $reasonData);
}
return new MultiConflictRule($literals, $reason, $reasonData);
}