@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $rdata = array(); |
175 | 175 | while ($consumed < $expected) { |
176 | 176 | $len = ord($data[$consumed]); |
177 | - $rdata[] = (string)substr($data, $consumed + 1, $len); |
|
177 | + $rdata[] = (string) substr($data, $consumed + 1, $len); |
|
178 | 178 | $consumed += $len + 1; |
179 | 179 | } |
180 | 180 | } elseif (Message::TYPE_MX === $type) { |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | \implode( |
292 | 292 | '.', |
293 | 293 | \array_map( |
294 | - function ($label) { |
|
294 | + function($label) { |
|
295 | 295 | return \addcslashes($label, "\0..\40.\177"); |
296 | 296 | }, |
297 | 297 | $labels |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | $stream = $this->streamExecutor; |
67 | 67 | $pending = $this->datagramExecutor->query($query); |
68 | 68 | |
69 | - return new Promise(function ($resolve, $reject) use (&$pending, $stream, $query) { |
|
69 | + return new Promise(function($resolve, $reject) use (&$pending, $stream, $query) { |
|
70 | 70 | $pending->then( |
71 | 71 | $resolve, |
72 | - function ($e) use (&$pending, $stream, $query, $resolve, $reject) { |
|
72 | + function($e) use (&$pending, $stream, $query, $resolve, $reject) { |
|
73 | 73 | if ($e->getCode() === (\defined('SOCKET_EMSGSIZE') ? \SOCKET_EMSGSIZE : 90)) { |
74 | 74 | $pending = $stream->query($query)->then($resolve, $reject); |
75 | 75 | } else { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | ); |
80 | - }, function () use (&$pending) { |
|
80 | + }, function() use (&$pending) { |
|
81 | 81 | $pending->cancel(); |
82 | 82 | $pending = null; |
83 | 83 | }); |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | $fallback = $this->fallback; |
22 | 22 | $promise = $this->executor->query($query); |
23 | 23 | |
24 | - return new Promise(function ($resolve, $reject) use (&$promise, $fallback, $query, &$cancelled) { |
|
25 | - $promise->then($resolve, function (\Exception $e1) use ($fallback, $query, $resolve, $reject, &$cancelled, &$promise) { |
|
24 | + return new Promise(function($resolve, $reject) use (&$promise, $fallback, $query, &$cancelled) { |
|
25 | + $promise->then($resolve, function(\Exception $e1) use ($fallback, $query, $resolve, $reject, &$cancelled, &$promise) { |
|
26 | 26 | // reject if primary resolution rejected due to cancellation |
27 | 27 | if ($cancelled) { |
28 | 28 | $reject($e1); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | // start fallback query if primary query rejected |
33 | - $promise = $fallback->query($query)->then($resolve, function (\Exception $e2) use ($e1, $reject) { |
|
33 | + $promise = $fallback->query($query)->then($resolve, function(\Exception $e2) use ($e1, $reject) { |
|
34 | 34 | $append = $e2->getMessage(); |
35 | 35 | if (($pos = strpos($append, ':')) !== false) { |
36 | 36 | $append = substr($append, $pos + 2); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $reject(new \RuntimeException($e1->getMessage() . '. ' . $append)); |
41 | 41 | }); |
42 | 42 | }); |
43 | - }, function () use (&$promise, &$cancelled) { |
|
43 | + }, function() use (&$promise, &$cancelled) { |
|
44 | 44 | // cancel pending query (primary or fallback) |
45 | 45 | $cancelled = true; |
46 | 46 | $promise->cancel(); |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | $executor = $this->executor; |
33 | 33 | |
34 | 34 | $pending = $cache->get($id); |
35 | - return new Promise(function ($resolve, $reject) use ($query, $id, $cache, $executor, &$pending, $that) { |
|
35 | + return new Promise(function($resolve, $reject) use ($query, $id, $cache, $executor, &$pending, $that) { |
|
36 | 36 | $pending->then( |
37 | - function ($message) use ($query, $id, $cache, $executor, &$pending, $that) { |
|
37 | + function($message) use ($query, $id, $cache, $executor, &$pending, $that) { |
|
38 | 38 | // return cached response message on cache hit |
39 | 39 | if ($message !== null) { |
40 | 40 | return $message; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | // perform DNS lookup if not already cached |
44 | 44 | return $pending = $executor->query($query)->then( |
45 | - function (Message $message) use ($cache, $id, $that) { |
|
45 | + function(Message $message) use ($cache, $id, $that) { |
|
46 | 46 | // DNS response message received => store in cache when not truncated and return |
47 | 47 | if (!$message->tc) { |
48 | 48 | $cache->set($id, $message, $that->ttl($message)); |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | } |
53 | 53 | ); |
54 | 54 | } |
55 | - )->then($resolve, function ($e) use ($reject, &$pending) { |
|
55 | + )->then($resolve, function($e) use ($reject, &$pending) { |
|
56 | 56 | $reject($e); |
57 | 57 | $pending = null; |
58 | 58 | }); |
59 | - }, function ($_, $reject) use (&$pending, $query) { |
|
59 | + }, function($_, $reject) use (&$pending, $query) { |
|
60 | 60 | $reject(new \RuntimeException('DNS query for ' . $query->describe() . ' has been cancelled')); |
61 | 61 | $pending->cancel(); |
62 | 62 | $pending = null; |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | $this->pending[$key] = $promise; |
59 | 59 | $this->counts[$key] = 1; |
60 | 60 | |
61 | - $pending =& $this->pending; |
|
62 | - $counts =& $this->counts; |
|
63 | - $promise->then(function () use ($key, &$pending, &$counts) { |
|
61 | + $pending = & $this->pending; |
|
62 | + $counts = & $this->counts; |
|
63 | + $promise->then(function() use ($key, &$pending, &$counts) { |
|
64 | 64 | unset($pending[$key], $counts[$key]); |
65 | - }, function () use ($key, &$pending, &$counts) { |
|
65 | + }, function() use ($key, &$pending, &$counts) { |
|
66 | 66 | unset($pending[$key], $counts[$key]); |
67 | 67 | }); |
68 | 68 | } |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | // Return a child promise awaiting the pending query. |
71 | 71 | // Cancelling this child promise should only cancel the pending query |
72 | 72 | // when no other child promise is awaiting the same query. |
73 | - $pending =& $this->pending; |
|
74 | - $counts =& $this->counts; |
|
75 | - return new Promise(function ($resolve, $reject) use ($promise) { |
|
73 | + $pending = & $this->pending; |
|
74 | + $counts = & $this->counts; |
|
75 | + return new Promise(function($resolve, $reject) use ($promise) { |
|
76 | 76 | $promise->then($resolve, $reject); |
77 | - }, function () use (&$promise, $key, $query, &$pending, &$counts) { |
|
77 | + }, function() use (&$promise, $key, $query, &$pending, &$counts) { |
|
78 | 78 | if (--$counts[$key] < 1) { |
79 | 79 | unset($pending[$key], $counts[$key]); |
80 | 80 | $promise->cancel(); |
@@ -23,19 +23,19 @@ |
||
23 | 23 | |
24 | 24 | public function tryQuery(Query $query, $retries) |
25 | 25 | { |
26 | - $deferred = new Deferred(function () use (&$promise) { |
|
26 | + $deferred = new Deferred(function() use (&$promise) { |
|
27 | 27 | if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) { |
28 | 28 | $promise->cancel(); |
29 | 29 | } |
30 | 30 | }); |
31 | 31 | |
32 | - $success = function ($value) use ($deferred, &$errorback) { |
|
32 | + $success = function($value) use ($deferred, &$errorback) { |
|
33 | 33 | $errorback = null; |
34 | 34 | $deferred->resolve($value); |
35 | 35 | }; |
36 | 36 | |
37 | 37 | $executor = $this->executor; |
38 | - $errorback = function ($e) use ($deferred, &$promise, $query, $success, &$errorback, &$retries, $executor) { |
|
38 | + $errorback = function($e) use ($deferred, &$promise, $query, $success, &$errorback, &$retries, $executor) { |
|
39 | 39 | if (!$e instanceof TimeoutException) { |
40 | 40 | $errorback = null; |
41 | 41 | $deferred->reject($e); |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | |
35 | 35 | $loop = $this->loop; |
36 | 36 | $time = $this->timeout; |
37 | - return new Promise(function ($resolve, $reject) use ($loop, $time, $promise, $query) { |
|
37 | + return new Promise(function($resolve, $reject) use ($loop, $time, $promise, $query) { |
|
38 | 38 | $timer = null; |
39 | - $promise = $promise->then(function ($v) use (&$timer, $loop, $resolve) { |
|
39 | + $promise = $promise->then(function($v) use (&$timer, $loop, $resolve) { |
|
40 | 40 | if ($timer) { |
41 | 41 | $loop->cancelTimer($timer); |
42 | 42 | } |
43 | 43 | $timer = false; |
44 | 44 | $resolve($v); |
45 | - }, function ($v) use (&$timer, $loop, $reject) { |
|
45 | + }, function($v) use (&$timer, $loop, $reject) { |
|
46 | 46 | if ($timer) { |
47 | 47 | $loop->cancelTimer($timer); |
48 | 48 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | // start timeout timer which will cancel the pending promise |
59 | - $timer = $loop->addTimer($time, function () use ($time, &$promise, $reject, $query) { |
|
59 | + $timer = $loop->addTimer($time, function() use ($time, &$promise, $reject, $query) { |
|
60 | 60 | $reject(new TimeoutException( |
61 | 61 | 'DNS query for ' . $query->describe() . ' timed out' |
62 | 62 | )); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $promise->cancel(); |
68 | 68 | $promise = null; |
69 | 69 | }); |
70 | - }, function () use (&$promise) { |
|
70 | + }, function() use (&$promise) { |
|
71 | 71 | // Cancelling this promise will cancel the pending query, thus triggering the rejection logic above. |
72 | 72 | // Avoid garbage references in call stack by passing pending promise by reference. |
73 | 73 | assert(\method_exists($promise, 'cancel')); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $socket = @\stream_socket_client($this->nameserver, $errno, $errstr, 0, \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT); |
181 | 181 | if ($socket === false) { |
182 | 182 | return \React\Promise\reject(new \RuntimeException( |
183 | - 'DNS query for ' . $query->describe() . ' failed: Unable to connect to DNS server ' . $this->nameserver . ' (' . $errstr . ')', |
|
183 | + 'DNS query for ' . $query->describe() . ' failed: Unable to connect to DNS server ' . $this->nameserver . ' (' . $errstr . ')', |
|
184 | 184 | $errno |
185 | 185 | )); |
186 | 186 | } |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | $this->loop->addWriteStream($this->socket, array($this, 'handleWritable')); |
206 | 206 | } |
207 | 207 | |
208 | - $names =& $this->names; |
|
208 | + $names = & $this->names; |
|
209 | 209 | $that = $this; |
210 | - $deferred = new Deferred(function () use ($that, &$names, $request) { |
|
210 | + $deferred = new Deferred(function() use ($that, &$names, $request) { |
|
211 | 211 | // remove from list of pending names, but remember pending query |
212 | 212 | $name = $names[$request->id]; |
213 | 213 | unset($names[$request->id]); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | $errno = 0; |
254 | 254 | $errstr = ''; |
255 | - \set_error_handler(function ($_, $error) use (&$errno, &$errstr) { |
|
255 | + \set_error_handler(function($_, $error) use (&$errno, &$errstr) { |
|
256 | 256 | // Match errstr from PHP's warning message. |
257 | 257 | // fwrite(): Send of 327712 bytes failed with errno=32 Broken pipe |
258 | 258 | \preg_match('/errno=(\d+) (.+)/', $error, $m); |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | $data = \substr($this->readBuffer, 2, $length); |
309 | - $this->readBuffer = (string)substr($this->readBuffer, $length + 2); |
|
309 | + $this->readBuffer = (string) substr($this->readBuffer, $length + 2); |
|
310 | 310 | |
311 | 311 | try { |
312 | 312 | $response = $this->parser->parseMessage($data); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | { |
375 | 375 | if ($this->idleTimer === null && !$this->names) { |
376 | 376 | $that = $this; |
377 | - $this->idleTimer = $this->loop->addTimer($this->idlePeriod, function () use ($that) { |
|
377 | + $this->idleTimer = $this->loop->addTimer($this->idlePeriod, function() use ($that) { |
|
378 | 378 | $that->closeError('Idle timeout'); |
379 | 379 | }); |
380 | 380 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $socket = @\stream_socket_client($this->nameserver, $errno, $errstr, 0); |
139 | 139 | if ($socket === false) { |
140 | 140 | return \React\Promise\reject(new \RuntimeException( |
141 | - 'DNS query for ' . $query->describe() . ' failed: Unable to connect to DNS server ' . $this->nameserver . ' (' . $errstr . ')', |
|
141 | + 'DNS query for ' . $query->describe() . ' failed: Unable to connect to DNS server ' . $this->nameserver . ' (' . $errstr . ')', |
|
142 | 142 | $errno |
143 | 143 | )); |
144 | 144 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | // set socket to non-blocking and immediately try to send (fill write buffer) |
147 | 147 | \stream_set_blocking($socket, false); |
148 | 148 | |
149 | - \set_error_handler(function ($_, $error) use (&$errno, &$errstr) { |
|
149 | + \set_error_handler(function($_, $error) use (&$errno, &$errstr) { |
|
150 | 150 | // Write may potentially fail, but most common errors are already caught by connection check above. |
151 | 151 | // Among others, macOS is known to report here when trying to send to broadcast address. |
152 | 152 | // This can also be reproduced by writing data exceeding `stream_set_chunk_size()` to a server refusing UDP data. |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | |
163 | 163 | if ($written !== \strlen($queryData)) { |
164 | 164 | return \React\Promise\reject(new \RuntimeException( |
165 | - 'DNS query for ' . $query->describe() . ' failed: Unable to send query to DNS server ' . $this->nameserver . ' (' . $errstr . ')', |
|
165 | + 'DNS query for ' . $query->describe() . ' failed: Unable to send query to DNS server ' . $this->nameserver . ' (' . $errstr . ')', |
|
166 | 166 | $errno |
167 | 167 | )); |
168 | 168 | } |
169 | 169 | |
170 | 170 | $loop = $this->loop; |
171 | - $deferred = new Deferred(function () use ($loop, $socket, $query) { |
|
171 | + $deferred = new Deferred(function() use ($loop, $socket, $query) { |
|
172 | 172 | // cancellation should remove socket from loop and close socket |
173 | 173 | $loop->removeReadStream($socket); |
174 | 174 | \fclose($socket); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $max = $this->maxPacketSize; |
180 | 180 | $parser = $this->parser; |
181 | 181 | $nameserver = $this->nameserver; |
182 | - $loop->addReadStream($socket, function ($socket) use ($loop, $deferred, $query, $parser, $request, $max, $nameserver) { |
|
182 | + $loop->addReadStream($socket, function($socket) use ($loop, $deferred, $query, $parser, $request, $max, $nameserver) { |
|
183 | 183 | // try to read a single data packet from the DNS server |
184 | 184 | // ignoring any errors, this is uses UDP packets and not a stream of data |
185 | 185 | $data = @\fread($socket, $max); |