Skip to content

Fixed code style #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ContentLengthPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
class ContentLengthPlugin implements Plugin
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
Expand Down
18 changes: 9 additions & 9 deletions src/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class CookiePlugin implements Plugin
{
/**
* Cookie storage
* Cookie storage.
*
* @var CookieJar
*/
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand All @@ -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':
Expand Down Expand Up @@ -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];
Expand Down
13 changes: 6 additions & 7 deletions src/DecoderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Http\Client\Plugin;

use Http\Client\Exception;
use Http\Encoding\DechunkStream;
use Http\Encoding\DecompressStream;
use Http\Encoding\GzipDecodeStream;
Expand All @@ -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 <[email protected]>
*/
Expand All @@ -36,7 +35,7 @@ public function __construct($useContentEncoding = true)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
Expand All @@ -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
*
Expand All @@ -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
Expand All @@ -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)) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/EmulateAsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Http\Client\Tools\HttpClientDecorator;

/**
* Emulate an async client
* Emulate an async client.
*/
class EmulateAsyncClient implements HttpClient, HttpAsyncClient
{
Expand Down
4 changes: 2 additions & 2 deletions src/ErrorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 8 additions & 8 deletions src/LoggerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
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
*/
Expand All @@ -34,7 +34,7 @@ class LoggerPlugin implements Plugin
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
$this->logger = $logger;
$this->normalizer = new Normalizer();
}

Expand All @@ -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)),
[
Expand All @@ -55,22 +55,22 @@ 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 {
$this->logger->error(
sprintf('Error: "%s" when emitting request: "%s"', $exception->getMessage(), $this->normalizer->normalizeRequestToString($request)),
[
'request' => $request,
'exception' => $exception
'exception' => $exception,
]
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Normalizer/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*
Expand All @@ -15,7 +15,7 @@
class Normalizer
{
/**
* Normalize a request to string
* Normalize a request to string.
*
* @param RequestInterface $request
*
Expand All @@ -27,14 +27,14 @@ public function normalizeRequestToString(RequestInterface $request)
}

/**
* Normalize a response to string
* Normalize a response to string.
*
* @param ResponseInterface $response
*
* @return string
*/
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());
}
}
7 changes: 3 additions & 4 deletions src/PluginClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;

/**
Expand All @@ -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[]
*/
Expand Down Expand Up @@ -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);
};

Expand Down
Loading