From 10555ecff358e854596e21c21635bec877f4936d Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Fri, 24 Apr 2020 17:42:24 +0200 Subject: [PATCH] Make sure there's always a constraint --- src/Composer/DependencyResolver/PoolBuilder.php | 6 +----- src/Composer/DependencyResolver/Request.php | 3 ++- src/Composer/Package/Link.php | 5 +++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index 727f086d8..575e89ce6 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -294,10 +294,6 @@ class PoolBuilder $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.'); } } else { - if (null === $this->loadedNames[$require] || null === $linkConstraint) { - unset($this->loadedNames[$require]); - } - if (!$this->loadedNames[$require]->matches($linkConstraint)) { $loadNames[$require] = MultiConstraint::create(array($this->loadedNames[$require], $linkConstraint), false); unset($this->loadedNames[$require]); @@ -313,7 +309,7 @@ class PoolBuilder if (isset($this->loadedNames[$replace]) && isset($this->skippedLoad[$replace])) { if ($request->getUpdateAllowTransitiveRootDependencies() || !$this->isRootRequire($request, $this->skippedLoad[$replace])) { $this->unfixPackage($request, $replace); - $loadNames[$replace] = null; + $loadNames[$replace] = $link->getConstraint(); } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $replace) && !isset($this->updateAllowWarned[$replace])) { $this->updateAllowWarned[$replace] = true; $this->io->writeError('Dependency "'.$replace.'" 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.'); diff --git a/src/Composer/DependencyResolver/Request.php b/src/Composer/DependencyResolver/Request.php index 5782c3ff1..959ba884b 100644 --- a/src/Composer/DependencyResolver/Request.php +++ b/src/Composer/DependencyResolver/Request.php @@ -17,6 +17,7 @@ use Composer\Package\PackageInterface; use Composer\Package\RootAliasPackage; use Composer\Repository\LockArrayRepository; use Composer\Semver\Constraint\ConstraintInterface; +use Composer\Semver\Constraint\EmptyConstraint; /** * @author Nils Adermann @@ -55,7 +56,7 @@ class Request public function requireName($packageName, ConstraintInterface $constraint = null) { $packageName = strtolower($packageName); - $this->requires[$packageName] = $constraint; + $this->requires[$packageName] = $constraint ? $constraint : new EmptyConstraint(); } /** diff --git a/src/Composer/Package/Link.php b/src/Composer/Package/Link.php index 5a6c683cc..03ea3edff 100644 --- a/src/Composer/Package/Link.php +++ b/src/Composer/Package/Link.php @@ -13,6 +13,7 @@ namespace Composer\Package; use Composer\Semver\Constraint\ConstraintInterface; +use Composer\Semver\Constraint\EmptyConstraint; /** * Represents a link between two packages, represented by their names @@ -59,7 +60,7 @@ class Link { $this->source = strtolower($source); $this->target = strtolower($target); - $this->constraint = $constraint; + $this->constraint = $constraint ? $constraint : new EmptyConstraint(); $this->description = $description; $this->prettyConstraint = $prettyConstraint; } @@ -89,7 +90,7 @@ class Link } /** - * @return ConstraintInterface|null + * @return ConstraintInterface */ public function getConstraint() {