Rule generator cleanup: no need for 2 added package arrays, more specific root alias rule

main
Nils Adermann 4 years ago
parent 6b48258432
commit 4215344c93

@ -35,6 +35,7 @@ abstract class Rule
const RULE_PACKAGE_SAME_NAME = 10;
const RULE_LEARNED = 12;
const RULE_PACKAGE_ALIAS = 13;
const RULE_PACKAGE_ROOT_ALIAS = 14;
// bitfield defs
const BITFIELD_TYPE = 0;
@ -312,12 +313,20 @@ abstract class Rule
return 'Conclusion: '.$ruleText.$learnedString;
case self::RULE_PACKAGE_ALIAS:
$aliasPackage = $pool->literalToPackage($literals[0]);
case self::RULE_PACKAGE_ROOT_ALIAS:
if ($this->getReason() === self::RULE_PACKAGE_ALIAS) {
$aliasPackage = $pool->literalToPackage($literals[0]);
$otherLiteral = 1;
} else {
// root alias rules work the other way around
$aliasPackage = $pool->literalToPackage($literals[1]);
$otherLiteral = 0;
}
// avoid returning content like "9999999-dev is an alias of dev-master" as it is useless
if ($aliasPackage->getVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
return '';
}
$package = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1]));
$package = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[$otherLiteral]));
return $aliasPackage->getPrettyString() .' is an alias of '.$package->getPrettyString().' and thus requires it to be installed too.';
default:

@ -28,7 +28,6 @@ class RuleSetGenerator
protected $rules;
protected $addedMap;
protected $conflictAddedMap;
protected $addedPackages;
protected $addedPackagesByNames;
protected $conflictsForName;
@ -157,9 +156,8 @@ class RuleSetGenerator
continue;
}
$this->addedMap[$package->id] = true;
$this->addedMap[$package->id] = $package;
$this->addedPackages[] = $package;
if (!$package instanceof AliasPackage) {
foreach ($package->getNames(false) as $name) {
$this->addedPackagesByNames[$name][] = $package;
@ -194,7 +192,7 @@ class RuleSetGenerator
protected function addConflictRules($ignorePlatformReqs = false)
{
/** @var PackageInterface $package */
foreach ($this->addedPackages as $package) {
foreach ($this->addedMap as $package) {
foreach ($package->getConflicts() as $link) {
if (!isset($this->addedPackagesByNames[$link->getTarget()])) {
continue;
@ -268,8 +266,8 @@ class RuleSetGenerator
// if it is a root alias, make sure that if the aliased version gets installed
// the alias must be installed too
if ($package instanceof AliasPackage && $package->isRootPackageAlias() && isset($this->addedMap[$package->getAliasOf()->id])) {
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createRequireRule($package->getAliasOf(), array($package), Rule::RULE_PACKAGE_REQUIRES, $package->getAliasOf()));
$this->addRulesForPackage($package, $ignorePlatformReqs);
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createRequireRule($package->getAliasOf(), array($package), Rule::RULE_PACKAGE_ALIAS, $package->getAliasOf()));
}
}
}
@ -283,7 +281,6 @@ class RuleSetGenerator
$this->addedMap = array();
$this->conflictAddedMap = array();
$this->addedPackages = array();
$this->addedPackagesByNames = array();
$this->conflictsForName = array();
@ -294,7 +291,7 @@ class RuleSetGenerator
$this->addConflictRules($ignorePlatformReqs);
// Remove references to packages
$this->addedPackages = $this->addedPackagesByNames = null;
$this->addedMap = $this->addedPackagesByNames = null;
return $this->rules;
}

Loading…
Cancel
Save