Skip to content

Commit f0e536c

Browse files
committed
[http client] code style
1 parent b345e90 commit f0e536c

5 files changed

Lines changed: 24 additions & 27 deletions

File tree

Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace React\Http;
44

5+
use Guzzle\Http\Message\Request as GuzzleRequest;
56
use React\EventLoop\LoopInterface;
67
use React\Http\Client\ConnectionManager;
7-
use React\Http\Client\SecureConnectionManager;
8-
use Guzzle\Http\Message\Request as GuzzleRequest;
98
use React\Http\Client\Request as ClientRequest;
9+
use React\Http\Client\SecureConnectionManager;
1010

1111
class Client
1212
{

Client/ConnectionManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getConnection($callback, $host, $port)
3535
$loop = $this->loop;
3636
$that = $this;
3737

38-
$this->loop->addWriteStream($socket, function() use ($that, $callback, $socket, $loop) {
38+
$this->loop->addWriteStream($socket, function () use ($that, $callback, $socket, $loop) {
3939

4040
$loop->removeWriteStream($socket);
4141

Client/Request.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
namespace React\Http\Client;
44

55
use Evenement\EventEmitter;
6-
use Guzzle\Http\Url;
7-
use React\Stream\Stream;
86
use Guzzle\Http\Message\Request as GuzzleRequest;
9-
use React\Http\Client\Response;
10-
use React\EventLoop\LoopInterface;
7+
use Guzzle\Http\Url;
118
use Guzzle\Parser\Message\MessageParser;
9+
use React\EventLoop\LoopInterface;
1210
use React\Http\Client\ConnectionManagerInterface;
11+
use React\Http\Client\Response;
1312
use React\Http\Client\ResponseHeaderParser;
13+
use React\Stream\Stream;
1414
use React\Stream\WritableStreamInterface;
1515

1616
class Request extends EventEmitter implements WritableStreamInterface
1717
{
18-
1918
const STATE_INIT = 0;
2019
const STATE_WRITING_HEAD = 1;
2120
const STATE_HEAD_WRITTEN = 2;
@@ -45,7 +44,7 @@ public function isWritable()
4544
public function writeHead()
4645
{
4746
if (self::STATE_WRITING_HEAD <= $this->state) {
48-
throw new \LogicException('headers already written');
47+
throw new \LogicException('Headers already written');
4948
}
5049

5150
$this->state = self::STATE_WRITING_HEAD;
@@ -55,10 +54,10 @@ public function writeHead()
5554
$streamRef = &$this->stream;
5655
$stateRef = &$this->state;
5756

58-
$this->connect(function($stream, \Exception $error = null) use ($that, $request, &$streamRef, &$stateRef) {
57+
$this->connect(function ($stream, \Exception $error = null) use ($that, $request, &$streamRef, &$stateRef) {
5958
if (!$stream) {
6059
$that->closeError(new \RuntimeException(
61-
"connection failed",
60+
"Connection failed",
6261
0,
6362
$error
6463
));
@@ -93,7 +92,7 @@ public function write($data)
9392
return $this->stream->write($data);
9493
}
9594

96-
$this->on('headers-written', function($that) use ($data) {
95+
$this->on('headers-written', function ($that) use ($data) {
9796
$that->write($data);
9897
});
9998

@@ -127,8 +126,7 @@ public function handleData($data)
127126
$this->buffer .= $data;
128127

129128
if (false !== strpos($this->buffer, "\r\n\r\n")) {
130-
131-
list($response, $body) = $this->parseResponse($this->buffer);
129+
list($response, $bodyChunk) = $this->parseResponse($this->buffer);
132130

133131
$this->stream->removeListener('drain', array($this, 'handleDrain'));
134132
$this->stream->removeListener('data', array($this, 'handleData'));
@@ -138,34 +136,34 @@ public function handleData($data)
138136
$this->response = $response;
139137
$that = $this;
140138

141-
$response->on('end', function() use ($that) {
139+
$response->on('end', function () use ($that) {
142140
$that->close();
143141
});
144-
$response->on('error', function(\Exception $error) use ($that) {
142+
$response->on('error', function (\Exception $error) use ($that) {
145143
$that->closeError(new \RuntimeException(
146-
"response error",
144+
"An error occured in the response",
147145
0,
148146
$error
149147
));
150148
});
151149

152150
$this->emit('response', array($response, $this));
153151

154-
$response->emit('data', array($body));
152+
$response->emit('data', array($bodyChunk));
155153
}
156154
}
157155

158156
public function handleEnd()
159157
{
160158
$this->closeError(new \RuntimeException(
161-
"connection closed before receiving response"
159+
"Connection closed before receiving response"
162160
));
163161
}
164162

165163
public function handleError($error)
166164
{
167165
$this->closeError(new \RuntimeException(
168-
"stream error",
166+
"An error occurred in the underlying stream",
169167
0,
170168
$error
171169
));
@@ -220,7 +218,7 @@ protected function connect($callback)
220218
$connectionManager = $this->connectionManager;
221219
$that = $this;
222220

223-
$connectionManager->getConnection(function($stream) use ($that, $callback) {
221+
$connectionManager->getConnection(function ($stream) use ($that, $callback) {
224222
call_user_func($callback, $stream);
225223
}, $host, $port);
226224
}
@@ -233,7 +231,6 @@ public function setResponseFactory($factory)
233231
public function getResponseFactory()
234232
{
235233
if (null === $factory = $this->responseFactory) {
236-
237234
$loop = $this->loop;
238235
$stream = $this->stream;
239236

Client/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Evenement\EventEmitter;
66
use React\EventLoop\LoopInterface;
7-
use React\Stream\Stream;
87
use React\Stream\ReadableStreamInterface;
8+
use React\Stream\Stream;
99
use React\Stream\Util;
1010
use React\Stream\WritableStreamInterface;
1111

@@ -79,7 +79,7 @@ public function handleEnd()
7979
public function handleError(\Exception $error)
8080
{
8181
$this->emit('error', array(new \RuntimeException(
82-
"an error occurred in the underlying stream",
82+
"An error occurred in the underlying stream",
8383
0,
8484
$error
8585
), $this));

Client/SecureConnectionManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public function handleConnectedSocket($callback, $socket)
1111
{
1212
$loop = $this->loop;
1313

14-
$enableCrypto = function() use ($callback, $socket, $loop) {
14+
$enableCrypto = function () use ($callback, $socket, $loop) {
1515

1616
$result = stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
1717

18-
// crypto was successfully enabled
1918
if (true === $result) {
19+
// crypto was successfully enabled
2020
$loop->removeWriteStream($socket);
2121
$loop->removeReadStream($socket);
2222
call_user_func($callback, new Stream($socket, $loop));
2323

24-
// an error occured
2524
} else if (false === $result) {
25+
// an error occured
2626
$loop->removeWriteStream($socket);
2727
$loop->removeReadStream($socket);
2828
call_user_func($callback, null);

0 commit comments

Comments
 (0)