Skip to content

Commit 122ff53

Browse files
dbuNyholm
authored andcommitted
typehint psr exceptions (#161)
* typehint psr exceptions * cs
1 parent f9f44c6 commit 122ff53

File tree

6 files changed

+11
-23
lines changed

6 files changed

+11
-23
lines changed

src/BatchClient.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace Http\Client\Common;
66

7-
use Http\Client\Exception;
87
use Http\Client\Common\Exception\BatchException;
8+
use Psr\Http\Client\ClientExceptionInterface;
99
use Psr\Http\Client\ClientInterface;
10-
use Psr\Http\Message\RequestInterface;
11-
use Psr\Http\Message\ResponseInterface;
1210

1311
final class BatchClient implements BatchClientInterface
1412
{
@@ -22,20 +20,15 @@ public function __construct(ClientInterface $client)
2220
$this->client = $client;
2321
}
2422

25-
public function sendRequest(RequestInterface $request): ResponseInterface
26-
{
27-
return $this->client->sendRequest($request);
28-
}
29-
3023
public function sendRequests(array $requests): BatchResult
3124
{
3225
$batchResult = new BatchResult();
3326

3427
foreach ($requests as $request) {
3528
try {
36-
$response = $this->sendRequest($request);
29+
$response = $this->client->sendRequest($request);
3730
$batchResult = $batchResult->addResponse($request, $response);
38-
} catch (Exception $e) {
31+
} catch (ClientExceptionInterface $e) {
3932
$batchResult = $batchResult->addException($request, $e);
4033
}
4134
}

src/BatchClientInterface.php

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

55
namespace Http\Client\Common;
66

7-
use Http\Client\HttpClient;
87
use Http\Client\Common\Exception\BatchException;
98
use Psr\Http\Message\RequestInterface;
109

@@ -15,7 +14,7 @@
1514
*
1615
* @author Joel Wurtz <[email protected]>
1716
*/
18-
interface BatchClientInterface extends HttpClient
17+
interface BatchClientInterface
1918
{
2019
/**
2120
* Send several requests.

src/BatchResult.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Http\Client\Common;
66

7-
use Http\Client\Exception;
7+
use Psr\Http\Client\ClientExceptionInterface;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
1010

@@ -102,7 +102,7 @@ public function hasExceptions(): bool
102102
/**
103103
* Returns all exceptions for the unsuccessful requests.
104104
*
105-
* @return Exception[]
105+
* @return ClientExceptionInterface[]
106106
*/
107107
public function getExceptions(): array
108108
{
@@ -129,7 +129,7 @@ public function isFailed(RequestInterface $request): bool
129129
*
130130
* @throws \UnexpectedValueException If request was not part of the batch or was successful
131131
*/
132-
public function getExceptionFor(RequestInterface $request): Exception
132+
public function getExceptionFor(RequestInterface $request): ClientExceptionInterface
133133
{
134134
try {
135135
return $this->exceptions[$request];
@@ -143,7 +143,7 @@ public function getExceptionFor(RequestInterface $request): Exception
143143
*
144144
* @return BatchResult the new BatchResult with this request-exception pair added to it
145145
*/
146-
public function addException(RequestInterface $request, Exception $exception): self
146+
public function addException(RequestInterface $request, ClientExceptionInterface $exception): self
147147
{
148148
$new = clone $this;
149149
$new->exceptions->attach($request, $exception);

src/HttpClientPool/HttpClientPoolItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class HttpClientPoolItem implements HttpClient, HttpAsyncClient
5555

5656
/**
5757
* @param ClientInterface|HttpAsyncClient $client
58-
* @param null|int $reenableAfter Number of seconds until this client is enabled again after an error
58+
* @param int|null $reenableAfter Number of seconds until this client is enabled again after an error
5959
*/
6060
public function __construct($client, $reenableAfter = null)
6161
{

src/HttpMethodsClient.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ final class HttpMethodsClient implements HttpMethodsClientInterface
2121
*/
2222
private $requestFactory;
2323

24-
/**
25-
* @param ClientInterface $httpClient The client to send requests with
26-
* @param RequestFactory $requestFactory The message factory to create requests
27-
*/
2824
public function __construct(ClientInterface $httpClient, RequestFactory $requestFactory)
2925
{
3026
$this->httpClient = $httpClient;

src/Plugin/RequestMatcherPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ final class RequestMatcherPlugin implements Plugin
2222
private $requestMatcher;
2323

2424
/**
25-
* @var null|Plugin
25+
* @var Plugin|null
2626
*/
2727
private $successPlugin;
2828

2929
/**
30-
* @var null|Plugin
30+
* @var Plugin|null
3131
*/
3232
private $failurePlugin;
3333

0 commit comments

Comments
 (0)