diff --git a/src/ContentLengthPlugin.php b/src/ContentLengthPlugin.php index afab963..665f1e2 100644 --- a/src/ContentLengthPlugin.php +++ b/src/ContentLengthPlugin.php @@ -6,14 +6,14 @@ use Psr\Http\Message\RequestInterface; /** - * Allow to set the correct content length header on the request or to transfer it as a chunk if not possible + * Allow to set the correct content length header on the request or to transfer it as a chunk if not possible. * * @author Joel Wurtz */ class ContentLengthPlugin implements Plugin { /** - * {@inheritDoc} + * {@inheritdoc} */ public function handleRequest(RequestInterface $request, callable $next, callable $first) { diff --git a/src/CookiePlugin.php b/src/CookiePlugin.php index 72a5f90..22ef116 100644 --- a/src/CookiePlugin.php +++ b/src/CookiePlugin.php @@ -15,7 +15,7 @@ class CookiePlugin implements Plugin { /** - * Cookie storage + * Cookie storage. * * @var CookieJar */ @@ -54,7 +54,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $request = $request->withAddedHeader('Cookie', sprintf('%s=%s', $cookie->getName(), $cookie->getValue())); } - return $next($request)->then(function (ResponseInterface $response) use($request) { + return $next($request)->then(function (ResponseInterface $response) use ($request) { if ($response->hasHeader('Set-Cookie')) { $setCookies = $response->getHeader('Set-Cookie'); @@ -92,15 +92,15 @@ private function createCookie(RequestInterface $request, $setCookie) $parts = array_map('trim', explode(';', $setCookie)); if (empty($parts) || !strpos($parts[0], '=')) { - return null; + return; } list($name, $cookieValue) = $this->createValueKey(array_shift($parts)); - $expires = 0; - $domain = $request->getUri()->getHost(); - $path = $request->getUri()->getPath(); - $secure = false; + $expires = 0; + $domain = $request->getUri()->getHost(); + $path = $request->getUri()->getPath(); + $secure = false; $httpOnly = false; // Add the cookie pieces into the parsed data array @@ -113,7 +113,7 @@ private function createCookie(RequestInterface $request, $setCookie) break; case 'max-age': - $expires = (new \DateTime())->add(new \DateInterval('PT' . (int)$value . 'S')); + $expires = (new \DateTime())->add(new \DateInterval('PT'.(int) $value.'S')); break; case 'domain': @@ -147,7 +147,7 @@ private function createCookie(RequestInterface $request, $setCookie) private function createValueKey($part) { $parts = explode('=', $part, 2); - $key = trim($parts[0]); + $key = trim($parts[0]); $value = isset($parts[1]) ? trim($parts[1]) : true; return [$key, $value]; diff --git a/src/DecoderPlugin.php b/src/DecoderPlugin.php index bc844b2..a85f9e7 100644 --- a/src/DecoderPlugin.php +++ b/src/DecoderPlugin.php @@ -2,7 +2,6 @@ namespace Http\Client\Plugin; -use Http\Client\Exception; use Http\Encoding\DechunkStream; use Http\Encoding\DecompressStream; use Http\Encoding\GzipDecodeStream; @@ -12,7 +11,7 @@ use Psr\Http\Message\StreamInterface; /** - * Allow to decode response body with a chunk, deflate, compress or gzip encoding + * Allow to decode response body with a chunk, deflate, compress or gzip encoding. * * @author Joel Wurtz */ @@ -36,7 +35,7 @@ public function __construct($useContentEncoding = true) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function handleRequest(RequestInterface $request, callable $next, callable $first) { @@ -52,7 +51,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl } /** - * Decode a response body given its Transfer-Encoding or Content-Encoding value + * Decode a response body given its Transfer-Encoding or Content-Encoding value. * * @param ResponseInterface $response Response to decode * @@ -70,7 +69,7 @@ private function decodeResponse(ResponseInterface $response) } /** - * Decode a response on a specific header (content encoding or transfer encoding mainly) + * Decode a response on a specific header (content encoding or transfer encoding mainly). * * @param string $headerName Name of the header * @param ResponseInterface $response Response @@ -80,7 +79,7 @@ private function decodeResponse(ResponseInterface $response) private function decodeOnEncodingHeader($headerName, ResponseInterface $response) { if ($response->hasHeader($headerName)) { - $encodings = $response->getHeader($headerName); + $encodings = $response->getHeader($headerName); $newEncodings = []; while ($encoding = array_pop($encodings)) { @@ -102,7 +101,7 @@ private function decodeOnEncodingHeader($headerName, ResponseInterface $response } /** - * Decorate a stream given an encoding + * Decorate a stream given an encoding. * * @param string $encoding * @param StreamInterface $stream diff --git a/src/EmulateAsyncClient.php b/src/EmulateAsyncClient.php index 21fd368..05953d3 100644 --- a/src/EmulateAsyncClient.php +++ b/src/EmulateAsyncClient.php @@ -8,7 +8,7 @@ use Http\Client\Tools\HttpClientDecorator; /** - * Emulate an async client + * Emulate an async client. */ class EmulateAsyncClient implements HttpClient, HttpAsyncClient { diff --git a/src/ErrorPlugin.php b/src/ErrorPlugin.php index 776b678..092e01c 100644 --- a/src/ErrorPlugin.php +++ b/src/ErrorPlugin.php @@ -37,8 +37,8 @@ public function handleRequest(RequestInterface $request, callable $next, callabl { $promise = $next($request); - return $promise->then(function (ResponseInterface $response) use($request) { - if (preg_match('/'.$this->statusCodeRegex.'/', (string)$response->getStatusCode())) { + return $promise->then(function (ResponseInterface $response) use ($request) { + if (preg_match('/'.$this->statusCodeRegex.'/', (string) $response->getStatusCode())) { throw new HttpException('The server returned an error', $request, $response); } diff --git a/src/LoggerPlugin.php b/src/LoggerPlugin.php index f0dafa3..6bd232e 100644 --- a/src/LoggerPlugin.php +++ b/src/LoggerPlugin.php @@ -9,21 +9,21 @@ use Psr\Log\LoggerInterface; /** - * Log request, response and exception for a HTTP Client + * Log request, response and exception for a HTTP Client. * * @author Joel Wurtz */ class LoggerPlugin implements Plugin { /** - * Logger to log request / response / exception for a http call + * Logger to log request / response / exception for a http call. * * @var LoggerInterface */ private $logger; /** - * Normalize request and response to string or array + * Normalize request and response to string or array. * * @var Normalizer */ @@ -34,7 +34,7 @@ class LoggerPlugin implements Plugin */ public function __construct(LoggerInterface $logger) { - $this->logger = $logger; + $this->logger = $logger; $this->normalizer = new Normalizer(); } @@ -45,7 +45,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl { $this->logger->info(sprintf('Emit request: "%s"', $this->normalizer->normalizeRequestToString($request)), ['request' => $request]); - return $next($request)->then(function (ResponseInterface $response) use($request) { + return $next($request)->then(function (ResponseInterface $response) use ($request) { $this->logger->info( sprintf('Receive response: "%s" for request: "%s"', $this->normalizer->normalizeResponseToString($response), $this->normalizer->normalizeRequestToString($request)), [ @@ -55,14 +55,14 @@ public function handleRequest(RequestInterface $request, callable $next, callabl ); return $response; - }, function (Exception $exception) use($request) { + }, function (Exception $exception) use ($request) { if ($exception instanceof Exception\HttpException) { $this->logger->error( sprintf('Error: "%s" with response: "%s" when emitting request: "%s"', $exception->getMessage(), $this->normalizer->normalizeResponseToString($exception->getResponse()), $this->normalizer->normalizeRequestToString($request)), [ 'request' => $request, 'response' => $exception->getResponse(), - 'exception' => $exception + 'exception' => $exception, ] ); } else { @@ -70,7 +70,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl sprintf('Error: "%s" when emitting request: "%s"', $exception->getMessage(), $this->normalizer->normalizeRequestToString($request)), [ 'request' => $request, - 'exception' => $exception + 'exception' => $exception, ] ); } diff --git a/src/Normalizer/Normalizer.php b/src/Normalizer/Normalizer.php index 480a393..f76ed9f 100644 --- a/src/Normalizer/Normalizer.php +++ b/src/Normalizer/Normalizer.php @@ -6,7 +6,7 @@ use Psr\Http\Message\ResponseInterface; /** - * Normalize a request or a response into a string or an array + * Normalize a request or a response into a string or an array. * * @author Joel Wurtz * @@ -15,7 +15,7 @@ class Normalizer { /** - * Normalize a request to string + * Normalize a request to string. * * @param RequestInterface $request * @@ -27,7 +27,7 @@ public function normalizeRequestToString(RequestInterface $request) } /** - * Normalize a response to string + * Normalize a response to string. * * @param ResponseInterface $response * @@ -35,6 +35,6 @@ public function normalizeRequestToString(RequestInterface $request) */ public function normalizeResponseToString(ResponseInterface $response) { - return sprintf("%s %s %s", $response->getStatusCode(), $response->getReasonPhrase(), $response->getProtocolVersion()); + return sprintf('%s %s %s', $response->getStatusCode(), $response->getReasonPhrase(), $response->getProtocolVersion()); } } diff --git a/src/PluginClient.php b/src/PluginClient.php index f68d5d0..c8c5d59 100644 --- a/src/PluginClient.php +++ b/src/PluginClient.php @@ -4,7 +4,6 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; -use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -15,14 +14,14 @@ class PluginClient implements HttpClient, HttpAsyncClient { /** - * An HTTP async client + * An HTTP async client. * * @var HttpAsyncClient */ protected $client; /** - * The plugin chain + * The plugin chain. * * @var Plugin[] */ @@ -75,7 +74,7 @@ public function sendAsyncRequest(RequestInterface $request) private function createPluginChain($pluginList) { $client = $this->client; - $lastCallable = function (RequestInterface $request) use($client) { + $lastCallable = function (RequestInterface $request) use ($client) { return $client->sendAsyncRequest($request); }; diff --git a/src/RedirectPlugin.php b/src/RedirectPlugin.php index ce10088..6241837 100644 --- a/src/RedirectPlugin.php +++ b/src/RedirectPlugin.php @@ -5,7 +5,6 @@ use Http\Client\Exception\HttpException; use Http\Client\Plugin\Exception\CircularRedirectionException; use Http\Client\Plugin\Exception\MultipleRedirectionException; -use Http\Promise\Promise; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -27,7 +26,7 @@ class RedirectPlugin implements Plugin 300 => [ 'switch' => [ 'unless' => ['GET', 'HEAD'], - 'to' => 'GET' + 'to' => 'GET', ], 'multiple' => true, 'permanent' => false, @@ -35,7 +34,7 @@ class RedirectPlugin implements Plugin 301 => [ 'switch' => [ 'unless' => ['GET', 'HEAD'], - 'to' => 'GET' + 'to' => 'GET', ], 'multiple' => false, 'permanent' => true, @@ -43,7 +42,7 @@ class RedirectPlugin implements Plugin 302 => [ 'switch' => [ 'unless' => ['GET', 'HEAD'], - 'to' => 'GET' + 'to' => 'GET', ], 'multiple' => false, 'permanent' => false, @@ -51,7 +50,7 @@ class RedirectPlugin implements Plugin 303 => [ 'switch' => [ 'unless' => ['GET', 'HEAD'], - 'to' => 'GET' + 'to' => 'GET', ], 'multiple' => false, 'permanent' => false, @@ -65,7 +64,7 @@ class RedirectPlugin implements Plugin 'switch' => false, 'multiple' => false, 'permanent' => true, - ] + ], ]; /** @@ -122,7 +121,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl return $first($redirectRequest); } - return $next($request)->then(function (ResponseInterface $response) use($request, $first) { + return $next($request)->then(function (ResponseInterface $response) use ($request, $first) { $statusCode = $response->getStatusCode(); if (!array_key_exists($statusCode, $this->redirectCodes)) { @@ -131,7 +130,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $uri = $this->createUri($response, $request); $redirectRequest = $this->buildRedirectRequest($request, $uri, $statusCode); - $chainIdentifier = spl_object_hash((object)$first); + $chainIdentifier = spl_object_hash((object) $first); if (!array_key_exists($chainIdentifier, $this->circularDetection)) { $this->circularDetection[$chainIdentifier] = []; @@ -145,7 +144,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl if ($this->redirectCodes[$statusCode]['permanent']) { $this->redirectStorage[$request->getRequestTarget()] = [ - 'uri' => $uri, + 'uri' => $uri, 'status' => $statusCode, ]; } @@ -160,9 +159,9 @@ public function handleRequest(RequestInterface $request, callable $next, callabl /** * Builds the redirect request. * - * @param RequestInterface $request Original request - * @param UriInterface $uri New uri - * @param int $statusCode Status code from the redirect response + * @param RequestInterface $request Original request + * @param UriInterface $uri New uri + * @param int $statusCode Status code from the redirect response * * @return MessageInterface|RequestInterface */ @@ -193,7 +192,7 @@ protected function buildRedirectRequest(RequestInterface $request, UriInterface * @param ResponseInterface $response The redirect response * @param RequestInterface $request The original request * - * @throws HttpException If location header is not usable (missing or incorrect) + * @throws HttpException If location header is not usable (missing or incorrect) * @throws MultipleRedirectionException If a 300 status code is received and default location cannot be resolved (doesn't use the location header or not present) * * @return UriInterface @@ -201,7 +200,7 @@ protected function buildRedirectRequest(RequestInterface $request, UriInterface private function createUri(ResponseInterface $response, RequestInterface $request) { if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) { - throw new MultipleRedirectionException("Cannot choose a redirection", $request, $response); + throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response); } if (!$response->hasHeader('Location')) { diff --git a/src/RetryPlugin.php b/src/RetryPlugin.php index 2dd8c65..d4cf01b 100644 --- a/src/RetryPlugin.php +++ b/src/RetryPlugin.php @@ -3,8 +3,6 @@ namespace Http\Client\Plugin; use Http\Client\Exception; -use Http\Client\Plugin\Exception\RetryException; -use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -44,9 +42,9 @@ public function __construct($retry = 1) */ public function handleRequest(RequestInterface $request, callable $next, callable $first) { - $chainIdentifier = spl_object_hash((object)$first); + $chainIdentifier = spl_object_hash((object) $first); - return $next($request)->then(function (ResponseInterface $response) use($request, $chainIdentifier) { + return $next($request)->then(function (ResponseInterface $response) use ($request, $chainIdentifier) { if (array_key_exists($chainIdentifier, $this->retryStorage)) { unset($this->retryStorage[$chainIdentifier]); } @@ -63,7 +61,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl throw $exception; } - $this->retryStorage[$chainIdentifier]++; + ++$this->retryStorage[$chainIdentifier]; // Retry in synchrone $promise = $this->handleRequest($request, $next, $first); diff --git a/src/StopwatchPlugin.php b/src/StopwatchPlugin.php index 1d2f2f0..48ce9ce 100644 --- a/src/StopwatchPlugin.php +++ b/src/StopwatchPlugin.php @@ -37,11 +37,11 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $eventName = $this->getStopwatchEventName($request); $this->stopwatch->start($eventName, self::CATEGORY); - return $next($request)->then(function (ResponseInterface $response) use($eventName) { + return $next($request)->then(function (ResponseInterface $response) use ($eventName) { $this->stopwatch->stop($eventName, self::CATEGORY); return $response; - }, function (Exception $exception) use($eventName) { + }, function (Exception $exception) use ($eventName) { $this->stopwatch->stop($eventName, self::CATEGORY); throw $exception;