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)) {

0 commit comments

Comments
 (0)