@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $errno = 0; |
| 71 | 71 | $errstr = ''; |
| 72 | - \set_error_handler(function ($_, $error) use (&$errno, &$errstr) { |
|
| 72 | + \set_error_handler(function($_, $error) use (&$errno, &$errstr) { |
|
| 73 | 73 | // PHP does not seem to report errno/errstr for Unix domain sockets (UDS) right now. |
| 74 | 74 | // This only applies to UDS server sockets, see also https://3v4l.org/NAhpr. |
| 75 | 75 | // Parse PHP warning message containing unknown error, HHVM reports proper info at least. |
| 76 | 76 | if (\preg_match('/\(([^\)]+)\)|\[(\d+)\]: (.*)/', $error, $match)) { |
| 77 | 77 | $errstr = isset($match[3]) ? $match['3'] : $match[1]; |
| 78 | - $errno = isset($match[2]) ? (int)$match[2] : 0; |
|
| 78 | + $errno = isset($match[2]) ? (int) $match[2] : 0; |
|
| 79 | 79 | } |
| 80 | 80 | }); |
| 81 | 81 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $that = $this; |
| 129 | - $this->loop->addReadStream($this->master, function ($master) use ($that) { |
|
| 129 | + $this->loop->addReadStream($this->master, function($master) use ($that) { |
|
| 130 | 130 | try { |
| 131 | 131 | $newSocket = SocketServer::accept($master); |
| 132 | 132 | } catch (\RuntimeException $e) { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | // swap arguments for legacy constructor signature |
| 59 | 59 | if (($context instanceof LoopInterface || $context === null) && (\func_num_args() <= 1 || \is_array($loop))) { |
| 60 | - $swap = $loop === null ? array(): $loop; |
|
| 60 | + $swap = $loop === null ? array() : $loop; |
|
| 61 | 61 | $loop = $context; |
| 62 | 62 | $context = $swap; |
| 63 | 63 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | if ($context['timeout'] === true) { |
| 81 | - $context['timeout'] = (float)\ini_get("default_socket_timeout"); |
|
| 81 | + $context['timeout'] = (float) \ini_get("default_socket_timeout"); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | if ($context['tcp'] instanceof ConnectorInterface) { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | { |
| 165 | 165 | $scheme = 'tcp'; |
| 166 | 166 | if (\strpos($uri, '://') !== false) { |
| 167 | - $scheme = (string)\substr($uri, 0, \strpos($uri, '://')); |
|
| 167 | + $scheme = (string) \substr($uri, 0, \strpos($uri, '://')); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | if (!isset($this->connectors[$scheme])) { |
@@ -88,10 +88,10 @@ |
||
| 88 | 88 | $this->server = $server; |
| 89 | 89 | |
| 90 | 90 | $that = $this; |
| 91 | - $server->on('connection', function (ConnectionInterface $conn) use ($that) { |
|
| 91 | + $server->on('connection', function(ConnectionInterface $conn) use ($that) { |
|
| 92 | 92 | $that->emit('connection', array($conn)); |
| 93 | 93 | }); |
| 94 | - $server->on('error', function (Exception $error) use ($that) { |
|
| 94 | + $server->on('error', function(Exception $error) use ($that) { |
|
| 95 | 95 | $that->emit('error', array($error)); |
| 96 | 96 | }); |
| 97 | 97 | } |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | public function connect() |
| 67 | 67 | { |
| 68 | 68 | $that = $this; |
| 69 | - return new Promise\Promise(function ($resolve, $reject) use ($that) { |
|
| 70 | - $lookupResolve = function ($type) use ($that, $resolve, $reject) { |
|
| 71 | - return function (array $ips) use ($that, $type, $resolve, $reject) { |
|
| 69 | + return new Promise\Promise(function($resolve, $reject) use ($that) { |
|
| 70 | + $lookupResolve = function($type) use ($that, $resolve, $reject) { |
|
| 71 | + return function(array $ips) use ($that, $type, $resolve, $reject) { |
|
| 72 | 72 | unset($that->resolverPromises[$type]); |
| 73 | 73 | $that->resolved[$type] = true; |
| 74 | 74 | |
@@ -82,29 +82,29 @@ discard block |
||
| 82 | 82 | }; |
| 83 | 83 | |
| 84 | 84 | $that->resolverPromises[Message::TYPE_AAAA] = $that->resolve(Message::TYPE_AAAA, $reject)->then($lookupResolve(Message::TYPE_AAAA)); |
| 85 | - $that->resolverPromises[Message::TYPE_A] = $that->resolve(Message::TYPE_A, $reject)->then(function (array $ips) use ($that) { |
|
| 85 | + $that->resolverPromises[Message::TYPE_A] = $that->resolve(Message::TYPE_A, $reject)->then(function(array $ips) use ($that) { |
|
| 86 | 86 | // happy path: IPv6 has resolved already (or could not resolve), continue with IPv4 addresses |
| 87 | 87 | if ($that->resolved[Message::TYPE_AAAA] === true || !$ips) { |
| 88 | 88 | return $ips; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Otherwise delay processing IPv4 lookup until short timer passes or IPv6 resolves in the meantime |
| 92 | - $deferred = new Promise\Deferred(function () use (&$ips) { |
|
| 92 | + $deferred = new Promise\Deferred(function() use (&$ips) { |
|
| 93 | 93 | // discard all IPv4 addresses if cancelled |
| 94 | 94 | $ips = array(); |
| 95 | 95 | }); |
| 96 | - $timer = $that->loop->addTimer($that::RESOLUTION_DELAY, function () use ($deferred, $ips) { |
|
| 96 | + $timer = $that->loop->addTimer($that::RESOLUTION_DELAY, function() use ($deferred, $ips) { |
|
| 97 | 97 | $deferred->resolve($ips); |
| 98 | 98 | }); |
| 99 | 99 | |
| 100 | - $that->resolverPromises[Message::TYPE_AAAA]->then(function () use ($that, $timer, $deferred, &$ips) { |
|
| 100 | + $that->resolverPromises[Message::TYPE_AAAA]->then(function() use ($that, $timer, $deferred, &$ips) { |
|
| 101 | 101 | $that->loop->cancelTimer($timer); |
| 102 | 102 | $deferred->resolve($ips); |
| 103 | 103 | }); |
| 104 | 104 | |
| 105 | 105 | return $deferred->promise(); |
| 106 | 106 | })->then($lookupResolve(Message::TYPE_A)); |
| 107 | - }, function ($_, $reject) use ($that) { |
|
| 107 | + }, function($_, $reject) use ($that) { |
|
| 108 | 108 | $reject(new \RuntimeException( |
| 109 | 109 | 'Connection to ' . $that->uri . ' cancelled' . (!$that->connectionPromises ? ' during DNS lookup' : '') . ' (ECONNABORTED)', |
| 110 | 110 | \defined('SOCKET_ECONNABORTED') ? \SOCKET_ECONNABORTED : 103 |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | public function resolve($type, $reject) |
| 127 | 127 | { |
| 128 | 128 | $that = $this; |
| 129 | - return $that->resolver->resolveAll($that->host, $type)->then(null, function (\Exception $e) use ($type, $reject, $that) { |
|
| 129 | + return $that->resolver->resolveAll($that->host, $type)->then(null, function(\Exception $e) use ($type, $reject, $that) { |
|
| 130 | 130 | unset($that->resolverPromises[$type]); |
| 131 | 131 | $that->resolved[$type] = true; |
| 132 | 132 | |
@@ -170,13 +170,13 @@ discard block |
||
| 170 | 170 | $index = \key($this->connectionPromises); |
| 171 | 171 | |
| 172 | 172 | $that = $this; |
| 173 | - $that->connectionPromises[$index]->then(function ($connection) use ($that, $index, $resolve) { |
|
| 173 | + $that->connectionPromises[$index]->then(function($connection) use ($that, $index, $resolve) { |
|
| 174 | 174 | unset($that->connectionPromises[$index]); |
| 175 | 175 | |
| 176 | 176 | $that->cleanUp(); |
| 177 | 177 | |
| 178 | 178 | $resolve($connection); |
| 179 | - }, function (\Exception $e) use ($that, $index, $ip, $resolve, $reject) { |
|
| 179 | + }, function(\Exception $e) use ($that, $index, $ip, $resolve, $reject) { |
|
| 180 | 180 | unset($that->connectionPromises[$index]); |
| 181 | 181 | |
| 182 | 182 | $that->failureCount++; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | // Allow next connection attempt in 100ms: https://tools.ietf.org/html/rfc8305#section-5 |
| 219 | 219 | // Only start timer when more IPs are queued or when DNS query is still pending (might add more IPs) |
| 220 | 220 | if ($this->nextAttemptTimer === null && (\count($this->connectQueue) > 0 || $this->resolved[Message::TYPE_A] === false || $this->resolved[Message::TYPE_AAAA] === false)) { |
| 221 | - $this->nextAttemptTimer = $this->loop->addTimer(self::CONNECTION_ATTEMPT_DELAY, function () use ($that, $resolve, $reject) { |
|
| 221 | + $this->nextAttemptTimer = $this->loop->addTimer(self::CONNECTION_ATTEMPT_DELAY, function() use ($that, $resolve, $reject) { |
|
| 222 | 222 | $that->nextAttemptTimer = null; |
| 223 | 223 | |
| 224 | 224 | if ($that->connectQueue) { |
@@ -329,6 +329,6 @@ discard block |
||
| 329 | 329 | $message = ': ' . $message; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - return 'Connection to ' . $this->uri . ' failed' . $message; |
|
| 332 | + return 'Connection to ' . $this->uri . ' failed' . $message; |
|
| 333 | 333 | } |
| 334 | 334 | } |
@@ -160,12 +160,12 @@ |
||
| 160 | 160 | // remove trailing colon from address for HHVM < 3.19: https://3v4l.org/5C1lo |
| 161 | 161 | // note that technically ":" is a valid address, so keep this in place otherwise |
| 162 | 162 | if (\substr($address, -1) === ':' && \defined('HHVM_VERSION_ID') && \HHVM_VERSION_ID < 31900) { |
| 163 | - $address = (string)\substr($address, 0, -1); // @codeCoverageIgnore |
|
| 163 | + $address = (string) \substr($address, 0, -1); // @codeCoverageIgnore |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // work around unknown addresses should return null value: https://3v4l.org/5C1lo and https://bugs.php.net/bug.php?id=74556 |
| 167 | 167 | // PHP uses "\0" string and HHVM uses empty string (colon removed above) |
| 168 | - if ($address === '' || $address[0] === "\x00" ) { |
|
| 168 | + if ($address === '' || $address[0] === "\x00") { |
|
| 169 | 169 | return null; // @codeCoverageIgnore |
| 170 | 170 | } |
| 171 | 171 | |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | $this->context = $context; |
| 143 | 143 | |
| 144 | 144 | $that = $this; |
| 145 | - $this->tcp->on('connection', function ($connection) use ($that) { |
|
| 145 | + $this->tcp->on('connection', function($connection) use ($that) { |
|
| 146 | 146 | $that->handleConnection($connection); |
| 147 | 147 | }); |
| 148 | - $this->tcp->on('error', function ($error) use ($that) { |
|
| 148 | + $this->tcp->on('error', function($error) use ($that) { |
|
| 149 | 149 | $that->emit('error', array($error)); |
| 150 | 150 | }); |
| 151 | 151 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | return null; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - return \str_replace('tcp://' , 'tls://', $address); |
|
| 160 | + return \str_replace('tcp://', 'tls://', $address); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | public function pause() |
@@ -193,10 +193,10 @@ discard block |
||
| 193 | 193 | $that = $this; |
| 194 | 194 | |
| 195 | 195 | $this->encryption->enable($connection)->then( |
| 196 | - function ($conn) use ($that) { |
|
| 196 | + function($conn) use ($that) { |
|
| 197 | 197 | $that->emit('connection', array($conn)); |
| 198 | 198 | }, |
| 199 | - function ($error) use ($that, $connection, $remote) { |
|
| 199 | + function($error) use ($that, $connection, $remote) { |
|
| 200 | 200 | $error = new \RuntimeException( |
| 201 | 201 | 'Connection from ' . $remote . ' failed during TLS handshake: ' . $error->getMessage(), |
| 202 | 202 | $error->getCode() |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $this->loop = $loop ?: Loop::get(); |
| 138 | 138 | |
| 139 | 139 | // a single port has been given => assume localhost |
| 140 | - if ((string)(int)$uri === (string)$uri) { |
|
| 140 | + if ((string) (int) $uri === (string) $uri) { |
|
| 141 | 141 | $uri = '127.0.0.1:' . $uri; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $that = $this; |
| 232 | - $this->loop->addReadStream($this->master, function ($master) use ($that) { |
|
| 232 | + $this->loop->addReadStream($this->master, function($master) use ($that) { |
|
| 233 | 233 | try { |
| 234 | 234 | $newSocket = SocketServer::accept($master); |
| 235 | 235 | } catch (\RuntimeException $e) { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | /** @var \React\Promise\PromiseInterface<ConnectionInterface> $promise */ |
| 56 | 56 | $promise = $this->connector->connect( |
| 57 | 57 | \str_replace('tls://', '', $uri) |
| 58 | - )->then(function (ConnectionInterface $connection) use ($context, $encryption, $uri, &$promise, &$connected) { |
|
| 58 | + )->then(function(ConnectionInterface $connection) use ($context, $encryption, $uri, &$promise, &$connected) { |
|
| 59 | 59 | // (unencrypted) TCP/IP connection succeeded |
| 60 | 60 | $connected = true; |
| 61 | 61 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // try to enable encryption |
| 73 | - return $promise = $encryption->enable($connection)->then(null, function ($error) use ($connection, $uri) { |
|
| 73 | + return $promise = $encryption->enable($connection)->then(null, function($error) use ($connection, $uri) { |
|
| 74 | 74 | // establishing encryption failed => close invalid connection and return error |
| 75 | 75 | $connection->close(); |
| 76 | 76 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $error->getCode() |
| 80 | 80 | ); |
| 81 | 81 | }); |
| 82 | - }, function (\Exception $e) use ($uri) { |
|
| 82 | + }, function(\Exception $e) use ($uri) { |
|
| 83 | 83 | if ($e instanceof \RuntimeException) { |
| 84 | 84 | $message = \preg_replace('/^Connection to [^ ]+/', '', $e->getMessage()); |
| 85 | 85 | $e = new \RuntimeException( |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | }); |
| 114 | 114 | |
| 115 | 115 | return new \React\Promise\Promise( |
| 116 | - function ($resolve, $reject) use ($promise) { |
|
| 116 | + function($resolve, $reject) use ($promise) { |
|
| 117 | 117 | $promise->then($resolve, $reject); |
| 118 | 118 | }, |
| 119 | - function ($_, $reject) use (&$promise, $uri, &$connected) { |
|
| 119 | + function($_, $reject) use (&$promise, $uri, &$connected) { |
|
| 120 | 120 | if ($connected) { |
| 121 | 121 | $reject(new \RuntimeException( |
| 122 | 122 | 'Connection to ' . $uri . ' cancelled during TLS handshake (ECONNABORTED)', |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | // TODO: add write() event to make sure we're not sending any excessive data |
| 67 | 67 | |
| 68 | 68 | // cancelling this leaves this stream in an inconsistent state… |
| 69 | - $deferred = new Deferred(function () { |
|
| 69 | + $deferred = new Deferred(function() { |
|
| 70 | 70 | throw new \RuntimeException(); |
| 71 | 71 | }); |
| 72 | 72 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $that = $this; |
| 84 | - $toggleCrypto = function () use ($socket, $deferred, $toggle, $method, $that) { |
|
| 84 | + $toggleCrypto = function() use ($socket, $deferred, $toggle, $method, $that) { |
|
| 85 | 85 | $that->toggleCrypto($socket, $deferred, $toggle, $method); |
| 86 | 86 | }; |
| 87 | 87 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | $loop = $this->loop; |
| 95 | 95 | |
| 96 | - return $deferred->promise()->then(function () use ($stream, $socket, $loop, $toggle) { |
|
| 96 | + return $deferred->promise()->then(function() use ($stream, $socket, $loop, $toggle) { |
|
| 97 | 97 | $loop->removeReadStream($socket); |
| 98 | 98 | |
| 99 | 99 | $stream->encryptionEnabled = $toggle; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function toggleCrypto($socket, Deferred $deferred, $toggle, $method) |
| 119 | 119 | { |
| 120 | 120 | $error = null; |
| 121 | - \set_error_handler(function ($_, $errstr) use (&$error) { |
|
| 121 | + \set_error_handler(function($_, $errstr) use (&$error) { |
|
| 122 | 122 | $error = \str_replace(array("\r", "\n"), ' ', $errstr); |
| 123 | 123 | |
| 124 | 124 | // remove useless function name from error message |