Skip to content

Commit 5e746fb

Browse files
committed
Add types where possible
1 parent b7e032b commit 5e746fb

19 files changed

+44
-38
lines changed

src/BatchClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
5252
* BatchResult with a map of request to result for success, request to
5353
* exception for failures
5454
*/
55-
public function sendRequests(array $requests)
55+
public function sendRequests(array $requests): BatchResult
5656
{
5757
$batchResult = new BatchResult();
5858

src/BatchResult.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct()
3434
*
3535
* @return bool
3636
*/
37-
public function hasResponses()
37+
public function hasResponses(): bool
3838
{
3939
return $this->responses->count() > 0;
4040
}
@@ -44,7 +44,7 @@ public function hasResponses()
4444
*
4545
* @return ResponseInterface[]
4646
*/
47-
public function getResponses()
47+
public function getResponses(): array
4848
{
4949
$responses = [];
5050

@@ -62,7 +62,7 @@ public function getResponses()
6262
*
6363
* @return bool
6464
*/
65-
public function isSuccessful(RequestInterface $request)
65+
public function isSuccessful(RequestInterface $request): bool
6666
{
6767
return $this->responses->contains($request);
6868
}
@@ -76,7 +76,7 @@ public function isSuccessful(RequestInterface $request)
7676
*
7777
* @throws \UnexpectedValueException If request was not part of the batch or failed
7878
*/
79-
public function getResponseFor(RequestInterface $request)
79+
public function getResponseFor(RequestInterface $request): ResponseInterface
8080
{
8181
try {
8282
return $this->responses[$request];
@@ -93,7 +93,7 @@ public function getResponseFor(RequestInterface $request)
9393
*
9494
* @return BatchResult the new BatchResult with this request-response pair added to it
9595
*/
96-
public function addResponse(RequestInterface $request, ResponseInterface $response)
96+
public function addResponse(RequestInterface $request, ResponseInterface $response): BatchResult
9797
{
9898
$new = clone $this;
9999
$new->responses->attach($request, $response);
@@ -106,7 +106,7 @@ public function addResponse(RequestInterface $request, ResponseInterface $respon
106106
*
107107
* @return bool
108108
*/
109-
public function hasExceptions()
109+
public function hasExceptions(): bool
110110
{
111111
return $this->exceptions->count() > 0;
112112
}
@@ -116,7 +116,7 @@ public function hasExceptions()
116116
*
117117
* @return Exception[]
118118
*/
119-
public function getExceptions()
119+
public function getExceptions(): array
120120
{
121121
$exceptions = [];
122122

@@ -134,7 +134,7 @@ public function getExceptions()
134134
*
135135
* @return bool
136136
*/
137-
public function isFailed(RequestInterface $request)
137+
public function isFailed(RequestInterface $request): bool
138138
{
139139
return $this->exceptions->contains($request);
140140
}
@@ -148,7 +148,7 @@ public function isFailed(RequestInterface $request)
148148
*
149149
* @throws \UnexpectedValueException If request was not part of the batch or was successful
150150
*/
151-
public function getExceptionFor(RequestInterface $request)
151+
public function getExceptionFor(RequestInterface $request): Exception
152152
{
153153
try {
154154
return $this->exceptions[$request];
@@ -165,7 +165,7 @@ public function getExceptionFor(RequestInterface $request)
165165
*
166166
* @return BatchResult the new BatchResult with this request-exception pair added to it
167167
*/
168-
public function addException(RequestInterface $request, Exception $exception)
168+
public function addException(RequestInterface $request, Exception $exception): BatchResult
169169
{
170170
$new = clone $this;
171171
$new->exceptions->attach($request, $exception);

src/Deferred.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(callable $waitCallback)
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function then(callable $onFulfilled = null, callable $onRejected = null)
37+
public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
3838
{
3939
$deferred = new self($this->waitCallback);
4040

@@ -69,13 +69,15 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function getState()
72+
public function getState(): string
7373
{
7474
return $this->state;
7575
}
7676

7777
/**
7878
* Resolve this deferred with a Response.
79+
*
80+
* @param ResponseInterface $response
7981
*/
8082
public function resolve(ResponseInterface $response)
8183
{
@@ -93,6 +95,8 @@ public function resolve(ResponseInterface $response)
9395

9496
/**
9597
* Reject this deferred with an Exception.
98+
*
99+
* @param Exception $exception
96100
*/
97101
public function reject(Exception $exception)
98102
{

src/FlexibleHttpClient.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Http\Client\HttpAsyncClient;
66
use Http\Client\HttpClient;
7+
use Psr\Http\Client\ClientInterface;
78

89
/**
910
* A flexible http client, which implements both interface and will emulate

src/HttpAsyncClientDecorator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Client\Common;
44

55
use Http\Client\HttpAsyncClient;
6+
use Http\Promise\Promise;
67
use Psr\Http\Message\RequestInterface;
78

89
/**

src/HttpClientPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function addHttpClient($client)
4040
*
4141
* @return HttpClientPoolItem Return a http client that can do both sync or async
4242
*/
43-
abstract protected function chooseHttpClient();
43+
abstract protected function chooseHttpClient(): HttpClientPoolItem;
4444

4545
/**
4646
* {@inheritdoc}

src/HttpClientPool/LeastUsedClientPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class LeastUsedClientPool extends HttpClientPool
1818
/**
1919
* {@inheritdoc}
2020
*/
21-
protected function chooseHttpClient()
21+
protected function chooseHttpClient(): HttpClientPoolItem
2222
{
2323
$clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) {
2424
return !$clientPoolItem->isDisabled();

src/HttpClientPool/RandomClientPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class RandomClientPool extends HttpClientPool
1616
/**
1717
* {@inheritdoc}
1818
*/
19-
protected function chooseHttpClient()
19+
protected function chooseHttpClient(): HttpClientPoolItem
2020
{
2121
$clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) {
2222
return !$clientPoolItem->isDisabled();

src/HttpClientPool/RoundRobinClientPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class RoundRobinClientPool extends HttpClientPool
1515
/**
1616
* {@inheritdoc}
1717
*/
18-
protected function chooseHttpClient()
18+
protected function chooseHttpClient(): HttpClientPoolItem
1919
{
2020
$last = current($this->clientPool);
2121

src/HttpClientRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function addClient($client, RequestMatcher $requestMatcher)
6262
*
6363
* @return HttpClient|HttpAsyncClient
6464
*/
65-
protected function chooseHttpClient(RequestInterface $request)
65+
private function chooseHttpClient(RequestInterface $request)
6666
{
6767
foreach ($this->clients as $client) {
6868
if ($client['matcher']->matches($request)) {

src/HttpMethodsClient.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(HttpClient $httpClient, RequestFactory $requestFacto
5656
*
5757
* @return ResponseInterface
5858
*/
59-
public function get($uri, array $headers = [])
59+
public function get($uri, array $headers = []): ResponseInterface
6060
{
6161
return $this->send('GET', $uri, $headers, null);
6262
}
@@ -71,7 +71,7 @@ public function get($uri, array $headers = [])
7171
*
7272
* @return ResponseInterface
7373
*/
74-
public function head($uri, array $headers = [])
74+
public function head($uri, array $headers = []): ResponseInterface
7575
{
7676
return $this->send('HEAD', $uri, $headers, null);
7777
}
@@ -86,7 +86,7 @@ public function head($uri, array $headers = [])
8686
*
8787
* @return ResponseInterface
8888
*/
89-
public function trace($uri, array $headers = [])
89+
public function trace($uri, array $headers = []): ResponseInterface
9090
{
9191
return $this->send('TRACE', $uri, $headers, null);
9292
}
@@ -102,7 +102,7 @@ public function trace($uri, array $headers = [])
102102
*
103103
* @return ResponseInterface
104104
*/
105-
public function post($uri, array $headers = [], $body = null)
105+
public function post($uri, array $headers = [], $body = null): ResponseInterface
106106
{
107107
return $this->send('POST', $uri, $headers, $body);
108108
}
@@ -118,7 +118,7 @@ public function post($uri, array $headers = [], $body = null)
118118
*
119119
* @return ResponseInterface
120120
*/
121-
public function put($uri, array $headers = [], $body = null)
121+
public function put($uri, array $headers = [], $body = null): ResponseInterface
122122
{
123123
return $this->send('PUT', $uri, $headers, $body);
124124
}
@@ -134,7 +134,7 @@ public function put($uri, array $headers = [], $body = null)
134134
*
135135
* @return ResponseInterface
136136
*/
137-
public function patch($uri, array $headers = [], $body = null)
137+
public function patch($uri, array $headers = [], $body = null): ResponseInterface
138138
{
139139
return $this->send('PATCH', $uri, $headers, $body);
140140
}
@@ -150,7 +150,7 @@ public function patch($uri, array $headers = [], $body = null)
150150
*
151151
* @return ResponseInterface
152152
*/
153-
public function delete($uri, array $headers = [], $body = null)
153+
public function delete($uri, array $headers = [], $body = null): ResponseInterface
154154
{
155155
return $this->send('DELETE', $uri, $headers, $body);
156156
}
@@ -166,7 +166,7 @@ public function delete($uri, array $headers = [], $body = null)
166166
*
167167
* @return ResponseInterface
168168
*/
169-
public function options($uri, array $headers = [], $body = null)
169+
public function options($uri, array $headers = [], $body = null): ResponseInterface
170170
{
171171
return $this->send('OPTIONS', $uri, $headers, $body);
172172
}
@@ -183,7 +183,7 @@ public function options($uri, array $headers = [], $body = null)
183183
*
184184
* @return ResponseInterface
185185
*/
186-
public function send($method, $uri, array $headers = [], $body = null)
186+
public function send($method, $uri, array $headers = [], $body = null): ResponseInterface
187187
{
188188
return $this->sendRequest($this->requestFactory->createRequest(
189189
$method,

src/Plugin/ContentTypePlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ final class ContentTypePlugin implements Plugin
2222
* true skip the content type detection
2323
* false detect the content type (default value)
2424
*/
25-
protected $skipDetection;
25+
private $skipDetection;
2626

2727
/**
2828
* Determine the size stream limit for which the detection as to be skipped (default to 16Mb).
2929
*
3030
* @var int
3131
*/
32-
protected $sizeLimit;
32+
private $sizeLimit;
3333

3434
/**
3535
* @param array $config {
@@ -96,7 +96,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
9696
*
9797
* @return bool
9898
*/
99-
private function isJson($stream)
99+
private function isJson($stream): bool
100100
{
101101
$stream->rewind();
102102

src/Plugin/CookiePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function createCookie(RequestInterface $request, $setCookie)
103103
$parts = array_map('trim', explode(';', $setCookie));
104104

105105
if (empty($parts) || !strpos($parts[0], '=')) {
106-
return;
106+
return null;
107107
}
108108

109109
list($name, $cookieValue) = $this->createValueKey(array_shift($parts));

src/Plugin/ErrorPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
6666
*
6767
* @return ResponseInterface If status code is not in 4xx or 5xx return response
6868
*/
69-
protected function transformResponseToException(RequestInterface $request, ResponseInterface $response)
69+
private function transformResponseToException(RequestInterface $request, ResponseInterface $response): ResponseInterface
7070
{
7171
if (!$this->onlyServerException && $response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
7272
throw new ClientErrorException($response->getReasonPhrase(), $request, $response);

src/Plugin/HeaderAppendPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class HeaderAppendPlugin implements Plugin
2121
/**
2222
* @var array
2323
*/
24-
private $headers = [];
24+
private $headers;
2525

2626
/**
2727
* @param array $headers Hashmap of header name to header value

src/Plugin/HeaderSetPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class HeaderSetPlugin implements Plugin
1717
/**
1818
* @var array
1919
*/
20-
private $headers = [];
20+
private $headers;
2121

2222
/**
2323
* @param array $headers Hashmap of header name to header value

src/Plugin/RedirectPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected function buildRedirectRequest(RequestInterface $request, UriInterface
218218
*
219219
* @return UriInterface
220220
*/
221-
private function createUri(ResponseInterface $response, RequestInterface $request)
221+
private function createUri(ResponseInterface $response, RequestInterface $request): UriInterface
222222
{
223223
if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) {
224224
throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response);

src/PluginClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function sendAsyncRequest(RequestInterface $request)
107107
*
108108
* @return array
109109
*/
110-
private function configure(array $options = [])
110+
private function configure(array $options = []): array
111111
{
112112
if (isset($options['debug_plugins'])) {
113113
@trigger_error('The "debug_plugins" option is deprecated since 1.5 and will be removed in 2.0.', E_USER_DEPRECATED);
@@ -143,7 +143,7 @@ private function configure(array $options = [])
143143
*
144144
* @return callable
145145
*/
146-
private function createPluginChain($pluginList, callable $clientCallable)
146+
private function createPluginChain(array $pluginList, callable $clientCallable): callable
147147
{
148148
$firstCallable = $lastCallable = $clientCallable;
149149

src/PluginClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function setFactory(callable $factory)
4747
*
4848
* @return PluginClient
4949
*/
50-
public function createClient($client, array $plugins = [], array $options = [])
50+
public function createClient($client, array $plugins = [], array $options = []): PluginClient
5151
{
5252
if (static::$factory) {
5353
$factory = static::$factory;

0 commit comments

Comments
 (0)