Skip to content

Commit 527b5eb

Browse files
committed
type declarations for php 7.1
1 parent 7656a55 commit 527b5eb

12 files changed

+32
-47
lines changed

src/Deferred.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function getState(): string
7979
/**
8080
* Resolve this deferred with a Response.
8181
*/
82-
public function resolve(ResponseInterface $response)
82+
public function resolve(ResponseInterface $response): void
8383
{
8484
if (self::PENDING !== $this->state) {
8585
return;
@@ -96,7 +96,7 @@ public function resolve(ResponseInterface $response)
9696
/**
9797
* Reject this deferred with an Exception.
9898
*/
99-
public function reject(Exception $exception)
99+
public function reject(Exception $exception): void
100100
{
101101
if (self::PENDING !== $this->state) {
102102
return;

src/Exception/BatchException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ public function __construct(BatchResult $result)
2828

2929
/**
3030
* Returns the BatchResult that contains all responses and exceptions.
31-
*
32-
* @return BatchResult
3331
*/
34-
public function getResult()
32+
public function getResult(): BatchResult
3533
{
3634
return $this->result;
3735
}

src/HttpClientPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ interface HttpClientPool extends HttpAsyncClient, HttpClient
2020
*
2121
* @param ClientInterface|HttpAsyncClient|HttpClientPoolItem $client
2222
*/
23-
public function addHttpClient($client);
23+
public function addHttpClient($client): void;
2424
}

src/HttpClientPool/HttpClientPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class HttpClientPool implements HttpClientPoolInterface
2727
*
2828
* @param ClientInterface|HttpAsyncClient|HttpClientPoolItem $client
2929
*/
30-
public function addHttpClient($client)
30+
public function addHttpClient($client): void
3131
{
3232
if (!$client instanceof HttpClientPoolItem) {
3333
$client = new HttpClientPoolItem($client);

src/HttpClientPool/HttpClientPoolItem.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,31 @@ public function getSendingRequestCount(): int
144144
/**
145145
* Increment the request count.
146146
*/
147-
private function incrementRequestCount()
147+
private function incrementRequestCount(): void
148148
{
149149
++$this->sendingRequestCount;
150150
}
151151

152152
/**
153153
* Decrement the request count.
154154
*/
155-
private function decrementRequestCount()
155+
private function decrementRequestCount(): void
156156
{
157157
--$this->sendingRequestCount;
158158
}
159159

160160
/**
161161
* Enable the current client.
162162
*/
163-
private function enable()
163+
private function enable(): void
164164
{
165165
$this->disabledAt = null;
166166
}
167167

168168
/**
169169
* Disable the current client.
170170
*/
171-
private function disable()
171+
private function disable(): void
172172
{
173173
$this->disabledAt = new \DateTime('now');
174174
}

src/HttpClientRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function sendAsyncRequest(RequestInterface $request)
4545
*
4646
* @param HttpClient|HttpAsyncClient $client
4747
*/
48-
public function addClient($client, RequestMatcher $requestMatcher)
48+
public function addClient($client, RequestMatcher $requestMatcher): void
4949
{
5050
$this->clients[] = [
5151
'matcher' => $requestMatcher,

src/HttpClientRouterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface HttpClientRouterInterface extends HttpClient, HttpAsyncClient
2323
*
2424
* @param ClientInterface|HttpAsyncClient $client
2525
*/
26-
public function addClient($client, RequestMatcher $requestMatcher);
26+
public function addClient($client, RequestMatcher $requestMatcher): void;
2727
}

src/HttpMethodsClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function options($uri, array $headers = [], $body = null): ResponseInterf
7171
return $this->send('OPTIONS', $uri, $headers, $body);
7272
}
7373

74-
public function send($method, $uri, array $headers = [], $body = null): ResponseInterface
74+
public function send(string $method, $uri, array $headers = [], $body = null): ResponseInterface
7575
{
7676
return $this->sendRequest($this->requestFactory->createRequest(
7777
$method,

src/HttpMethodsClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ public function options($uri, array $headers = [], $body = null): ResponseInterf
112112
*
113113
* @throws Exception
114114
*/
115-
public function send($method, $uri, array $headers = [], $body = null): ResponseInterface;
115+
public function send(string $method, $uri, array $headers = [], $body = null): ResponseInterface;
116116
}

src/Plugin/AddHostPlugin.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
return $next($request);
6767
}
6868

69-
private function configureOptions(OptionsResolver $resolver)
69+
private function configureOptions(OptionsResolver $resolver): void
7070
{
7171
$resolver->setDefaults([
7272
'replace' => false,

src/Plugin/CookiePlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
9191
/**
9292
* Creates a cookie from a string.
9393
*
94-
* @return Cookie|null
95-
*
9694
* @throws TransferException
9795
*/
98-
private function createCookie(RequestInterface $request, string $setCookieHeader)
96+
private function createCookie(RequestInterface $request, string $setCookieHeader): ?Cookie
9997
{
10098
$parts = array_map('trim', explode(';', $setCookieHeader));
10199

@@ -168,6 +166,8 @@ private function createCookie(RequestInterface $request, string $setCookieHeader
168166
* Separates key/value pair from cookie.
169167
*
170168
* @param string $part A single cookie value in format key=value
169+
*
170+
* @return string[]
171171
*/
172172
private function createValueKey(string $part): array
173173
{

src/Plugin/RedirectPlugin.php

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Http\Client\Common\Plugin;
1010
use Http\Client\Exception\HttpException;
1111
use Http\Promise\Promise;
12-
use Psr\Http\Message\MessageInterface;
1312
use Psr\Http\Message\RequestInterface;
1413
use Psr\Http\Message\ResponseInterface;
1514
use Psr\Http\Message\UriInterface;
@@ -180,63 +179,51 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
180179
});
181180
}
182181

183-
/**
184-
* Builds the redirect request.
185-
*
186-
* @param RequestInterface $request Original request
187-
* @param UriInterface $uri New uri
188-
* @param int $statusCode Status code from the redirect response
189-
*
190-
* @return MessageInterface|RequestInterface
191-
*/
192-
private function buildRedirectRequest(RequestInterface $request, UriInterface $uri, $statusCode)
182+
private function buildRedirectRequest(RequestInterface $originalRequest, UriInterface $targetUri, int $statusCode): RequestInterface
193183
{
194-
$request = $request->withUri($uri);
184+
$originalRequest = $originalRequest->withUri($targetUri);
195185

196-
if (false !== $this->redirectCodes[$statusCode]['switch'] && !in_array($request->getMethod(), $this->redirectCodes[$statusCode]['switch']['unless'])) {
197-
$request = $request->withMethod($this->redirectCodes[$statusCode]['switch']['to']);
186+
if (false !== $this->redirectCodes[$statusCode]['switch'] && !in_array($originalRequest->getMethod(), $this->redirectCodes[$statusCode]['switch']['unless'])) {
187+
$originalRequest = $originalRequest->withMethod($this->redirectCodes[$statusCode]['switch']['to']);
198188
}
199189

200190
if (is_array($this->preserveHeader)) {
201-
$headers = array_keys($request->getHeaders());
191+
$headers = array_keys($originalRequest->getHeaders());
202192

203193
foreach ($headers as $name) {
204194
if (!in_array($name, $this->preserveHeader)) {
205-
$request = $request->withoutHeader($name);
195+
$originalRequest = $originalRequest->withoutHeader($name);
206196
}
207197
}
208198
}
209199

210-
return $request;
200+
return $originalRequest;
211201
}
212202

213203
/**
214204
* Creates a new Uri from the old request and the location header.
215205
*
216-
* @param ResponseInterface $response The redirect response
217-
* @param RequestInterface $request The original request
218-
*
219206
* @throws HttpException If location header is not usable (missing or incorrect)
220207
* @throws MultipleRedirectionException If a 300 status code is received and default location cannot be resolved (doesn't use the location header or not present)
221208
*/
222-
private function createUri(ResponseInterface $response, RequestInterface $request): UriInterface
209+
private function createUri(ResponseInterface $redirectResponse, RequestInterface $originalRequest): UriInterface
223210
{
224-
if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) {
225-
throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response);
211+
if ($this->redirectCodes[$redirectResponse->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$redirectResponse->hasHeader('Location'))) {
212+
throw new MultipleRedirectionException('Cannot choose a redirection', $originalRequest, $redirectResponse);
226213
}
227214

228-
if (!$response->hasHeader('Location')) {
229-
throw new HttpException('Redirect status code, but no location header present in the response', $request, $response);
215+
if (!$redirectResponse->hasHeader('Location')) {
216+
throw new HttpException('Redirect status code, but no location header present in the response', $originalRequest, $redirectResponse);
230217
}
231218

232-
$location = $response->getHeaderLine('Location');
219+
$location = $redirectResponse->getHeaderLine('Location');
233220
$parsedLocation = parse_url($location);
234221

235222
if (false === $parsedLocation) {
236-
throw new HttpException(sprintf('Location %s could not be parsed', $location), $request, $response);
223+
throw new HttpException(sprintf('Location %s could not be parsed', $location), $originalRequest, $redirectResponse);
237224
}
238225

239-
$uri = $request->getUri();
226+
$uri = $originalRequest->getUri();
240227

241228
if (array_key_exists('scheme', $parsedLocation)) {
242229
$uri = $uri->withScheme($parsedLocation['scheme']);

0 commit comments

Comments
 (0)