Skip to content

Commit 2c26c8b

Browse files
committed
[HttpClient] Add types to private properties
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 31762b1 commit 2c26c8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+196
-184
lines changed

AmpHttpClient.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ final class AmpHttpClient implements HttpClientInterface, LoggerAwareInterface,
4242
use HttpClientTrait;
4343
use LoggerAwareTrait;
4444

45-
private $defaultOptions = self::OPTIONS_DEFAULTS;
46-
47-
/** @var AmpClientState */
48-
private $multi;
45+
private array $defaultOptions = self::OPTIONS_DEFAULTS;
46+
private AmpClientState $multi;
4947

5048
/**
5149
* @param array $defaultOptions Default requests' options

CachingHttpClient.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class CachingHttpClient implements HttpClientInterface
3434
{
3535
use HttpClientTrait;
3636

37-
private $client;
38-
private $cache;
39-
private $defaultOptions = self::OPTIONS_DEFAULTS;
37+
private HttpClientInterface $client;
38+
private HttpCache $cache;
39+
private array $defaultOptions = self::OPTIONS_DEFAULTS;
4040

4141
public function __construct(HttpClientInterface $client, StoreInterface $store, array $defaultOptions = [])
4242
{

Chunk/DataChunk.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
class DataChunk implements ChunkInterface
2222
{
23-
private $offset = 0;
24-
private $content = '';
23+
private int $offset = 0;
24+
private string $content = '';
2525

2626
public function __construct(int $offset = 0, string $content = '')
2727
{

Chunk/ErrorChunk.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
*/
2323
class ErrorChunk implements ChunkInterface
2424
{
25-
private $didThrow = false;
26-
private $offset;
27-
private $errorMessage;
28-
private $error;
25+
private bool $didThrow = false;
26+
private int $offset;
27+
private string $errorMessage;
28+
private ?\Throwable $error = null;
2929

3030
public function __construct(int $offset, \Throwable|string $error)
3131
{

Chunk/InformationalChunk.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class InformationalChunk extends DataChunk
2020
{
21-
private $status;
21+
private array $status;
2222

2323
public function __construct(int $statusCode, array $headers)
2424
{

Chunk/ServerSentEvent.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
*/
2020
final class ServerSentEvent extends DataChunk implements ChunkInterface
2121
{
22-
private $data = '';
23-
private $id = '';
24-
private $type = 'message';
25-
private $retry = 0;
22+
private string $data = '';
23+
private string $id = '';
24+
private string $type = 'message';
25+
private float $retry = 0;
2626

2727
public function __construct(string $content)
2828
{

CurlHttpClient.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
3737
use HttpClientTrait;
3838
use LoggerAwareTrait;
3939

40-
private $defaultOptions = self::OPTIONS_DEFAULTS + [
40+
private array $defaultOptions = self::OPTIONS_DEFAULTS + [
4141
'auth_ntlm' => null, // array|string - an array containing the username as first value, and optionally the
4242
// password as the second one; or string like username:password - enabling NTLM auth
4343
'extra' => [
@@ -47,12 +47,10 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
4747

4848
/**
4949
* An internal object to share state between the client and its responses.
50-
*
51-
* @var CurlClientState
5250
*/
53-
private $multi;
51+
private CurlClientState $multi;
5452

55-
private static $curlVersion;
53+
private static array $curlVersion;
5654

5755
/**
5856
* @param array $defaultOptions Default request's options

DataCollector/HttpClientDataCollector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class HttpClientDataCollector extends DataCollector implements LateDataCol
2626
/**
2727
* @var TraceableHttpClient[]
2828
*/
29-
private $clients = [];
29+
private array $clients = [];
3030

3131
public function registerClient(string $name, TraceableHttpClient $client)
3232
{

DecoratorTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
trait DecoratorTrait
2424
{
25-
private $client;
25+
private HttpClientInterface $client;
2626

2727
public function __construct(HttpClientInterface $client = null)
2828
{

EventSourceHttpClient.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class EventSourceHttpClient implements HttpClientInterface
3030
AsyncDecoratorTrait::withOptions insteadof HttpClientTrait;
3131
}
3232

33-
private $reconnectionTime;
33+
private float $reconnectionTime;
3434

3535
public function __construct(HttpClientInterface $client = null, float $reconnectionTime = 10.0)
3636
{
@@ -52,10 +52,10 @@ public function connect(string $url, array $options = []): ResponseInterface
5252
public function request(string $method, string $url, array $options = []): ResponseInterface
5353
{
5454
$state = new class() {
55-
public $buffer = null;
56-
public $lastEventId = null;
57-
public $reconnectionTime;
58-
public $lastError = null;
55+
public ?string $buffer = null;
56+
public ?string $lastEventId = null;
57+
public float $reconnectionTime;
58+
public ?float $lastError = null;
5959
};
6060
$state->reconnectionTime = $this->reconnectionTime;
6161

Exception/HttpExceptionTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
trait HttpExceptionTrait
2222
{
23-
private $response;
23+
private ResponseInterface $response;
2424

2525
public function __construct(ResponseInterface $response)
2626
{

HttpClientTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
trait HttpClientTrait
2525
{
26-
private static $CHUNK_SIZE = 16372;
26+
private static int $CHUNK_SIZE = 16372;
2727

2828
/**
2929
* {@inheritdoc}

HttpOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class HttpOptions
2424
{
25-
private $options = [];
25+
private array $options = [];
2626

2727
public function toArray(): array
2828
{

HttplugClient.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,34 @@
5757
*/
5858
final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory
5959
{
60-
private $client;
61-
private $responseFactory;
62-
private $streamFactory;
63-
private $promisePool;
64-
private $waitLoop;
60+
private HttpClientInterface $client;
61+
private ResponseFactoryInterface $responseFactory;
62+
private StreamFactoryInterface $streamFactory;
63+
private ?\SplObjectStorage $promisePool;
64+
private HttplugWaitLoop $waitLoop;
6565

6666
public function __construct(HttpClientInterface $client = null, ResponseFactoryInterface $responseFactory = null, StreamFactoryInterface $streamFactory = null)
6767
{
6868
$this->client = $client ?? HttpClient::create();
69-
$this->responseFactory = $responseFactory;
70-
$this->streamFactory = $streamFactory ?? ($responseFactory instanceof StreamFactoryInterface ? $responseFactory : null);
69+
$streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null;
7170
$this->promisePool = \function_exists('GuzzleHttp\Promise\queue') ? new \SplObjectStorage() : null;
7271

73-
if (null === $this->responseFactory || null === $this->streamFactory) {
72+
if (null === $responseFactory || null === $streamFactory) {
7473
if (!class_exists(Psr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) {
7574
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
7675
}
7776

7877
try {
7978
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
80-
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
81-
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
79+
$responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
80+
$streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
8281
} catch (NotFoundException $e) {
8382
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
8483
}
8584
}
8685

86+
$this->responseFactory = $responseFactory;
87+
$this->streamFactory = $streamFactory;
8788
$this->waitLoop = new HttplugWaitLoop($this->client, $this->promisePool, $this->responseFactory, $this->streamFactory);
8889
}
8990

Internal/AmpBody.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
*/
2626
class AmpBody implements RequestBody, InputStream
2727
{
28-
private $body;
29-
private $onProgress;
30-
private $offset = 0;
31-
private $length = -1;
32-
private $uploaded;
33-
28+
private ResourceInputStream|\Closure|string $body;
29+
private \Closure $onProgress;
30+
private ?int $offset = 0;
31+
private int $length = -1;
32+
private ?int $uploaded = null;
33+
34+
/**
35+
* @param \Closure|resource|string $body
36+
*/
3437
public function __construct($body, &$info, \Closure $onProgress)
3538
{
36-
$this->body = $body;
3739
$this->info = &$info;
3840
$this->onProgress = $onProgress;
3941

@@ -43,6 +45,9 @@ public function __construct($body, &$info, \Closure $onProgress)
4345
$this->body = new ResourceInputStream($body);
4446
} elseif (\is_string($body)) {
4547
$this->length = \strlen($body);
48+
$this->body = $body;
49+
} else {
50+
$this->body = $body;
4651
}
4752
}
4853

Internal/AmpClientState.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@
4141
*/
4242
final class AmpClientState extends ClientState
4343
{
44-
public $dnsCache = [];
45-
public $responseCount = 0;
46-
public $pushedResponses = [];
44+
public array $dnsCache = [];
45+
public int $responseCount = 0;
46+
public array $pushedResponses = [];
4747

48-
private $clients = [];
49-
private $clientConfigurator;
50-
private $maxHostConnections;
51-
private $maxPendingPushes;
52-
private $logger;
48+
private array $clients = [];
49+
private \Closure $clientConfigurator;
50+
private int $maxHostConnections;
51+
private int $maxPendingPushes;
52+
private ?LoggerInterface $logger;
5353

5454
public function __construct(?callable $clientConfigurator, int $maxHostConnections, int $maxPendingPushes, ?LoggerInterface &$logger)
5555
{
56-
$this->clientConfigurator = $clientConfigurator ?? static function (PooledHttpClient $client) {
57-
return new InterceptedHttpClient($client, new RetryRequests(2));
58-
};
56+
$clientConfigurator ??= static fn (PooledHttpClient $client) => new InterceptedHttpClient($client, new RetryRequests(2));
57+
$this->clientConfigurator = $clientConfigurator instanceof \Closure ? $clientConfigurator : \Closure::fromCallable($clientConfigurator);
58+
5959
$this->maxHostConnections = $maxHostConnections;
6060
$this->maxPendingPushes = $maxPendingPushes;
6161
$this->logger = &$logger;

Internal/AmpListener.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
*/
2626
class AmpListener implements EventListener
2727
{
28-
private $info;
29-
private $pinSha256;
30-
private $onProgress;
28+
private array $info;
29+
private array $pinSha256;
30+
private \Closure $onProgress;
3131
private $handle;
3232

3333
public function __construct(array &$info, array $pinSha256, \Closure $onProgress, &$handle)

Internal/AmpResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class AmpResolver implements Dns\Resolver
2727
{
28-
private $dnsMap;
28+
private array $dnsMap;
2929

3030
public function __construct(array &$dnsMap)
3131
{

Internal/Canary.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
final class Canary
2020
{
21-
private $canceller;
21+
private \Closure $canceller;
2222

2323
public function __construct(\Closure $canceller)
2424
{
@@ -27,8 +27,9 @@ public function __construct(\Closure $canceller)
2727

2828
public function cancel()
2929
{
30-
if (($canceller = $this->canceller) instanceof \Closure) {
31-
$this->canceller = null;
30+
if (isset($this->canceller)) {
31+
$canceller = $this->canceller;
32+
unset($this->canceller);
3233
$canceller();
3334
}
3435
}

Internal/ClientState.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ClientState
2222
{
23-
public $handlesActivity = [];
24-
public $openHandles = [];
25-
public $lastTimeout;
23+
public array $handlesActivity = [];
24+
public array $openHandles = [];
25+
public ?float $lastTimeout = null;
2626
}

Internal/CurlClientState.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@
2222
*/
2323
final class CurlClientState extends ClientState
2424
{
25-
/** @var \CurlMultiHandle */
26-
public $handle;
25+
public \CurlMultiHandle $handle;
2726
/** @var PushedResponse[] */
28-
public $pushedResponses = [];
29-
/** @var DnsCache */
30-
public $dnsCache;
27+
public array $pushedResponses = [];
28+
public DnsCache $dnsCache;
3129
/** @var float[] */
32-
public $pauseExpiries = [];
33-
public $execCounter = \PHP_INT_MIN;
34-
/** @var LoggerInterface|null */
35-
public $logger;
30+
public array $pauseExpiries = [];
31+
public int $execCounter = \PHP_INT_MIN;
32+
public ?LoggerInterface $logger = null;
3633

3734
public function __construct()
3835
{

Internal/DnsCache.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ final class DnsCache
2525
*
2626
* @var string[]
2727
*/
28-
public $hostnames = [];
28+
public array $hostnames = [];
2929

3030
/**
3131
* @var string[]
3232
*/
33-
public $removals = [];
33+
public array $removals = [];
3434

3535
/**
3636
* @var string[]
3737
*/
38-
public $evictions = [];
38+
public array $evictions = [];
3939
}

Internal/HttplugWaitLoop.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
*/
2929
final class HttplugWaitLoop
3030
{
31-
private $client;
32-
private $promisePool;
33-
private $responseFactory;
34-
private $streamFactory;
31+
private HttpClientInterface $client;
32+
private ?\SplObjectStorage $promisePool;
33+
private ResponseFactoryInterface $responseFactory;
34+
private StreamFactoryInterface $streamFactory;
3535

3636
public function __construct(HttpClientInterface $client, ?\SplObjectStorage $promisePool, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
3737
{

0 commit comments

Comments
 (0)