@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function send(RequestInterface $request) |
70 | 70 | { |
71 | 71 | $state = new ClientRequestState(); |
72 | - $deferred = new Deferred(function () use ($state) { |
|
72 | + $deferred = new Deferred(function() use ($state) { |
|
73 | 73 | if ($state->pending !== null) { |
74 | 74 | $state->pending->cancel(); |
75 | 75 | $state->pending = null; |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | }); |
78 | 78 | |
79 | 79 | // use timeout from options or default to PHP's default_socket_timeout (60) |
80 | - $timeout = (float)($this->timeout !== null ? $this->timeout : ini_get("default_socket_timeout")); |
|
80 | + $timeout = (float) ($this->timeout !== null ? $this->timeout : ini_get("default_socket_timeout")); |
|
81 | 81 | |
82 | 82 | $loop = $this->loop; |
83 | 83 | $this->next($request, $deferred, $state)->then( |
84 | - function (ResponseInterface $response) use ($state, $deferred, $loop, &$timeout) { |
|
84 | + function(ResponseInterface $response) use ($state, $deferred, $loop, &$timeout) { |
|
85 | 85 | if ($state->timeout !== null) { |
86 | 86 | $loop->cancelTimer($state->timeout); |
87 | 87 | $state->timeout = null; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $timeout = -1; |
90 | 90 | $deferred->resolve($response); |
91 | 91 | }, |
92 | - function ($e) use ($state, $deferred, $loop, &$timeout) { |
|
92 | + function($e) use ($state, $deferred, $loop, &$timeout) { |
|
93 | 93 | if ($state->timeout !== null) { |
94 | 94 | $loop->cancelTimer($state->timeout); |
95 | 95 | $state->timeout = null; |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $body = $request->getBody(); |
107 | 107 | if ($body instanceof ReadableStreamInterface && $body->isReadable()) { |
108 | 108 | $that = $this; |
109 | - $body->on('close', function () use ($that, $deferred, $state, &$timeout) { |
|
109 | + $body->on('close', function() use ($that, $deferred, $state, &$timeout) { |
|
110 | 110 | if ($timeout >= 0) { |
111 | 111 | $that->applyTimeout($deferred, $state, $timeout); |
112 | 112 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function applyTimeout(Deferred $deferred, ClientRequestState $state, $timeout) |
127 | 127 | { |
128 | - $state->timeout = $this->loop->addTimer($timeout, function () use ($timeout, $deferred, $state) { |
|
128 | + $state->timeout = $this->loop->addTimer($timeout, function() use ($timeout, $deferred, $state) { |
|
129 | 129 | $deferred->reject(new \RuntimeException( |
130 | 130 | 'Request timed out after ' . $timeout . ' seconds' |
131 | 131 | )); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $promise = $this->sender->send($request); |
147 | 147 | |
148 | 148 | if (!$this->streaming) { |
149 | - $promise = $promise->then(function ($response) use ($deferred, $state, $that) { |
|
149 | + $promise = $promise->then(function($response) use ($deferred, $state, $that) { |
|
150 | 150 | return $that->bufferResponse($response, $deferred, $state); |
151 | 151 | }); |
152 | 152 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $state->pending = $promise; |
155 | 155 | |
156 | 156 | return $promise->then( |
157 | - function (ResponseInterface $response) use ($request, $that, $deferred, $state) { |
|
157 | + function(ResponseInterface $response) use ($request, $that, $deferred, $state) { |
|
158 | 158 | return $that->onResponse($response, $request, $deferred, $state); |
159 | 159 | } |
160 | 160 | ); |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | $closer = null; |
187 | 187 | $maximumSize = $this->maximumSize; |
188 | 188 | |
189 | - return $state->pending = new Promise(function ($resolve, $reject) use ($body, $maximumSize, $response, &$closer) { |
|
189 | + return $state->pending = new Promise(function($resolve, $reject) use ($body, $maximumSize, $response, &$closer) { |
|
190 | 190 | // resolve with current buffer when stream closes successfully |
191 | 191 | $buffer = ''; |
192 | - $body->on('close', $closer = function () use (&$buffer, $response, $maximumSize, $resolve, $reject) { |
|
192 | + $body->on('close', $closer = function() use (&$buffer, $response, $maximumSize, $resolve, $reject) { |
|
193 | 193 | $resolve($response->withBody(new BufferedBody($buffer))); |
194 | 194 | }); |
195 | 195 | |
196 | 196 | // buffer response body data in memory |
197 | - $body->on('data', function ($data) use (&$buffer, $maximumSize, $body, $closer, $reject) { |
|
197 | + $body->on('data', function($data) use (&$buffer, $maximumSize, $body, $closer, $reject) { |
|
198 | 198 | $buffer .= $data; |
199 | 199 | |
200 | 200 | // close stream and reject promise if limit is exceeded |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | }); |
213 | 213 | |
214 | 214 | // reject buffering if body emits error |
215 | - $body->on('error', function (\Exception $e) use ($reject) { |
|
215 | + $body->on('error', function(\Exception $e) use ($reject) { |
|
216 | 216 | $reject(new \RuntimeException( |
217 | 217 | 'Error while buffering response body: ' . $e->getMessage(), |
218 | 218 | $e->getCode(), |
219 | 219 | $e |
220 | 220 | )); |
221 | 221 | }); |
222 | - }, function () use ($body, &$closer) { |
|
222 | + }, function() use ($body, &$closer) { |
|
223 | 223 | // cancelled buffering: remove close handler to avoid resolving, then close and reject |
224 | 224 | assert($closer instanceof \Closure); |
225 | 225 | $body->removeListener('close', $closer); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $this->parser = new RequestHeaderParser($this->clock); |
111 | 111 | |
112 | 112 | $that = $this; |
113 | - $this->parser->on('headers', function (ServerRequestInterface $request, ConnectionInterface $conn) use ($that) { |
|
113 | + $this->parser->on('headers', function(ServerRequestInterface $request, ConnectionInterface $conn) use ($that) { |
|
114 | 114 | $that->handleRequest($conn, $request); |
115 | 115 | }); |
116 | 116 | |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | // cancel pending promise once connection closes |
160 | - $connectionOnCloseResponseCancelerHandler = function () {}; |
|
160 | + $connectionOnCloseResponseCancelerHandler = function() {}; |
|
161 | 161 | if ($response instanceof PromiseInterface && \method_exists($response, 'cancel')) { |
162 | - $connectionOnCloseResponseCanceler = function () use ($response) { |
|
162 | + $connectionOnCloseResponseCanceler = function() use ($response) { |
|
163 | 163 | $response->cancel(); |
164 | 164 | }; |
165 | - $connectionOnCloseResponseCancelerHandler = function () use ($connectionOnCloseResponseCanceler, $conn) { |
|
165 | + $connectionOnCloseResponseCancelerHandler = function() use ($connectionOnCloseResponseCanceler, $conn) { |
|
166 | 166 | if ($connectionOnCloseResponseCanceler !== null) { |
167 | 167 | $conn->removeListener('close', $connectionOnCloseResponseCanceler); |
168 | 168 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | $that = $this; |
184 | 184 | $response->then( |
185 | - function ($response) use ($that, $conn, $request) { |
|
185 | + function($response) use ($that, $conn, $request) { |
|
186 | 186 | if (!$response instanceof ResponseInterface) { |
187 | 187 | $message = 'The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but resolved with "%s" instead.'; |
188 | 188 | $message = \sprintf($message, \is_object($response) ? \get_class($response) : \gettype($response)); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | } |
194 | 194 | $that->handleResponse($conn, $request, $response); |
195 | 195 | }, |
196 | - function ($error) use ($that, $conn, $request) { |
|
196 | + function($error) use ($that, $conn, $request) { |
|
197 | 197 | $message = 'The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but rejected with "%s" instead.'; |
198 | 198 | $message = \sprintf($message, \is_object($error) ? \get_class($error) : \gettype($error)); |
199 | 199 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | // assign default "Server" header automatically |
256 | 256 | if (!$response->hasHeader('Server')) { |
257 | 257 | $response = $response->withHeader('Server', 'ReactPHP/1'); |
258 | - } elseif ($response->getHeaderLine('Server') === ''){ |
|
258 | + } elseif ($response->getHeaderLine('Server') === '') { |
|
259 | 259 | $response = $response->withoutHeader('Server'); |
260 | 260 | } |
261 | 261 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | if (!$response->hasHeader('Date')) { |
264 | 264 | // IMF-fixdate = day-name "," SP date1 SP time-of-day SP GMT |
265 | 265 | $response = $response->withHeader('Date', gmdate('D, d M Y H:i:s', (int) $this->clock->now()) . ' GMT'); |
266 | - } elseif ($response->getHeaderLine('Date') === ''){ |
|
266 | + } elseif ($response->getHeaderLine('Date') === '') { |
|
267 | 267 | $response = $response->withoutHeader('Date'); |
268 | 268 | } |
269 | 269 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | // 304 Not Modified: preserve explicit Content-Length and preserve missing header if body is empty |
279 | 279 | } elseif ($body->getSize() !== null) { |
280 | 280 | // assign Content-Length header when using a "normal" buffered body string |
281 | - $response = $response->withHeader('Content-Length', (string)$body->getSize()); |
|
281 | + $response = $response->withHeader('Content-Length', (string) $body->getSize()); |
|
282 | 282 | } elseif (!$response->hasHeader('Content-Length') && $version === '1.1') { |
283 | 283 | // assign chunked transfer-encoding if no 'content-length' is given for HTTP/1.1 responses |
284 | 284 | $chunked = true; |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | if (($code === Response::STATUS_SWITCHING_PROTOCOLS || ($method === 'CONNECT' && $code >= 200 && $code < 300)) && $body instanceof HttpBodyStream && $body->input instanceof WritableStreamInterface) { |
320 | 320 | if ($request->getBody()->isReadable()) { |
321 | 321 | // request is still streaming => wait for request close before forwarding following data from connection |
322 | - $request->getBody()->on('close', function () use ($connection, $body) { |
|
322 | + $request->getBody()->on('close', function() use ($connection, $body) { |
|
323 | 323 | if ($body->input->isWritable()) { |
324 | 324 | $connection->pipe($body->input); |
325 | 325 | $connection->resume(); |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | if ($persist) { |
395 | 395 | $body->pipe($connection, array('end' => false)); |
396 | 396 | $parser = $this->parser; |
397 | - $body->on('end', function () use ($connection, $parser, $body) { |
|
397 | + $body->on('end', function() use ($connection, $parser, $body) { |
|
398 | 398 | $connection->removeListener('close', array($body, 'close')); |
399 | 399 | $parser->handle($connection); |
400 | 400 | }); |
@@ -74,7 +74,7 @@ |
||
74 | 74 | { |
75 | 75 | if (($this->transferredLength + \strlen($data)) > $this->maxLength) { |
76 | 76 | // Only emit data until the value of 'Content-Length' is reached, the rest will be ignored |
77 | - $data = (string)\substr($data, 0, $this->maxLength - $this->transferredLength); |
|
77 | + $data = (string) \substr($data, 0, $this->maxLength - $this->transferredLength); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | if ($data !== '') { |
@@ -251,14 +251,14 @@ |
||
251 | 251 | * Filter out any configuration middleware, no need to run requests through something that isn't |
252 | 252 | * doing anything with the request. |
253 | 253 | */ |
254 | - $middleware = \array_filter($middleware, function ($handler) { |
|
254 | + $middleware = \array_filter($middleware, function($handler) { |
|
255 | 255 | return !($handler instanceof StreamingRequestMiddleware); |
256 | 256 | }); |
257 | 257 | |
258 | 258 | $this->streamingServer = new StreamingServer($loop, new MiddlewareRunner($middleware)); |
259 | 259 | |
260 | 260 | $that = $this; |
261 | - $this->streamingServer->on('error', function ($error) use ($that) { |
|
261 | + $this->streamingServer->on('error', function($error) use ($that) { |
|
262 | 262 | $that->emit('error', array($error)); |
263 | 263 | }); |
264 | 264 | } |
@@ -235,7 +235,7 @@ |
||
235 | 235 | */ |
236 | 236 | public function patch($url, array $headers = array(), $body = '') |
237 | 237 | { |
238 | - return $this->requestMayBeStreaming('PATCH', $url , $headers, $body); |
|
238 | + return $this->requestMayBeStreaming('PATCH', $url, $headers, $body); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | private function createTimerCallback() |
241 | 241 | { |
242 | 242 | $timers = $this->timerEvents; |
243 | - $this->timerCallback = function ($_, $__, $timer) use ($timers) { |
|
243 | + $this->timerCallback = function($_, $__, $timer) use ($timers) { |
|
244 | 244 | \call_user_func($timer->getCallback(), $timer); |
245 | 245 | |
246 | 246 | if (!$timer->isPeriodic() && $timers->contains($timer)) { |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | */ |
259 | 259 | private function createStreamCallback() |
260 | 260 | { |
261 | - $read =& $this->readListeners; |
|
262 | - $write =& $this->writeListeners; |
|
263 | - $this->streamCallback = function ($stream, $flags) use (&$read, &$write) { |
|
261 | + $read = & $this->readListeners; |
|
262 | + $write = & $this->writeListeners; |
|
263 | + $this->streamCallback = function($stream, $flags) use (&$read, &$write) { |
|
264 | 264 | $key = (int) $stream; |
265 | 265 | |
266 | 266 | if (Event::READ === (Event::READ & $flags) && isset($read[$key])) { |
@@ -39,12 +39,12 @@ |
||
39 | 39 | // This is tested using child processes, so coverage is actually 100%, see BinTest. |
40 | 40 | // @codeCoverageIgnoreStart |
41 | 41 | $hasRun = false; |
42 | - $loop->futureTick(function () use (&$hasRun) { |
|
42 | + $loop->futureTick(function() use (&$hasRun) { |
|
43 | 43 | $hasRun = true; |
44 | 44 | }); |
45 | 45 | |
46 | - $stopped =& self::$stopped; |
|
47 | - register_shutdown_function(function () use ($loop, &$hasRun, &$stopped) { |
|
46 | + $stopped = & self::$stopped; |
|
47 | + register_shutdown_function(function() use ($loop, &$hasRun, &$stopped) { |
|
48 | 48 | // Don't run if we're coming from a fatal error (uncaught exception). |
49 | 49 | $error = error_get_last(); |
50 | 50 | if ((isset($error['type']) ? $error['type'] : 0) & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR)) { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $that = $this; |
118 | 118 | $timers = $this->timers; |
119 | - $callback = function () use ($timer, $timers, $that) { |
|
119 | + $callback = function() use ($timer, $timers, $that) { |
|
120 | 120 | \call_user_func($timer->getCallback(), $timer); |
121 | 121 | |
122 | 122 | if ($timers->contains($timer)) { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | { |
144 | 144 | $timer = new Timer($interval, $callback, true); |
145 | 145 | |
146 | - $callback = function () use ($timer) { |
|
146 | + $callback = function() use ($timer) { |
|
147 | 147 | \call_user_func($timer->getCallback(), $timer); |
148 | 148 | }; |
149 | 149 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | if (!isset($this->signalEvents[$signal])) { |
187 | 187 | $signals = $this->signals; |
188 | 188 | $this->signalEvents[$signal] = \uv_signal_init($this->uv); |
189 | - \uv_signal_start($this->signalEvents[$signal], function () use ($signals, $signal) { |
|
189 | + \uv_signal_start($this->signalEvents[$signal], function() use ($signals, $signal) { |
|
190 | 190 | $signals->call($signal); |
191 | 191 | }, $signal); |
192 | 192 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | private function addStream($stream) |
245 | 245 | { |
246 | 246 | if (!isset($this->streamEvents[(int) $stream])) { |
247 | - $this->streamEvents[(int)$stream] = \uv_poll_init_socket($this->uv, $stream); |
|
247 | + $this->streamEvents[(int) $stream] = \uv_poll_init_socket($this->uv, $stream); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | if ($this->streamEvents[(int) $stream] !== false) { |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | */ |
295 | 295 | private function createStreamListener() |
296 | 296 | { |
297 | - $callback = function ($event, $status, $events, $stream) { |
|
297 | + $callback = function($event, $status, $events, $stream) { |
|
298 | 298 | // libuv automatically stops polling on error, re-enable polling to match other loop implementations |
299 | 299 | if ($status !== 0) { |
300 | 300 | $this->pollStream($stream); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | public function addReadStream($stream, $listener) |
75 | 75 | { |
76 | - $key = (int)$stream; |
|
76 | + $key = (int) $stream; |
|
77 | 77 | |
78 | 78 | if (isset($this->readStreams[$key])) { |
79 | 79 | return; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | */ |
93 | 93 | private function getStreamListenerClosure($stream, $listener) |
94 | 94 | { |
95 | - return function () use ($stream, $listener) { |
|
95 | + return function() use ($stream, $listener) { |
|
96 | 96 | \call_user_func($listener, $stream); |
97 | 97 | }; |
98 | 98 | } |
99 | 99 | |
100 | 100 | public function addWriteStream($stream, $listener) |
101 | 101 | { |
102 | - $key = (int)$stream; |
|
102 | + $key = (int) $stream; |
|
103 | 103 | |
104 | 104 | if (isset($this->writeStreams[$key])) { |
105 | 105 | return; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | public function removeReadStream($stream) |
114 | 114 | { |
115 | - $key = (int)$stream; |
|
115 | + $key = (int) $stream; |
|
116 | 116 | |
117 | 117 | if (!isset($this->readStreams[$key])) { |
118 | 118 | return; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | public function removeWriteStream($stream) |
126 | 126 | { |
127 | - $key = (int)$stream; |
|
127 | + $key = (int) $stream; |
|
128 | 128 | |
129 | 129 | if (!isset($this->writeStreams[$key])) { |
130 | 130 | return; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | $that = $this; |
142 | 142 | $timers = $this->timers; |
143 | - $callback = function () use ($timer, $timers, $that) { |
|
143 | + $callback = function() use ($timer, $timers, $that) { |
|
144 | 144 | \call_user_func($timer->getCallback(), $timer); |
145 | 145 | |
146 | 146 | if ($timers->contains($timer)) { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | { |
159 | 159 | $timer = new Timer($interval, $callback, true); |
160 | 160 | |
161 | - $callback = function () use ($timer) { |
|
161 | + $callback = function() use ($timer) { |
|
162 | 162 | \call_user_func($timer->getCallback(), $timer); |
163 | 163 | }; |
164 | 164 |