@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | return new static( |
47 | 47 | $this->resolver($onFulfilled, $onRejected, $onProgress), |
48 | - static function () use (&$parent) { |
|
48 | + static function() use (&$parent) { |
|
49 | 49 | if (++$parent->cancelRequests >= $parent->requiredCancelRequests) { |
50 | 50 | $parent->cancel(); |
51 | 51 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return $this->result->done($onFulfilled, $onRejected, $onProgress); |
62 | 62 | } |
63 | 63 | |
64 | - $this->handlers[] = static function (ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected) { |
|
64 | + $this->handlers[] = static function(ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected) { |
|
65 | 65 | $promise |
66 | 66 | ->done($onFulfilled, $onRejected); |
67 | 67 | }; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | public function otherwise(callable $onRejected) |
75 | 75 | { |
76 | - return $this->then(null, static function ($reason) use ($onRejected) { |
|
76 | + return $this->then(null, static function($reason) use ($onRejected) { |
|
77 | 77 | if (!_checkTypehint($onRejected, $reason)) { |
78 | 78 | return new RejectedPromise($reason); |
79 | 79 | } |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | |
85 | 85 | public function always(callable $onFulfilledOrRejected) |
86 | 86 | { |
87 | - return $this->then(static function ($value) use ($onFulfilledOrRejected) { |
|
88 | - return resolve($onFulfilledOrRejected())->then(function () use ($value) { |
|
87 | + return $this->then(static function($value) use ($onFulfilledOrRejected) { |
|
88 | + return resolve($onFulfilledOrRejected())->then(function() use ($value) { |
|
89 | 89 | return $value; |
90 | 90 | }); |
91 | - }, static function ($reason) use ($onFulfilledOrRejected) { |
|
92 | - return resolve($onFulfilledOrRejected())->then(function () use ($reason) { |
|
91 | + }, static function($reason) use ($onFulfilledOrRejected) { |
|
92 | + return resolve($onFulfilledOrRejected())->then(function() use ($reason) { |
|
93 | 93 | return new RejectedPromise($reason); |
94 | 94 | }); |
95 | 95 | }); |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | |
115 | 115 | private function resolver(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null) |
116 | 116 | { |
117 | - return function ($resolve, $reject, $notify) use ($onFulfilled, $onRejected, $onProgress) { |
|
117 | + return function($resolve, $reject, $notify) use ($onFulfilled, $onRejected, $onProgress) { |
|
118 | 118 | if ($onProgress) { |
119 | - $progressHandler = static function ($update) use ($notify, $onProgress) { |
|
119 | + $progressHandler = static function($update) use ($notify, $onProgress) { |
|
120 | 120 | try { |
121 | 121 | $notify($onProgress($update)); |
122 | 122 | } catch (\Throwable $e) { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $progressHandler = $notify; |
130 | 130 | } |
131 | 131 | |
132 | - $this->handlers[] = static function (ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected, $resolve, $reject, $progressHandler) { |
|
132 | + $this->handlers[] = static function(ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected, $resolve, $reject, $progressHandler) { |
|
133 | 133 | $promise |
134 | 134 | ->then($onFulfilled, $onRejected) |
135 | 135 | ->done($resolve, $reject, $progressHandler); |
@@ -222,23 +222,23 @@ discard block |
||
222 | 222 | // garbage cycles if any callback creates an Exception. |
223 | 223 | // These assumptions are covered by the test suite, so if you ever feel like |
224 | 224 | // refactoring this, go ahead, any alternative suggestions are welcome! |
225 | - $target =& $this; |
|
226 | - $progressHandlers =& $this->progressHandlers; |
|
225 | + $target = & $this; |
|
226 | + $progressHandlers = & $this->progressHandlers; |
|
227 | 227 | |
228 | 228 | $callback( |
229 | - static function ($value = null) use (&$target) { |
|
229 | + static function($value = null) use (&$target) { |
|
230 | 230 | if ($target !== null) { |
231 | 231 | $target->settle(resolve($value)); |
232 | 232 | $target = null; |
233 | 233 | } |
234 | 234 | }, |
235 | - static function ($reason = null) use (&$target) { |
|
235 | + static function($reason = null) use (&$target) { |
|
236 | 236 | if ($target !== null) { |
237 | 237 | $target->reject($reason); |
238 | 238 | $target = null; |
239 | 239 | } |
240 | 240 | }, |
241 | - static function ($update = null) use (&$progressHandlers) { |
|
241 | + static function($update = null) use (&$progressHandlers) { |
|
242 | 242 | foreach ($progressHandlers as $handler) { |
243 | 243 | $handler($update); |
244 | 244 | } |
@@ -61,8 +61,8 @@ |
||
61 | 61 | |
62 | 62 | public function always(callable $onFulfilledOrRejected) |
63 | 63 | { |
64 | - return $this->then(null, function ($reason) use ($onFulfilledOrRejected) { |
|
65 | - return resolve($onFulfilledOrRejected())->then(function () use ($reason) { |
|
64 | + return $this->then(null, function($reason) use ($onFulfilledOrRejected) { |
|
65 | + return resolve($onFulfilledOrRejected())->then(function() use ($reason) { |
|
66 | 66 | return new RejectedPromise($reason); |
67 | 67 | }); |
68 | 68 | }); |
@@ -53,8 +53,8 @@ |
||
53 | 53 | |
54 | 54 | public function always(callable $onFulfilledOrRejected) |
55 | 55 | { |
56 | - return $this->then(function ($value) use ($onFulfilledOrRejected) { |
|
57 | - return resolve($onFulfilledOrRejected())->then(function () use ($value) { |
|
56 | + return $this->then(function($value) use ($onFulfilledOrRejected) { |
|
57 | + return resolve($onFulfilledOrRejected())->then(function() use ($value) { |
|
58 | 58 | return $value; |
59 | 59 | }); |
60 | 60 | }); |
@@ -18,7 +18,7 @@ |
||
18 | 18 | public function promise() |
19 | 19 | { |
20 | 20 | if (null === $this->promise) { |
21 | - $this->promise = new Promise(function ($resolve, $reject, $notify) { |
|
21 | + $this->promise = new Promise(function($resolve, $reject, $notify) { |
|
22 | 22 | $this->resolveCallback = $resolve; |
23 | 23 | $this->rejectCallback = $reject; |
24 | 24 | $this->notifyCallback = $notify; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $error = \error_get_last(); |
79 | 79 | if (\preg_match('/\(([^\)]+)\)|\[(\d+)\]: (.*)/', $error['message'], $match)) { |
80 | 80 | $errstr = isset($match[3]) ? $match['3'] : $match[1]; |
81 | - $errno = isset($match[2]) ? (int)$match[2] : 0; |
|
81 | + $errno = isset($match[2]) ? (int) $match[2] : 0; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | $that = $this; |
121 | - $this->loop->addReadStream($this->master, function ($master) use ($that) { |
|
121 | + $this->loop->addReadStream($this->master, function($master) use ($that) { |
|
122 | 122 | try { |
123 | 123 | $newSocket = SocketServer::accept($master); |
124 | 124 | } catch (\RuntimeException $e) { |
@@ -68,10 +68,10 @@ |
||
68 | 68 | $this->server = $server; |
69 | 69 | |
70 | 70 | $that = $this; |
71 | - $server->on('connection', function (ConnectionInterface $conn) use ($that) { |
|
71 | + $server->on('connection', function(ConnectionInterface $conn) use ($that) { |
|
72 | 72 | $that->emit('connection', array($conn)); |
73 | 73 | }); |
74 | - $server->on('error', function (\Exception $error) use ($that) { |
|
74 | + $server->on('error', function(\Exception $error) use ($that) { |
|
75 | 75 | $that->emit('error', array($error)); |
76 | 76 | }); |
77 | 77 | } |
@@ -178,7 +178,7 @@ |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | $that = $this; |
181 | - $this->loop->addReadStream($this->master, function ($master) use ($that) { |
|
181 | + $this->loop->addReadStream($this->master, function($master) use ($that) { |
|
182 | 182 | try { |
183 | 183 | $newSocket = SocketServer::accept($master); |
184 | 184 | } catch (\RuntimeException $e) { |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | |
99 | 99 | // wait for connection |
100 | 100 | $loop = $this->loop; |
101 | - return new Promise\Promise(function ($resolve, $reject) use ($loop, $stream, $uri) { |
|
102 | - $loop->addWriteStream($stream, function ($stream) use ($loop, $resolve, $reject, $uri) { |
|
101 | + return new Promise\Promise(function($resolve, $reject) use ($loop, $stream, $uri) { |
|
102 | + $loop->addWriteStream($stream, function($stream) use ($loop, $resolve, $reject, $uri) { |
|
103 | 103 | $loop->removeWriteStream($stream); |
104 | 104 | |
105 | 105 | // The following hack looks like the only way to |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $resolve(new Connection($stream, $loop)); |
140 | 140 | } |
141 | 141 | }); |
142 | - }, function () use ($loop, $stream, $uri) { |
|
142 | + }, function() use ($loop, $stream, $uri) { |
|
143 | 143 | $loop->removeWriteStream($stream); |
144 | 144 | \fclose($stream); |
145 | 145 |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | { |
68 | 68 | $timer = null; |
69 | 69 | $that = $this; |
70 | - return new Promise\Promise(function ($resolve, $reject) use ($that, &$timer) { |
|
71 | - $lookupResolve = function ($type) use ($that, $resolve, $reject) { |
|
72 | - return function (array $ips) use ($that, $type, $resolve, $reject) { |
|
70 | + return new Promise\Promise(function($resolve, $reject) use ($that, &$timer) { |
|
71 | + $lookupResolve = function($type) use ($that, $resolve, $reject) { |
|
72 | + return function(array $ips) use ($that, $type, $resolve, $reject) { |
|
73 | 73 | unset($that->resolverPromises[$type]); |
74 | 74 | $that->resolved[$type] = true; |
75 | 75 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | }; |
84 | 84 | |
85 | 85 | $that->resolverPromises[Message::TYPE_AAAA] = $that->resolve(Message::TYPE_AAAA, $reject)->then($lookupResolve(Message::TYPE_AAAA)); |
86 | - $that->resolverPromises[Message::TYPE_A] = $that->resolve(Message::TYPE_A, $reject)->then(function (array $ips) use ($that, &$timer) { |
|
86 | + $that->resolverPromises[Message::TYPE_A] = $that->resolve(Message::TYPE_A, $reject)->then(function(array $ips) use ($that, &$timer) { |
|
87 | 87 | // happy path: IPv6 has resolved already (or could not resolve), continue with IPv4 addresses |
88 | 88 | if ($that->resolved[Message::TYPE_AAAA] === true || !$ips) { |
89 | 89 | return $ips; |
@@ -91,18 +91,18 @@ discard block |
||
91 | 91 | |
92 | 92 | // Otherwise delay processing IPv4 lookup until short timer passes or IPv6 resolves in the meantime |
93 | 93 | $deferred = new Promise\Deferred(); |
94 | - $timer = $that->loop->addTimer($that::RESOLUTION_DELAY, function () use ($deferred, $ips) { |
|
94 | + $timer = $that->loop->addTimer($that::RESOLUTION_DELAY, function() use ($deferred, $ips) { |
|
95 | 95 | $deferred->resolve($ips); |
96 | 96 | }); |
97 | 97 | |
98 | - $that->resolverPromises[Message::TYPE_AAAA]->then(function () use ($that, $timer, $deferred, $ips) { |
|
98 | + $that->resolverPromises[Message::TYPE_AAAA]->then(function() use ($that, $timer, $deferred, $ips) { |
|
99 | 99 | $that->loop->cancelTimer($timer); |
100 | 100 | $deferred->resolve($ips); |
101 | 101 | }); |
102 | 102 | |
103 | 103 | return $deferred->promise(); |
104 | 104 | })->then($lookupResolve(Message::TYPE_A)); |
105 | - }, function ($_, $reject) use ($that, &$timer) { |
|
105 | + }, function($_, $reject) use ($that, &$timer) { |
|
106 | 106 | $reject(new \RuntimeException( |
107 | 107 | 'Connection to ' . $that->uri . ' cancelled' . (!$that->connectionPromises ? ' during DNS lookup' : '') . ' (ECONNABORTED)', |
108 | 108 | \defined('SOCKET_ECONNABORTED') ? \SOCKET_ECONNABORTED : 103 |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | public function resolve($type, $reject) |
128 | 128 | { |
129 | 129 | $that = $this; |
130 | - return $that->resolver->resolveAll($that->host, $type)->then(null, function (\Exception $e) use ($type, $reject, $that) { |
|
130 | + return $that->resolver->resolveAll($that->host, $type)->then(null, function(\Exception $e) use ($type, $reject, $that) { |
|
131 | 131 | unset($that->resolverPromises[$type]); |
132 | 132 | $that->resolved[$type] = true; |
133 | 133 | |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | $index = \key($this->connectionPromises); |
172 | 172 | |
173 | 173 | $that = $this; |
174 | - $that->connectionPromises[$index]->then(function ($connection) use ($that, $index, $resolve) { |
|
174 | + $that->connectionPromises[$index]->then(function($connection) use ($that, $index, $resolve) { |
|
175 | 175 | unset($that->connectionPromises[$index]); |
176 | 176 | |
177 | 177 | $that->cleanUp(); |
178 | 178 | |
179 | 179 | $resolve($connection); |
180 | - }, function (\Exception $e) use ($that, $index, $ip, $resolve, $reject) { |
|
180 | + }, function(\Exception $e) use ($that, $index, $ip, $resolve, $reject) { |
|
181 | 181 | unset($that->connectionPromises[$index]); |
182 | 182 | |
183 | 183 | $that->failureCount++; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | // Allow next connection attempt in 100ms: https://tools.ietf.org/html/rfc8305#section-5 |
220 | 220 | // Only start timer when more IPs are queued or when DNS query is still pending (might add more IPs) |
221 | 221 | if ($this->nextAttemptTimer === null && (\count($this->connectQueue) > 0 || $this->resolved[Message::TYPE_A] === false || $this->resolved[Message::TYPE_AAAA] === false)) { |
222 | - $this->nextAttemptTimer = $this->loop->addTimer(self::CONNECTION_ATTEMPT_DELAY, function () use ($that, $resolve, $reject) { |
|
222 | + $this->nextAttemptTimer = $this->loop->addTimer(self::CONNECTION_ATTEMPT_DELAY, function() use ($that, $resolve, $reject) { |
|
223 | 223 | $that->nextAttemptTimer = null; |
224 | 224 | |
225 | 225 | if ($that->connectQueue) { |
@@ -328,6 +328,6 @@ discard block |
||
328 | 328 | $message = ': ' . $message; |
329 | 329 | } |
330 | 330 | |
331 | - return 'Connection to ' . $this->uri . ' failed' . $message; |
|
331 | + return 'Connection to ' . $this->uri . ' failed' . $message; |
|
332 | 332 | } |
333 | 333 | } |