diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index ce13d3df5c48..93eca56967ea 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -134,6 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $file = Factory::getComposerFile(); $jsonFile = new JsonFile($file); + /** @var array{require?: array, require-dev?: array} $composer */ $composer = $jsonFile->read(); $composerBackup = file_get_contents($jsonFile->getPath()); @@ -176,7 +177,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } } } - } elseif (isset($composer[$type]) && $matches = Preg::grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$type]))) { + } elseif (isset($composer[$type]) && count($matches = Preg::grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$type]))) > 0) { foreach ($matches as $matchedPackage) { if ($dryRun) { $toRemove[$type][] = $matchedPackage; @@ -184,7 +185,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $json->removeLink($type, $matchedPackage); } } - } elseif (isset($composer[$altType]) && $matches = Preg::grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$altType]))) { + } elseif (isset($composer[$altType]) && count($matches = Preg::grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$altType]))) > 0) { foreach ($matches as $matchedPackage) { $io->writeError('' . $matchedPackage . ' could not be found in ' . $type . ' but it is present in ' . $altType . ''); if ($io->isInteractive()) { diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 8909f67fec85..f02b764115fa 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -373,6 +373,7 @@ public function getPrettyString(RepositorySet $repositorySet, Request $request, $package = $pool->literalToPackage($literal); $packageNames[$package->getName()] = true; } + /** @var string $replacedName */ $replacedName = $this->reasonData; if (count($packageNames) > 1) { diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index b82c850ba4e9..1a71f96aa3af 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -333,6 +333,9 @@ public function tick(): void } $progress = curl_getinfo($curlHandle); + if (false === $progress) { + throw new \RuntimeException('Failed getting info from curl handle '.$i.' ('.$this->jobs[$i]['url'].')'); + } $job = $this->jobs[$i]; unset($this->jobs[$i]); $error = curl_error($curlHandle); @@ -364,7 +367,7 @@ public function tick(): void continue; } - if ($errno === 28 /* CURLE_OPERATION_TIMEDOUT */ && isset($progress['namelookup_time']) && $progress['namelookup_time'] == 0 && !$timeoutWarning) { + if ($errno === 28 /* CURLE_OPERATION_TIMEDOUT */ && PHP_VERSION_ID >= 70300 && $progress['namelookup_time'] == 0 && !$timeoutWarning) { $timeoutWarning = true; $this->io->writeError('A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.'); } @@ -443,14 +446,14 @@ public function tick(): void call_user_func($job['resolve'], $response); } } catch (\Exception $e) { - if ($e instanceof TransportException && $headers) { - $e->setHeaders($headers); - $e->setStatusCode($statusCode); - } - if ($e instanceof TransportException && $response) { - $e->setResponse($response->getBody()); - } - if ($e instanceof TransportException && $progress) { + if ($e instanceof TransportException) { + if (null !== $headers) { + $e->setHeaders($headers); + $e->setStatusCode($statusCode); + } + if (null !== $response) { + $e->setResponse($response->getBody()); + } $e->setResponseInfo($progress); } diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index 0b672729b03a..960ea25c8dcb 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -1078,7 +1078,7 @@ public static function provideLibraryTestCases(): array * * @param string|string[] $extensions * @param string|null $info - * @param array $expectations + * @param array $expectations array of packageName => expected version (or false if expected to be msising), or packageName => array(expected version, expected replaced names, expected provided names) * @param list $functions * @param list $constants * @param list $classDefinitions @@ -1153,10 +1153,6 @@ public function testLibraryInformation( $platformRepository = new PlatformRepository(array(), array(), $runtime); - $expectations = array_map(function ($expectation): array { - return array_replace(array(null, array(), array()), (array) $expectation); - }, $expectations); - $libraries = array_map( function ($package): string { return $package['name']; @@ -1168,17 +1164,21 @@ function ($package): bool { } ) ); - $expectedLibraries = array_merge(array_keys(array_filter($expectations, function ($expectation): bool { - return $expectation[0] !== false; - }))); + $expectedLibraries = array_keys(array_filter($expectations, function ($expectation): bool { + return $expectation !== false; + })); self::assertCount(count(array_filter($expectedLibraries)), $libraries, sprintf('Expected: %s, got %s', var_export($expectedLibraries, true), var_export($libraries, true))); - $expectations = array_merge($expectations, array_combine(array_map(function ($extension): string { - return 'ext-'.$extension; - }, $extensions), array_fill(0, count($extensions), array($extensionVersion, array(), array())))); + foreach ($extensions as $extension) { + $expectations['ext-'.$extension] = $extensionVersion; + } - foreach ($expectations as $packageName => $expectation) { - list($expectedVersion, $expectedReplaces, $expectedProvides) = $expectation; + foreach ($expectations as $expectedLibOrExt => $expectation) { + $packageName = $expectedLibOrExt; + if (!is_array($expectation)) { + $expectation = [$expectation, [], []]; + } + list($expectedVersion, $expectedReplaces, $expectedProvides) = array_pad($expectation, 3, []); $package = $platformRepository->findPackage($packageName, '*'); if ($expectedVersion === false) {