Rule generator cleanup: no need for 2 added package arrays, more specific root alias rule
parent
6b48258432
commit
4215344c93
|
@ -35,6 +35,7 @@ abstract class Rule
|
||||||
const RULE_PACKAGE_SAME_NAME = 10;
|
const RULE_PACKAGE_SAME_NAME = 10;
|
||||||
const RULE_LEARNED = 12;
|
const RULE_LEARNED = 12;
|
||||||
const RULE_PACKAGE_ALIAS = 13;
|
const RULE_PACKAGE_ALIAS = 13;
|
||||||
|
const RULE_PACKAGE_ROOT_ALIAS = 14;
|
||||||
|
|
||||||
// bitfield defs
|
// bitfield defs
|
||||||
const BITFIELD_TYPE = 0;
|
const BITFIELD_TYPE = 0;
|
||||||
|
@ -312,12 +313,20 @@ abstract class Rule
|
||||||
|
|
||||||
return 'Conclusion: '.$ruleText.$learnedString;
|
return 'Conclusion: '.$ruleText.$learnedString;
|
||||||
case self::RULE_PACKAGE_ALIAS:
|
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
|
// avoid returning content like "9999999-dev is an alias of dev-master" as it is useless
|
||||||
if ($aliasPackage->getVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
|
if ($aliasPackage->getVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
|
||||||
return '';
|
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.';
|
return $aliasPackage->getPrettyString() .' is an alias of '.$package->getPrettyString().' and thus requires it to be installed too.';
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -28,7 +28,6 @@ class RuleSetGenerator
|
||||||
protected $rules;
|
protected $rules;
|
||||||
protected $addedMap;
|
protected $addedMap;
|
||||||
protected $conflictAddedMap;
|
protected $conflictAddedMap;
|
||||||
protected $addedPackages;
|
|
||||||
protected $addedPackagesByNames;
|
protected $addedPackagesByNames;
|
||||||
protected $conflictsForName;
|
protected $conflictsForName;
|
||||||
|
|
||||||
|
@ -157,9 +156,8 @@ class RuleSetGenerator
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addedMap[$package->id] = true;
|
$this->addedMap[$package->id] = $package;
|
||||||
|
|
||||||
$this->addedPackages[] = $package;
|
|
||||||
if (!$package instanceof AliasPackage) {
|
if (!$package instanceof AliasPackage) {
|
||||||
foreach ($package->getNames(false) as $name) {
|
foreach ($package->getNames(false) as $name) {
|
||||||
$this->addedPackagesByNames[$name][] = $package;
|
$this->addedPackagesByNames[$name][] = $package;
|
||||||
|
@ -194,7 +192,7 @@ class RuleSetGenerator
|
||||||
protected function addConflictRules($ignorePlatformReqs = false)
|
protected function addConflictRules($ignorePlatformReqs = false)
|
||||||
{
|
{
|
||||||
/** @var PackageInterface $package */
|
/** @var PackageInterface $package */
|
||||||
foreach ($this->addedPackages as $package) {
|
foreach ($this->addedMap as $package) {
|
||||||
foreach ($package->getConflicts() as $link) {
|
foreach ($package->getConflicts() as $link) {
|
||||||
if (!isset($this->addedPackagesByNames[$link->getTarget()])) {
|
if (!isset($this->addedPackagesByNames[$link->getTarget()])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -268,8 +266,8 @@ class RuleSetGenerator
|
||||||
// if it is a root alias, make sure that if the aliased version gets installed
|
// if it is a root alias, make sure that if the aliased version gets installed
|
||||||
// the alias must be installed too
|
// the alias must be installed too
|
||||||
if ($package instanceof AliasPackage && $package->isRootPackageAlias() && isset($this->addedMap[$package->getAliasOf()->id])) {
|
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->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->addedMap = array();
|
||||||
$this->conflictAddedMap = array();
|
$this->conflictAddedMap = array();
|
||||||
$this->addedPackages = array();
|
|
||||||
$this->addedPackagesByNames = array();
|
$this->addedPackagesByNames = array();
|
||||||
$this->conflictsForName = array();
|
$this->conflictsForName = array();
|
||||||
|
|
||||||
|
@ -294,7 +291,7 @@ class RuleSetGenerator
|
||||||
$this->addConflictRules($ignorePlatformReqs);
|
$this->addConflictRules($ignorePlatformReqs);
|
||||||
|
|
||||||
// Remove references to packages
|
// Remove references to packages
|
||||||
$this->addedPackages = $this->addedPackagesByNames = null;
|
$this->addedMap = $this->addedPackagesByNames = null;
|
||||||
|
|
||||||
return $this->rules;
|
return $this->rules;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue