From c270d3cfa6c677bd92db046bf6ff58018e2e42be Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 1 Apr 2020 15:27:51 +0200 Subject: [PATCH] PoolBuilder: make io non-nullable, NullIO can be used instead --- .../DependencyResolver/PoolBuilder.php | 40 +++++++++---------- src/Composer/Installer.php | 4 +- src/Composer/Repository/RepositorySet.php | 7 ++-- .../DependencyResolver/PoolBuilderTest.php | 2 +- .../Test/DependencyResolver/SolverTest.php | 5 ++- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index 06c50bdeb..36c991816 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -48,7 +48,7 @@ class PoolBuilder private $skippedLoad = array(); private $updateAllowWarned = array(); - public function __construct(array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences, EventDispatcher $eventDispatcher = null, IOInterface $io = null) + public function __construct(array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences, IOInterface $io = null, EventDispatcher $eventDispatcher = null) { $this->acceptableStabilities = $acceptableStabilities; $this->stabilityFlags = $stabilityFlags; @@ -244,7 +244,7 @@ class PoolBuilder if ($request->getUpdateAllowTransitiveRootDependencies() || !$this->isRootRequire($request, $require)) { $this->unfixPackage($request, $require); $loadNames[$require] = null; - } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $require) && !isset($this->updateAllowWarned[$require]) && $this->io) { + } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $require) && !isset($this->updateAllowWarned[$require])) { $this->updateAllowWarned[$require] = true; $this->io->writeError('Dependency "'.$require.'" is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies to include root dependencies.'); } @@ -275,7 +275,7 @@ class PoolBuilder $loadNames[$replace] = null; // TODO should we try to merge constraints here? $this->nameConstraints[$replace] = null; - } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $replace) && !isset($this->updateAllowWarned[$require]) && $this->io) { + } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $replace) && !isset($this->updateAllowWarned[$require])) { $this->updateAllowWarned[$replace] = true; $this->io->writeError('Dependency "'.$require.'" is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies to include root dependencies.'); } @@ -315,27 +315,25 @@ class PoolBuilder private function warnAboutNonMatchingUpdateAllowList(Request $request) { - if ($this->io) { - foreach ($this->updateAllowList as $pattern => $void) { - $patternRegexp = BasePackage::packageNameToRegexp($pattern); - // update pattern matches a locked package? => all good - foreach ($request->getLockedRepository()->getPackages() as $package) { - if (preg_match($patternRegexp, $package->getName())) { - continue 2; - } + foreach ($this->updateAllowList as $pattern => $void) { + $patternRegexp = BasePackage::packageNameToRegexp($pattern); + // update pattern matches a locked package? => all good + foreach ($request->getLockedRepository()->getPackages() as $package) { + if (preg_match($patternRegexp, $package->getName())) { + continue 2; } - // update pattern matches a root require? => all good, probably a new package - foreach ($request->getRequires() as $packageName => $constraint) { - if (preg_match($patternRegexp, $packageName)) { - continue 2; - } - } - if (strpos($pattern, '*') !== false) { - $this->io->writeError('Pattern "' . $pattern . '" listed for update does not match any locked packages.'); - } else { - $this->io->writeError('Package "' . $pattern . '" listed for update is not locked.'); + } + // update pattern matches a root require? => all good, probably a new package + foreach ($request->getRequires() as $packageName => $constraint) { + if (preg_match($patternRegexp, $packageName)) { + continue 2; } } + if (strpos($pattern, '*') !== false) { + $this->io->writeError('Pattern "' . $pattern . '" listed for update does not match any locked packages.'); + } else { + $this->io->writeError('Package "' . $pattern . '" listed for update is not locked.'); + } } } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 500a9a827..3937a15b0 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -393,7 +393,7 @@ class Installer $request->setUpdateAllowList($this->updateAllowList, $this->updateAllowTransitiveDependencies); } - $pool = $repositorySet->createPool($request, $this->eventDispatcher, $this->io); + $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher); // solve dependencies $solver = new Solver($policy, $pool, $this->io, $repositorySet); @@ -612,7 +612,7 @@ class Installer $request->requireName($link->getTarget(), $link->getConstraint()); } - $pool = $repositorySet->createPool($request, $this->eventDispatcher, $this->io); + $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher); // solve dependencies $solver = new Solver($policy, $pool, $this->io, $repositorySet); diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index 7e5d6437d..b0489e99b 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -17,6 +17,7 @@ use Composer\DependencyResolver\PoolBuilder; use Composer\DependencyResolver\Request; use Composer\EventDispatcher\EventDispatcher; use Composer\IO\IOInterface; +use Composer\IO\NullIO; use Composer\Package\BasePackage; use Composer\Package\Version\VersionParser; use Composer\Repository\CompositeRepository; @@ -186,9 +187,9 @@ class RepositorySet * * @return Pool */ - public function createPool(Request $request, EventDispatcher $eventDispatcher = null, IOInterface $io = null) + public function createPool(Request $request, IOInterface $io, EventDispatcher $eventDispatcher = null) { - $poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $eventDispatcher, $io); + $poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $io, $eventDispatcher); foreach ($this->repositories as $repo) { if (($repo instanceof InstalledRepositoryInterface || $repo instanceof InstalledRepository) && !$this->allowInstalledRepositories) { @@ -237,6 +238,6 @@ class RepositorySet $request->requireName($packageName); } - return $this->createPool($request); + return $this->createPool($request, new NullIO()); } } diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index c55431b6e..f51661db6 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -89,7 +89,7 @@ class PoolBuilderTest extends TestCase $request->fixPackage($loadPackage($fixedPackage)); } - $pool = $repositorySet->createPool($request); + $pool = $repositorySet->createPool($request, new NullIO()); for ($i = 1, $count = count($pool); $i <= $count; $i++) { $result[] = $pool->packageById($i); } diff --git a/tests/Composer/Test/DependencyResolver/SolverTest.php b/tests/Composer/Test/DependencyResolver/SolverTest.php index 46d882e9f..3090d9d83 100644 --- a/tests/Composer/Test/DependencyResolver/SolverTest.php +++ b/tests/Composer/Test/DependencyResolver/SolverTest.php @@ -890,8 +890,9 @@ class SolverTest extends TestCase protected function createSolver() { - $this->pool = $this->repoSet->createPool($this->request); - $this->solver = new Solver($this->policy, $this->pool, new NullIO()); + $io = new NullIO(); + $this->pool = $this->repoSet->createPool($this->request, $io); + $this->solver = new Solver($this->policy, $this->pool, $io); } protected function checkSolverResult(array $expected)