function PoolOptimizer::optimizeImpossiblePackagesAway
Use the list of locked packages to constrain the loaded packages This will reduce packages with significant numbers of historical versions to a smaller number and reduce the resulting rule set that is generated
1 call to PoolOptimizer::optimizeImpossiblePackagesAway()
- PoolOptimizer::optimize in vendor/
composer/ composer/ src/ Composer/ DependencyResolver/ PoolOptimizer.php
File
-
vendor/
composer/ composer/ src/ Composer/ DependencyResolver/ PoolOptimizer.php, line 372
Class
- PoolOptimizer
- Optimizes a given pool
Namespace
Composer\DependencyResolverCode
private function optimizeImpossiblePackagesAway(Request $request, Pool $pool) : void {
if (\count($request->getLockedPackages()) === 0) {
return;
}
$packageIndex = [];
foreach ($pool->getPackages() as $package) {
$id = $package->id;
// Do not remove irremovable packages
if (isset($this->irremovablePackages[$id])) {
continue;
}
// Do not remove a package aliased by another package, nor aliases
if (isset($this->aliasesPerPackage[$id]) || $package instanceof AliasPackage) {
continue;
}
// Do not remove locked packages
if ($request->isFixedPackage($package) || $request->isLockedPackage($package)) {
continue;
}
$packageIndex[$package->getName()][$package->id] = $package;
}
foreach ($request->getLockedPackages() as $package) {
// If this locked package is no longer required by root or anything in the pool, it may get uninstalled so do not apply its requirements
// In a case where a requirement WERE to appear in the pool by a package that would not be used, it would've been unlocked and so not filtered still
$isUnusedPackage = true;
foreach ($package->getNames(false) as $packageName) {
if (isset($this->requireConstraintsPerPackage[$packageName])) {
$isUnusedPackage = false;
break;
}
}
if ($isUnusedPackage) {
continue;
}
foreach ($package->getRequires() as $link) {
$require = $link->getTarget();
if (!isset($packageIndex[$require])) {
continue;
}
$linkConstraint = $link->getConstraint();
foreach ($packageIndex[$require] as $id => $requiredPkg) {
if (false === CompilingMatcher::match($linkConstraint, Constraint::OP_EQ, $requiredPkg->getVersion())) {
$this->markPackageForRemoval($id);
unset($packageIndex[$require][$id]);
}
}
}
}
}