Skip to content

Commit 5730342

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

11 files changed

+31
-45
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/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 & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -180,63 +180,51 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
180180
});
181181
}
182182

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)
183+
private function buildRedirectRequest(RequestInterface $originalRequest, UriInterface $targetUri, int $statusCode): RequestInterface
193184
{
194-
$request = $request->withUri($uri);
185+
$originalRequest = $originalRequest->withUri($targetUri);
195186

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']);
187+
if (false !== $this->redirectCodes[$statusCode]['switch'] && !in_array($originalRequest->getMethod(), $this->redirectCodes[$statusCode]['switch']['unless'])) {
188+
$originalRequest = $originalRequest->withMethod($this->redirectCodes[$statusCode]['switch']['to']);
198189
}
199190

200191
if (is_array($this->preserveHeader)) {
201-
$headers = array_keys($request->getHeaders());
192+
$headers = array_keys($originalRequest->getHeaders());
202193

203194
foreach ($headers as $name) {
204195
if (!in_array($name, $this->preserveHeader)) {
205-
$request = $request->withoutHeader($name);
196+
$originalRequest = $originalRequest->withoutHeader($name);
206197
}
207198
}
208199
}
209200

210-
return $request;
201+
return $originalRequest;
211202
}
212203

213204
/**
214205
* Creates a new Uri from the old request and the location header.
215206
*
216-
* @param ResponseInterface $response The redirect response
217-
* @param RequestInterface $request The original request
218-
*
219207
* @throws HttpException If location header is not usable (missing or incorrect)
220208
* @throws MultipleRedirectionException If a 300 status code is received and default location cannot be resolved (doesn't use the location header or not present)
221209
*/
222-
private function createUri(ResponseInterface $response, RequestInterface $request): UriInterface
210+
private function createUri(ResponseInterface $redirectResponse, RequestInterface $originalRequest): UriInterface
223211
{
224-
if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) {
225-
throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response);
212+
if ($this->redirectCodes[$redirectResponse->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$redirectResponse->hasHeader('Location'))) {
213+
throw new MultipleRedirectionException('Cannot choose a redirection', $originalRequest, $redirectResponse);
226214
}
227215

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

232-
$location = $response->getHeaderLine('Location');
220+
$location = $redirectResponse->getHeaderLine('Location');
233221
$parsedLocation = parse_url($location);
234222

235223
if (false === $parsedLocation) {
236-
throw new HttpException(sprintf('Location %s could not be parsed', $location), $request, $response);
224+
throw new HttpException(sprintf('Location %s could not be parsed', $location), $originalRequest, $redirectResponse);
237225
}
238226

239-
$uri = $request->getUri();
227+
$uri = $originalRequest->getUri();
240228

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

0 commit comments

Comments
 (0)