Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
shulard committed Dec 11, 2015
1 parent fa572bc commit cde88a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/ReactFactory.php
Expand Up @@ -48,7 +48,7 @@ public static function buildHttpClient(
LoopInterface $loop,
DnsResolver $dns = null
) {
if( null === $dns ) {
if (null === $dns) {
$dns = self::buildDnsResolver($loop);
}

Expand Down
22 changes: 10 additions & 12 deletions src/ReactHttpAdapter.php
Expand Up @@ -7,14 +7,12 @@
use React\HttpClient\Client;
use React\HttpClient\Request as ReactRequest;
use React\HttpClient\Response as ReactResponse;

use Http\Client\HttpClient;
use Http\Client\HttpAsyncClient;
use Http\Client\Promise;
use Http\Client\Exception\HttpException;
use Http\Client\Exception\RequestException;
use Http\Message\MessageFactory;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamInterface;

Expand Down Expand Up @@ -47,9 +45,9 @@ public function __construct(
Client $client = null
) {
$this->loop = null === $loop?ReactFactory::buildEventLoop():$loop;
if( null === $client ) {
if (null === $client) {
$this->client = ReactFactory::buildHttpClient($this->loop);
} elseif( null === $loop ) {
} elseif (null === $loop) {
throw new \RuntimeException(
"You must give a LoopInterface instance with the Client"
);
Expand Down Expand Up @@ -81,30 +79,30 @@ public function sendAsyncRequest(RequestInterface $request)
$requestStream = $this->buildReactRequest($request);
$deferred = new Deferred();

$requestStream->on('error', function(\Exception $error) use ($deferred, $request) {
$requestStream->on('error', function (\Exception $error) use ($deferred, $request) {
$deferred->reject(new RequestException(
$error->getMessage(),
$request,
$error
));
});
$requestStream->on('response', function(ReactResponse $response = null) use ($deferred, $requestStream, $request) {
$requestStream->on('response', function (ReactResponse $response = null) use ($deferred, $requestStream, $request) {
$bodyStream = null;
$response->on('data', function($data) use (&$bodyStream) {
if( $data instanceof StreamInterface ) {
$response->on('data', function ($data) use (&$bodyStream) {
if ($data instanceof StreamInterface) {
$bodyStream = $data;
} else {
$bodyStream->write($data);
}
});

$response->on('end', function(\Exception $error = null) use ($deferred, $request, $response, &$bodyStream) {
$response->on('end', function (\Exception $error = null) use ($deferred, $request, $response, &$bodyStream) {
$bodyStream->rewind();
$psr7Response = $this->messageFactory->buildResponse(
$response,
$bodyStream
);
if( null !== $error ) {
if (null !== $error) {
$deferred->reject(new HttpException(
$error->getMessage(),
$request,
Expand Down Expand Up @@ -132,10 +130,10 @@ public function sendAsyncRequest(RequestInterface $request)
private function buildReactRequest(RequestInterface $request)
{
$headers = [];
foreach( $request->getHeaders() as $name => $value ) {
foreach ($request->getHeaders() as $name => $value) {
$headers[$name] = (is_array($value)?$value[0]:$value);
}
if( $request->getBody()->getSize() > 0 ) {
if ($request->getBody()->getSize() > 0) {
$headers['Content-Length'] = $request->getBody()->getSize();
}

Expand Down
16 changes: 8 additions & 8 deletions src/ReactPromiseAdapter.php
Expand Up @@ -51,11 +51,11 @@ class ReactPromiseAdapter implements Promise
public function __construct(ReactPromise $promise)
{
$promise->then(
function(ResponseInterface $response) {
function (ResponseInterface $response) {
$this->state = Promise::FULFILLED;
$this->response = $response;
},
function(Exception $error) {
function (Exception $error) {
$this->state = Promise::REJECTED;
$this->exception = $error;
}
Expand All @@ -71,12 +71,12 @@ function(Exception $error) {
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
$this->promise->then(function() use ($onFulfilled) {
if( null !== $onFulfilled ) {
$this->promise->then(function () use ($onFulfilled) {
if (null !== $onFulfilled) {
call_user_func($onFulfilled, $this->response);
}
}, function() use ($onRejected) {
if( null !== $onRejected ) {
}, function () use ($onRejected) {
if (null !== $onRejected) {
call_user_func($onRejected, $this->exception);
}
});
Expand Down Expand Up @@ -123,10 +123,10 @@ public function setLoop(LoopInterface $loop)
*/
public function wait()
{
if( null === $this->loop ) {
if (null === $this->loop) {
throw new \LogicException("You must set the loop before wait!");
}
while( Promise::PENDING === $this->getState() ) {
while (Promise::PENDING === $this->getState()) {
$this->loop->tick();
}
}
Expand Down

0 comments on commit cde88a4

Please sign in to comment.