From 419567ba6db91e8cf15f78ba0690d5e4b6668c0e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 4 May 2020 21:12:21 +0200 Subject: [PATCH 1/3] Update VersionSelector to take all platform requirements into account when selecting packages --- UPGRADE-2.0.md | 1 + .../Package/Version/VersionSelector.php | 47 ++++++++--- .../Package/Version/VersionSelectorTest.php | 80 ++++++++++++++++--- 3 files changed, 105 insertions(+), 23 deletions(-) diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index c8bcedf70..22486cae0 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -27,6 +27,7 @@ - packages now contain an `"installed-path"` key which lists where they were installed - there is a top level `"dev"` key which stores whether dev requirements were installed or not - `PreFileDownloadEvent` now receives an `HttpDownloader` instance instead of `RemoteFilesystem`, and that instance can not be overridden by listeners anymore +- `VersionSelector::findBestCandidate`'s third argument (phpVersion) was removed in favor of passing in a complete PlatformRepository instance into the constructor - `IOInterface` now extends PSR-3's `LoggerInterface`, and has new `writeRaw` + `writeErrorRaw` methods - `RepositoryInterface` changes: - A new `loadPackages(array $packageNameMap, array $acceptableStabilities, array $stabilityFlags)` function was added for use during pool building diff --git a/src/Composer/Package/Version/VersionSelector.php b/src/Composer/Package/Version/VersionSelector.php index 9f331dffe..82d60dce7 100644 --- a/src/Composer/Package/Version/VersionSelector.php +++ b/src/Composer/Package/Version/VersionSelector.php @@ -20,6 +20,7 @@ use Composer\Composer; use Composer\Package\Loader\ArrayLoader; use Composer\Package\Dumper\ArrayDumper; use Composer\Repository\RepositorySet; +use Composer\Repository\PlatformRepository; use Composer\Semver\Constraint\Constraint; /** @@ -32,11 +33,22 @@ class VersionSelector { private $repositorySet; + private $platformConstraints; + private $parser; - public function __construct(RepositorySet $repositorySet) + /** + * @param PlatformRepository $platformRepo If passed in, the versions found will be filtered against their requirements to eliminate any not matching the current platform packages + */ + public function __construct(RepositorySet $repositorySet, PlatformRepository $platformRepo = null) { $this->repositorySet = $repositorySet; + if ($platformRepo) { + $this->platformConstraints = array(); + foreach ($platformRepo->getPackages() as $package) { + $this->platformConstraints[$package->getName()][] = new Constraint('==', $package->getVersion()); + } + } } /** @@ -45,25 +57,38 @@ class VersionSelector * * @param string $packageName * @param string $targetPackageVersion - * @param string $targetPhpVersion * @param string $preferredStability + * @param bool $ignorePlatformReqs * @return PackageInterface|false */ - public function findBestCandidate($packageName, $targetPackageVersion = null, $targetPhpVersion = null, $preferredStability = 'stable') + public function findBestCandidate($packageName, $targetPackageVersion = null, $preferredStability = 'stable', $ignorePlatformReqs = false) { + if (!isset(BasePackage::$stabilities[$preferredStability])) { + // If you get this, maybe you are still relying on the Composer 1.x signature where the 3rd arg was the php version + throw new \UnexpectedValueException('Expected a valid stability name as 3rd argument, got '.$preferredStability); + } + $constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null; $candidates = $this->repositorySet->findPackages(strtolower($packageName), $constraint); - if ($targetPhpVersion) { - $phpConstraint = new Constraint('==', $this->getParser()->normalize($targetPhpVersion)); - $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) { + if ($this->platformConstraints && !$ignorePlatformReqs) { + $platformConstraints = $this->platformConstraints; + $candidates = array_filter($candidates, function ($pkg) use ($platformConstraints) { $reqs = $pkg->getRequires(); - 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)); + foreach ($reqs as $name => $link) { + if (isset($platformConstraints[$name])) { + foreach ($platformConstraints[$name] as $constraint) { + if ($link->getConstraint()->matches($constraint)) { + continue 2; + } + } + + return false; + } + } + + return true; }); } diff --git a/tests/Composer/Test/Package/Version/VersionSelectorTest.php b/tests/Composer/Test/Package/Version/VersionSelectorTest.php index 66d07d267..14d00b438 100644 --- a/tests/Composer/Test/Package/Version/VersionSelectorTest.php +++ b/tests/Composer/Test/Package/Version/VersionSelectorTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Package\Version; use Composer\Package\Version\VersionSelector; use Composer\Package\Package; use Composer\Package\Link; +use Composer\Repository\PlatformRepository; use Composer\Semver\VersionParser; use Composer\Test\TestCase; @@ -46,27 +47,82 @@ class VersionSelectorTest extends TestCase $this->assertSame($package2, $best, 'Latest version should be 1.2.2'); } - public function testLatestVersionIsReturnedThatMatchesPhpRequirement() + public function testLatestVersionIsReturnedThatMatchesPhpRequirements() { $packageName = 'foobar'; + $platform = new PlatformRepository(array(), array('php' => '5.5.0')); + $repositorySet = $this->createMockRepositorySet(); + $versionSelector = new VersionSelector($repositorySet, $platform); + $parser = new VersionParser; $package1 = $this->createPackage('1.0.0'); - $package2 = $this->createPackage('2.0.0'); $package1->setRequires(array('php' => new Link($packageName, 'php', $parser->parseConstraints('>=5.4'), 'requires', '>=5.4'))); + $package2 = $this->createPackage('2.0.0'); $package2->setRequires(array('php' => new Link($packageName, 'php', $parser->parseConstraints('>=5.6'), 'requires', '>=5.6'))); $packages = array($package1, $package2); - $repositorySet = $this->createMockRepositorySet(); - $repositorySet->expects($this->once()) + $repositorySet->expects($this->any()) ->method('findPackages') ->with($packageName, null) ->will($this->returnValue($packages)); - $versionSelector = new VersionSelector($repositorySet); - $best = $versionSelector->findBestCandidate($packageName, null, '5.5.0'); - + $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package1, $best, 'Latest version supporting php 5.5 should be returned (1.0.0)'); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (2.0.0)'); + } + + public function testLatestVersionIsReturnedThatMatchesExtRequirements() + { + $packageName = 'foobar'; + + $platform = new PlatformRepository(array(), array('ext-zip' => '5.3.0')); + $repositorySet = $this->createMockRepositorySet(); + $versionSelector = new VersionSelector($repositorySet, $platform); + + $parser = new VersionParser; + $package1 = $this->createPackage('1.0.0'); + $package1->setRequires(array('ext-zip' => new Link($packageName, 'ext-zip', $parser->parseConstraints('^5.2'), 'requires', '^5.2'))); + $package2 = $this->createPackage('2.0.0'); + $package2->setRequires(array('ext-zip' => new Link($packageName, 'ext-zip', $parser->parseConstraints('^5.4'), 'requires', '^5.4'))); + $packages = array($package1, $package2); + + $repositorySet->expects($this->any()) + ->method('findPackages') + ->with($packageName, null) + ->will($this->returnValue($packages)); + + $best = $versionSelector->findBestCandidate($packageName); + $this->assertSame($package1, $best, 'Latest version supporting ext-zip 5.3.0 should be returned (1.0.0)'); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (2.0.0)'); + } + + public function testLatestVersionIsReturnedThatMatchesComposerRequirements() + { + $packageName = 'foobar'; + + $platform = new PlatformRepository(array(), array('composer-runtime-api' => '1.0.0')); + $repositorySet = $this->createMockRepositorySet(); + $versionSelector = new VersionSelector($repositorySet, $platform); + + $parser = new VersionParser; + $package1 = $this->createPackage('1.0.0'); + $package1->setRequires(array('composer-runtime-api' => new Link($packageName, 'composer-runtime-api', $parser->parseConstraints('^1.0'), 'requires', '^1.0'))); + $package2 = $this->createPackage('1.1.0'); + $package2->setRequires(array('composer-runtime-api' => new Link($packageName, 'composer-runtime-api', $parser->parseConstraints('^2.0'), 'requires', '^2.0'))); + $packages = array($package1, $package2); + + $repositorySet->expects($this->any()) + ->method('findPackages') + ->with($packageName, null) + ->will($this->returnValue($packages)); + + $best = $versionSelector->findBestCandidate($packageName); + $this->assertSame($package1, $best, 'Latest version supporting composer 1 should be returned (1.0.0)'); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (1.1.0)'); } public function testMostStableVersionIsReturned() @@ -109,10 +165,10 @@ class VersionSelectorTest extends TestCase ->will($this->returnValue(array_reverse($packages))); $versionSelector = new VersionSelector($repositorySet); - $best = $versionSelector->findBestCandidate($packageName, null, null); + $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package2, $best, 'Expecting 2.0.0-beta3, cause beta is more stable than dev'); - $best = $versionSelector->findBestCandidate($packageName, null, null); + $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package2, $best, 'Expecting 2.0.0-beta3, cause beta is more stable than dev'); } @@ -131,7 +187,7 @@ class VersionSelectorTest extends TestCase ->will($this->returnValue($packages)); $versionSelector = new VersionSelector($repositorySet); - $best = $versionSelector->findBestCandidate($packageName, null, null, 'dev'); + $best = $versionSelector->findBestCandidate($packageName, null, 'dev'); $this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)'); } @@ -152,7 +208,7 @@ class VersionSelectorTest extends TestCase ->will($this->returnValue($packages)); $versionSelector = new VersionSelector($repositorySet); - $best = $versionSelector->findBestCandidate($packageName, null, null, 'beta'); + $best = $versionSelector->findBestCandidate($packageName, null, 'beta'); $this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)'); } @@ -172,7 +228,7 @@ class VersionSelectorTest extends TestCase ->will($this->returnValue($packages)); $versionSelector = new VersionSelector($repositorySet); - $best = $versionSelector->findBestCandidate($packageName, null, null, 'stable'); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable'); $this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)'); } From 8a2dd1baefdc87cb6cab69eda6938cec748a825c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 4 May 2020 21:36:10 +0200 Subject: [PATCH 2/3] Adjust all usages of VersionSelector to the new API --- UPGRADE-2.0.md | 1 + src/Composer/Command/CreateProjectCommand.php | 15 ++--- src/Composer/Command/InitCommand.php | 56 ++++++++++--------- src/Composer/Command/RequireCommand.php | 13 ++++- src/Composer/Command/ShowCommand.php | 19 +++---- 5 files changed, 56 insertions(+), 48 deletions(-) diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index 22486cae0..ba9fa3615 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -28,6 +28,7 @@ - there is a top level `"dev"` key which stores whether dev requirements were installed or not - `PreFileDownloadEvent` now receives an `HttpDownloader` instance instead of `RemoteFilesystem`, and that instance can not be overridden by listeners anymore - `VersionSelector::findBestCandidate`'s third argument (phpVersion) was removed in favor of passing in a complete PlatformRepository instance into the constructor +- `InitCommand::determineRequirements`'s fourth argument (phpVersion) should now receive a complete PlatformRepository instance or null if platform requirements are to be ignored - `IOInterface` now extends PSR-3's `LoggerInterface`, and has new `writeRaw` + `writeErrorRaw` methods - `RepositoryInterface` changes: - A new `loadPackages(array $packageNameMap, array $acceptableStabilities, array $stabilityFlags)` function was added for use during pool building diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 9263ba7ee..2b3c7b20d 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -336,25 +336,20 @@ EOT $repositorySet = new RepositorySet($stability); $repositorySet->addRepository($sourceRepo); - $phpVersion = null; - $prettyPhpVersion = null; + $platformRepo = null; if (!$ignorePlatformReqs) { $platformOverrides = $config->get('platform') ?: array(); - // initialize $this->repos as it is used by the parent InitCommand - $platform = new PlatformRepository(array(), $platformOverrides); - $phpPackage = $platform->findPackage('php', '*'); - $phpVersion = $phpPackage->getVersion(); - $prettyPhpVersion = $phpPackage->getPrettyVersion(); + $platformRepo = new PlatformRepository(array(), $platformOverrides); } // find the latest version if there are multiple - $versionSelector = new VersionSelector($repositorySet); + $versionSelector = new VersionSelector($repositorySet, $platformRepo); $package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability); if (!$package) { $errorMessage = "Could not find package $name with " . ($packageVersion ? "version $packageVersion" : "stability $stability"); - if ($phpVersion && $versionSelector->findBestCandidate($name, $packageVersion, null, $stability)) { - throw new \InvalidArgumentException($errorMessage .' in a version installable using your PHP version '.$prettyPhpVersion.'.'); + if ($platformRepo && $versionSelector->findBestCandidate($name, $packageVersion, $stability, true)) { + throw new \InvalidArgumentException($errorMessage .' in a version installable using your PHP version, PHP extensions and Composer version.'); } throw new \InvalidArgumentException($errorMessage .'.'); diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 8f101515c..ecbbbf1e0 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -345,13 +345,21 @@ EOT // prepare to resolve dependencies $repos = $this->getRepos(); $preferredStability = $minimumStability ?: 'stable'; - $phpVersion = $repos->findPackage('php', '*')->getPrettyVersion(); + $platformRepo = null; + if ($repos instanceof CompositeRepository) { + foreach ($repos->getRepositories() as $candidateRepo) { + if ($candidateRepo instanceof PlatformRepository) { + $platformRepo = $candidateRepo; + break; + } + } + } $question = 'Would you like to define your dependencies (require) interactively [yes]? '; $require = $input->getOption('require'); $requirements = array(); if ($require || $io->askConfirmation($question, true)) { - $requirements = $this->determineRequirements($input, $output, $require, $phpVersion, $preferredStability); + $requirements = $this->determineRequirements($input, $output, $require, $platformRepo, $preferredStability); } $input->setOption('require', $requirements); @@ -359,7 +367,7 @@ EOT $requireDev = $input->getOption('require-dev'); $devRequirements = array(); if ($requireDev || $io->askConfirmation($question, true)) { - $devRequirements = $this->determineRequirements($input, $output, $requireDev, $phpVersion, $preferredStability); + $devRequirements = $this->determineRequirements($input, $output, $requireDev, $platformRepo, $preferredStability); } $input->setOption('require-dev', $devRequirements); } @@ -403,7 +411,7 @@ EOT return $this->repos; } - final protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), $phpVersion = null, $preferredStability = 'stable', $checkProvidedVersions = true, $fixed = false) + final protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), PlatformRepository $platformRepo = null, $preferredStability = 'stable', $checkProvidedVersions = true, $fixed = false) { if ($requires) { $requires = $this->normalizeRequirements($requires); @@ -413,7 +421,7 @@ EOT foreach ($requires as $requirement) { if (!isset($requirement['version'])) { // determine the best version automatically - list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $phpVersion, $preferredStability, null, null, $fixed); + list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $platformRepo, $preferredStability, null, null, $fixed); $requirement['version'] = $version; // replace package name from packagist.org @@ -426,7 +434,7 @@ EOT )); } else { // check that the specified version/constraint exists before we proceed - list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $phpVersion, $preferredStability, $checkProvidedVersions ? $requirement['version'] : null, 'dev', $fixed); + list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $platformRepo, $preferredStability, $checkProvidedVersions ? $requirement['version'] : null, 'dev', $fixed); // replace package name from packagist.org $requirement['name'] = $name; @@ -550,7 +558,7 @@ EOT ); if (false === $constraint) { - list($name, $constraint) = $this->findBestVersionAndNameForPackage($input, $package, $phpVersion, $preferredStability); + list($name, $constraint) = $this->findBestVersionAndNameForPackage($input, $package, $platformRepo, $preferredStability); $io->writeError(sprintf( 'Using version %s for %s', @@ -723,7 +731,7 @@ EOT * * @param InputInterface $input * @param string $name - * @param string|null $phpVersion + * @param PlatformRepository|null $platformRepo * @param string $preferredStability * @param string|null $requiredVersion * @param string $minimumStability @@ -731,18 +739,18 @@ EOT * @throws \InvalidArgumentException * @return array name version */ - private function findBestVersionAndNameForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null, $fixed = null) + private function findBestVersionAndNameForPackage(InputInterface $input, $name, PlatformRepository $platformRepo = null, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null, $fixed = null) { - // find the latest version allowed in this repo set - $versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability)); + // ignore platform repo if platform requirements are ignored $ignorePlatformReqs = $input->hasOption('ignore-platform-reqs') && $input->getOption('ignore-platform-reqs'); - - // ignore phpVersion if platform requirements are ignored if ($ignorePlatformReqs) { - $phpVersion = null; + $platformRepo = null; } - $package = $versionSelector->findBestCandidate($name, $requiredVersion, $phpVersion, $preferredStability); + // find the latest version allowed in this repo set + $versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability), $platformRepo); + + $package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability); if (!$package) { // platform packages can not be found in the pool in versions other than the local platform's has @@ -752,28 +760,26 @@ EOT } // Check whether the PHP version was the problem - if ($phpVersion && $versionSelector->findBestCandidate($name, $requiredVersion, null, $preferredStability)) { + if ($platformRepo && $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, true)) { throw new \InvalidArgumentException(sprintf( - 'Package %s at version %s has a PHP requirement incompatible with your PHP version (%s)', + 'Package %s at version %s has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version', $name, - $requiredVersion, - $phpVersion + $requiredVersion )); } // Check whether the required version was the problem - if ($requiredVersion && $versionSelector->findBestCandidate($name, null, $phpVersion, $preferredStability)) { + if ($requiredVersion && $versionSelector->findBestCandidate($name, null, $preferredStability)) { throw new \InvalidArgumentException(sprintf( 'Could not find package %s in a version matching %s', $name, $requiredVersion )); } - // Check whether the PHP version was the problem - if ($phpVersion && $versionSelector->findBestCandidate($name)) { + // Check whether the PHP version was the problem for all versions + if ($platformRepo && $versionSelector->findBestCandidate($name, null, $preferredStability, true)) { throw new \InvalidArgumentException(sprintf( - 'Could not find package %s in any version matching your PHP version (%s)', - $name, - $phpVersion + 'Could not find package %s in any version matching your PHP version, PHP extensions and Composer version', + $name )); } diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 7e290aca6..4bc08905b 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -166,7 +166,7 @@ EOT $platformOverrides = $composer->getConfig()->get('platform') ?: array(); // initialize $this->repos as it is used by the parent InitCommand $this->repos = new CompositeRepository(array_merge( - array(new PlatformRepository(array(), $platformOverrides)), + array($platformRepo = new PlatformRepository(array(), $platformOverrides)), $repos )); @@ -176,9 +176,16 @@ EOT $preferredStability = $composer->getPackage()->getMinimumStability(); } - $phpVersion = $this->repos->findPackage('php', '*')->getPrettyVersion(); try { - $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'), $phpVersion, $preferredStability, !$input->getOption('no-update'), $input->getOption('fixed')); + $requirements = $this->determineRequirements( + $input, + $output, + $input->getArgument('packages'), + $input->getOption('ignore-platform-reqs') ? null : $platformRepo, + $preferredStability, + !$input->getOption('no-update'), + $input->getOption('fixed') + ); } catch (\Exception $e) { if ($this->newlyCreated) { throw new \RuntimeException('No composer.json present in the current directory, this may be the cause of the following exception.', 0, $e); diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index b153c408c..b928765f9 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -151,7 +151,6 @@ EOT } $platformRepo = new PlatformRepository(array(), $platformOverrides); $lockedRepo = null; - $phpVersion = $platformRepo->findPackage('php', '*')->getVersion(); if ($input->getOption('self')) { $package = $this->getComposer()->getPackage(); @@ -249,7 +248,7 @@ EOT } else { $latestPackage = null; if ($input->getOption('latest')) { - $latestPackage = $this->findLatestPackage($package, $composer, $phpVersion); + $latestPackage = $this->findLatestPackage($package, $composer, $platformRepo); } if ($input->getOption('outdated') && $input->getOption('strict') && $latestPackage && $latestPackage->getFullPrettyVersion() !== $package->getFullPrettyVersion() && !$latestPackage->isAbandoned()) { $exitCode = 1; @@ -382,7 +381,7 @@ EOT if ($showLatest && $showVersion) { foreach ($packages[$type] as $package) { if (is_object($package)) { - $latestPackage = $this->findLatestPackage($package, $composer, $phpVersion, $showMinorOnly); + $latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly); if ($latestPackage === false) { continue; } @@ -1180,18 +1179,18 @@ EOT /** * Given a package, this finds the latest package matching it * - * @param PackageInterface $package - * @param Composer $composer - * @param string $phpVersion - * @param bool $minorOnly + * @param PackageInterface $package + * @param Composer $composer + * @param PlatformRepository $platformRepo + * @param bool $minorOnly * * @return PackageInterface|false */ - private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false) + private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, $minorOnly = false) { // find the latest version allowed in this repo set $name = $package->getName(); - $versionSelector = new VersionSelector($this->getRepositorySet($composer)); + $versionSelector = new VersionSelector($this->getRepositorySet($composer), $platformRepo); $stability = $composer->getPackage()->getMinimumStability(); $flags = $composer->getPackage()->getStabilityFlags(); if (isset($flags[$name])) { @@ -1212,7 +1211,7 @@ EOT $targetVersion = '^' . $package->getVersion(); } - return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability); + return $versionSelector->findBestCandidate($name, $targetVersion, $bestStability); } private function getRepositorySet(Composer $composer) From 1d68e85433c50d84c166ec964b23679b049b5d0c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 4 May 2020 22:04:57 +0200 Subject: [PATCH 3/3] Fix usage --- src/Composer/Command/CreateProjectCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 2b3c7b20d..e79ed8a7d 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -344,7 +344,7 @@ EOT // find the latest version if there are multiple $versionSelector = new VersionSelector($repositorySet, $platformRepo); - $package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability); + $package = $versionSelector->findBestCandidate($name, $packageVersion, $stability); if (!$package) { $errorMessage = "Could not find package $name with " . ($packageVersion ? "version $packageVersion" : "stability $stability");