Skip to content

Commit

Permalink
Update phpstan & baseline (2158, 104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and emahorvat52 committed Jan 18, 2023
1 parent afd3339 commit e1a4dc9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/Composer/Command/RemoveCommand.php
Expand Up @@ -134,6 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$file = Factory::getComposerFile();

$jsonFile = new JsonFile($file);
/** @var array{require?: array<string, string>, require-dev?: array<string, string>} $composer */
$composer = $jsonFile->read();
$composerBackup = file_get_contents($jsonFile->getPath());

Expand Down Expand Up @@ -176,15 +177,15 @@ 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;
} else {
$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('<warning>' . $matchedPackage . ' could not be found in ' . $type . ' but it is present in ' . $altType . '</warning>');
if ($io->isInteractive()) {
Expand Down
1 change: 1 addition & 0 deletions src/Composer/DependencyResolver/Rule.php
Expand Up @@ -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) {
Expand Down
21 changes: 12 additions & 9 deletions src/Composer/Util/Http/CurlDownloader.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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('<warning>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.</warning>');
}
Expand Down Expand Up @@ -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);
}

Expand Down
26 changes: 13 additions & 13 deletions tests/Composer/Test/Repository/PlatformRepositoryTest.php
Expand Up @@ -1078,7 +1078,7 @@ public static function provideLibraryTestCases(): array
*
* @param string|string[] $extensions
* @param string|null $info
* @param array<string,string|false> $expectations
* @param array<string,string|false|array{string|false, 1?: string[], 2?: string[]}> $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<mixed> $functions
* @param list<mixed> $constants
* @param list<mixed> $classDefinitions
Expand Down Expand Up @@ -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'];
Expand All @@ -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) {
Expand Down

0 comments on commit e1a4dc9

Please sign in to comment.