Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Command/BisectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Override;
use PHPStan\Command\Bisect\BinarySearch;
use PHPStan\File\FileReader;
use PHPStan\Internal\HttpClientFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -106,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$client = new Client([
$client = HttpClientFactory::createClient([
RequestOptions::TIMEOUT => 30,
RequestOptions::CONNECT_TIMEOUT => 10,
'headers' => [
Expand Down
4 changes: 2 additions & 2 deletions src/Command/FixerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Nette\Utils\Json;
Expand All @@ -23,6 +22,7 @@
use PHPStan\Internal\ComposerHelper;
use PHPStan\Internal\DirectoryCreator;
use PHPStan\Internal\DirectoryCreatorException;
use PHPStan\Internal\HttpClientFactory;
use PHPStan\PhpDoc\StubFilesProvider;
use PHPStan\Process\ProcessCanceledException;
use PHPStan\Process\ProcessCrashedException;
Expand Down Expand Up @@ -325,7 +325,7 @@ private function downloadPhar(
$output->writeln('<fg=green>Checking if there\'s a new PHPStan Pro release...</>');
}

$client = new Client([
$client = HttpClientFactory::createClient([
RequestOptions::TIMEOUT => 30,
RequestOptions::CONNECT_TIMEOUT => 5,
]);
Expand Down
28 changes: 28 additions & 0 deletions src/Internal/HttpClientFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types = 1);

namespace PHPStan\Internal;

use GuzzleHttp\Client;
use function extension_loaded;

final class HttpClientFactory
{

/**
* @param array<mixed> $config
*
* @see \GuzzleHttp\RequestOptions
*/
public static function createClient(array $config): Client
{
if (
!isset($config['headers']['Accept-Encoding'])
&& extension_loaded('zlib')
) {
$config['headers']['Accept-Encoding'] = 'gzip,deflate';
}

return new Client($config);
}

}
Loading