Skip to content

Commit 4b03db7

Browse files
committed
centralize timeout
1 parent 049c03c commit 4b03db7

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/Command/BisectCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
108108
}
109109

110110
$client = (new HttpClientFactory())->createClient([
111-
RequestOptions::TIMEOUT => 30,
112-
RequestOptions::CONNECT_TIMEOUT => 10,
113111
'headers' => [
114112
'Authorization' => 'token ' . $token,
115113
'Accept' => 'application/vnd.github.v3+json',

src/Command/FixerApplication.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,7 @@ private function downloadPhar(
326326
$output->writeln('<fg=green>Checking if there\'s a new PHPStan Pro release...</>');
327327
}
328328

329-
$client = $this->httpClientFactory->createClient([
330-
RequestOptions::TIMEOUT => 30,
331-
RequestOptions::CONNECT_TIMEOUT => 5,
332-
]);
329+
$client = $this->httpClientFactory->createClient([]);
333330

334331
$latestUrl = sprintf('https://fixer-download-api.phpstan.com/latest?%s', http_build_query(['phpVersion' => PHP_VERSION_ID, 'branch' => $branch]));
335332

src/Internal/HttpClientFactory.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
namespace PHPStan\Internal;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\RequestOptions;
67
use PHPStan\DependencyInjection\AutowiredService;
78
use function extension_loaded;
89

910
#[AutowiredService]
1011
final class HttpClientFactory
1112
{
1213

13-
/**
14-
* @param array<mixed> $defaults
15-
*
16-
* @see \GuzzleHttp\RequestOptions
17-
*/
18-
public function __construct(private readonly array $defaults = [])
14+
public function __construct(
15+
private int $timeout = 30,
16+
private int $connectTimeout = 10,
17+
)
1918
{
2019
}
2120

@@ -33,7 +32,12 @@ public function createClient(array $config): Client
3332
$config['headers']['Accept-Encoding'] = 'gzip,deflate';
3433
}
3534

36-
return new Client($config + $this->defaults);
35+
$defaults = [
36+
RequestOptions::TIMEOUT => $this->timeout,
37+
RequestOptions::CONNECT_TIMEOUT => $this->connectTimeout,
38+
];
39+
40+
return new Client($config + $defaults);
3741
}
3842

3943
}

0 commit comments

Comments
 (0)