From 92aed041e4b06db5ad348f4043dff17c11938201 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 4 May 2020 13:51:34 +0200 Subject: [PATCH] Make the VersionSelector take Composer API/Runtime versions into account, refs getsentry/sentry-php#1008 --- src/Composer/Package/Version/VersionSelector.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Composer/Package/Version/VersionSelector.php b/src/Composer/Package/Version/VersionSelector.php index 8e225d803..200f56e0f 100644 --- a/src/Composer/Package/Version/VersionSelector.php +++ b/src/Composer/Package/Version/VersionSelector.php @@ -15,6 +15,8 @@ namespace Composer\Package\Version; use Composer\DependencyResolver\Pool; use Composer\Package\BasePackage; use Composer\Package\PackageInterface; +use Composer\Plugin\PluginInterface; +use Composer\Composer; use Composer\Package\Loader\ArrayLoader; use Composer\Package\Dumper\ArrayDumper; use Composer\Semver\Constraint\Constraint; @@ -53,10 +55,14 @@ class VersionSelector if ($targetPhpVersion) { $phpConstraint = new Constraint('==', $this->getParser()->normalize($targetPhpVersion)); - $candidates = array_filter($candidates, function ($pkg) use ($phpConstraint) { + $composerRuntimeConstraint = new Constraint('==', $this->getParser()->normalize(Composer::RUNTIME_API_VERSION)); + $composerPluginConstraint = new Constraint('==', $this->getParser()->normalize(PluginInterface::PLUGIN_API_VERSION)); + $candidates = array_filter($candidates, function ($pkg) use ($phpConstraint, $composerPluginConstraint, $composerRuntimeConstraint) { $reqs = $pkg->getRequires(); - return !isset($reqs['php']) || $reqs['php']->getConstraint()->matches($phpConstraint); + return (!isset($reqs['php']) || $reqs['php']->getConstraint()->matches($phpConstraint)) + && (!isset($reqs['composer-plugin-api']) || $reqs['composer-plugin-api']->getConstraint()->matches($composerPluginConstraint)) + && (!isset($reqs['composer-runtime-api']) || $reqs['composer-runtime-api']->getConstraint()->matches($composerRuntimeConstraint)); }); }