From a520b7d3d3de41d35b99ac32bd385270541b3eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Sun, 3 Jul 2022 22:59:39 +0200 Subject: [PATCH] qa: add support for `composer` 2.3.6+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- .../PackageProviderDetectionFactory.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/PackageProvider/PackageProviderDetectionFactory.php b/src/PackageProvider/PackageProviderDetectionFactory.php index 6bb214d..19108e7 100644 --- a/src/PackageProvider/PackageProviderDetectionFactory.php +++ b/src/PackageProvider/PackageProviderDetectionFactory.php @@ -6,15 +6,19 @@ use Composer\Composer; use Composer\Installer\PackageEvent; +use Composer\IO\IOInterface; use Composer\IO\NullIO; use Composer\Repository\CompositeRepository; use Composer\Repository\InstalledArrayRepository; use Composer\Repository\InstalledRepository; use Composer\Repository\PlatformRepository; use Composer\Repository\RepositoryFactory; +use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface as ComposerRepositoryInterface; use Composer\Repository\RootPackageRepository; +use function method_exists; + /** * @internal */ @@ -37,7 +41,7 @@ public static function create(Composer $composer): self public function detect(PackageEvent $event, string $packageName): PackageProviderDetectionInterface { $installedRepo = new InstalledRepository($this->prepareRepositoriesForInstalledRepository()); - $defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos(new NullIO())); + $defaultRepos = new CompositeRepository($this->createDefaultRepos(new NullIO())); if ( ($match = $defaultRepos->findPackage($packageName, '*')) @@ -63,4 +67,16 @@ private function prepareRepositoriesForInstalledRepository(): array new PlatformRepository([], $platformOverrides), ]; } + + /** + * @return RepositoryInterface[] + */ + private function createDefaultRepos(IOInterface $io): array + { + if (method_exists(RepositoryFactory::class, 'defaultReposWithDefaultManager')) { + return RepositoryFactory::defaultReposWithDefaultManager($io); + } + + return RepositoryFactory::defaultRepos($io); + } }