Skip to content

Commit 0cf2798

Browse files
authored
Merge pull request #148 from clue-labs/imports
Clean up and unify class imports
2 parents e9e206b + 04a6011 commit 0cf2798

14 files changed

+39
-32
lines changed

src/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use React\EventLoop\LoopInterface;
77
use React\Stream\DuplexResourceStream;
88
use React\Stream\Util;
9-
use React\Stream\WritableStreamInterface;
109
use React\Stream\WritableResourceStream;
10+
use React\Stream\WritableStreamInterface;
1111

1212
/**
1313
* The actual connection implementation for ConnectionInterface

src/Connector.php

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

33
namespace React\Socket;
44

5-
use React\EventLoop\LoopInterface;
6-
use React\Dns\Resolver\Resolver;
75
use React\Dns\Resolver\Factory;
6+
use React\Dns\Resolver\Resolver;
7+
use React\EventLoop\LoopInterface;
88
use React\Promise;
99
use RuntimeException;
1010

src/DnsConnector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use React\Dns\Resolver\Resolver;
66
use React\Promise;
77
use React\Promise\CancellablePromiseInterface;
8+
use InvalidArgumentException;
9+
use RuntimeException;
810

911
final class DnsConnector implements ConnectorInterface
1012
{
@@ -27,7 +29,7 @@ public function connect($uri)
2729
}
2830

2931
if (!$parts || !isset($parts['host'])) {
30-
return Promise\reject(new \InvalidArgumentException('Given URI "' . $uri . '" is invalid'));
32+
return Promise\reject(new InvalidArgumentException('Given URI "' . $uri . '" is invalid'));
3133
}
3234

3335
$host = trim($parts['host'], '[]');
@@ -97,7 +99,7 @@ function ($resolve, $reject) use ($promise) {
9799
},
98100
function ($_, $reject) use ($promise) {
99101
// cancellation should reject connection attempt
100-
$reject(new \RuntimeException('Connection attempt cancelled during DNS lookup'));
102+
$reject(new RuntimeException('Connection attempt cancelled during DNS lookup'));
101103

102104
// (try to) cancel pending DNS lookup
103105
if ($promise instanceof CancellablePromiseInterface) {

src/FixedUriConnector.php

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

33
namespace React\Socket;
44

5-
use React\Socket\ConnectorInterface;
6-
75
/**
86
* Decorates an existing Connector to always use a fixed, preconfigured URI
97
*

src/LimitingServer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace React\Socket;
44

55
use Evenement\EventEmitter;
6+
use Exception;
7+
use OverflowException;
68

79
/**
810
* The `LimitingServer` decorator wraps a given `ServerInterface` and is responsible
@@ -155,7 +157,7 @@ public function handleConnection(ConnectionInterface $connection)
155157
{
156158
// close connection if limit exceeded
157159
if ($this->limit !== null && count($this->connections) >= $this->limit) {
158-
$this->handleError(new \OverflowException('Connection closed because server reached connection limit'));
160+
$this->handleError(new OverflowException('Connection closed because server reached connection limit'));
159161
$connection->close();
160162
return;
161163
}
@@ -194,7 +196,7 @@ public function handleDisconnection(ConnectionInterface $connection)
194196
}
195197

196198
/** @internal */
197-
public function handleError(\Exception $error)
199+
public function handleError(Exception $error)
198200
{
199201
$this->emit('error', array($error));
200202
}

src/SecureConnector.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use React\EventLoop\LoopInterface;
66
use React\Promise;
7+
use BadMethodCallException;
8+
use InvalidArgumentException;
9+
use UnexpectedValueException;
710

811
final class SecureConnector implements ConnectorInterface
912
{
@@ -21,7 +24,7 @@ public function __construct(ConnectorInterface $connector, LoopInterface $loop,
2124
public function connect($uri)
2225
{
2326
if (!function_exists('stream_socket_enable_crypto')) {
24-
return Promise\reject(new \BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)')); // @codeCoverageIgnore
27+
return Promise\reject(new BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)')); // @codeCoverageIgnore
2528
}
2629

2730
if (strpos($uri, '://') === false) {
@@ -30,7 +33,7 @@ public function connect($uri)
3033

3134
$parts = parse_url($uri);
3235
if (!$parts || !isset($parts['scheme']) || $parts['scheme'] !== 'tls') {
33-
return Promise\reject(new \InvalidArgumentException('Given URI "' . $uri . '" is invalid'));
36+
return Promise\reject(new InvalidArgumentException('Given URI "' . $uri . '" is invalid'));
3437
}
3538

3639
$uri = str_replace('tls://', '', $uri);
@@ -42,7 +45,7 @@ public function connect($uri)
4245

4346
if (!$connection instanceof Connection) {
4447
$connection->close();
45-
throw new \UnexpectedValueException('Base connector does not use internal Connection class exposing stream resource');
48+
throw new UnexpectedValueException('Base connector does not use internal Connection class exposing stream resource');
4649
}
4750

4851
// set required SSL/TLS context options

src/SecureServer.php

Lines changed: 5 additions & 5 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\Socket\TcpServer;
8-
use React\Socket\ConnectionInterface;
7+
use BadMethodCallException;
8+
use UnexpectedValueException;
99

1010
/**
1111
* The `SecureServer` class implements the `ServerInterface` and is responsible
@@ -111,14 +111,14 @@ final class SecureServer extends EventEmitter implements ServerInterface
111111
* @param ServerInterface|TcpServer $tcp
112112
* @param LoopInterface $loop
113113
* @param array $context
114-
* @throws \BadMethodCallException for legacy HHVM < 3.8 due to lack of support
114+
* @throws BadMethodCallException for legacy HHVM < 3.8 due to lack of support
115115
* @see TcpServer
116116
* @link http://php.net/manual/en/context.ssl.php for TLS context options
117117
*/
118118
public function __construct(ServerInterface $tcp, LoopInterface $loop, array $context)
119119
{
120120
if (!function_exists('stream_socket_enable_crypto')) {
121-
throw new \BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)'); // @codeCoverageIgnore
121+
throw new BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)'); // @codeCoverageIgnore
122122
}
123123

124124
// default to empty passphrase to suppress blocking passphrase prompt
@@ -168,7 +168,7 @@ public function close()
168168
public function handleConnection(ConnectionInterface $connection)
169169
{
170170
if (!$connection instanceof Connection) {
171-
$this->emit('error', array(new \UnexpectedValueException('Base server does not use internal Connection class exposing stream resource')));
171+
$this->emit('error', array(new UnexpectedValueException('Base server does not use internal Connection class exposing stream resource')));
172172
$connection->end();
173173
return;
174174
}

src/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Evenement\EventEmitter;
66
use React\EventLoop\LoopInterface;
7+
use Exception;
78

89
final class Server extends EventEmitter implements ServerInterface
910
{
@@ -45,7 +46,7 @@ public function __construct($uri, LoopInterface $loop, array $context = array())
4546
$server->on('connection', function (ConnectionInterface $conn) use ($that) {
4647
$that->emit('connection', array($conn));
4748
});
48-
$server->on('error', function (\Exception $error) use ($that) {
49+
$server->on('error', function (Exception $error) use ($that) {
4950
$that->emit('error', array($error));
5051
});
5152
}

src/StreamEncryption.php

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

33
namespace React\Socket;
44

5-
use React\Promise\Deferred;
65
use React\EventLoop\LoopInterface;
6+
use React\Promise\Deferred;
7+
use RuntimeException;
78
use UnexpectedValueException;
89

910
/**
@@ -72,7 +73,7 @@ public function toggle(Connection $stream, $toggle)
7273

7374
$deferred = new Deferred(function ($_, $reject) use ($toggle) {
7475
// cancelling this leaves this stream in an inconsistent state…
75-
$reject(new \RuntimeException('Cancelled toggling encryption ' . $toggle ? 'on' : 'off'));
76+
$reject(new RuntimeException('Cancelled toggling encryption ' . $toggle ? 'on' : 'off'));
7677
});
7778

7879
// get actual stream socket from stream instance

src/TcpConnector.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace React\Socket;
44

55
use React\EventLoop\LoopInterface;
6-
use React\Stream\Stream;
76
use React\Promise;
7+
use InvalidArgumentException;
8+
use RuntimeException;
89

910
final class TcpConnector implements ConnectorInterface
1011
{
@@ -25,12 +26,12 @@ public function connect($uri)
2526

2627
$parts = parse_url($uri);
2728
if (!$parts || !isset($parts['scheme'], $parts['host'], $parts['port']) || $parts['scheme'] !== 'tcp') {
28-
return Promise\reject(new \InvalidArgumentException('Given URI "' . $uri . '" is invalid'));
29+
return Promise\reject(new InvalidArgumentException('Given URI "' . $uri . '" is invalid'));
2930
}
3031

3132
$ip = trim($parts['host'], '[]');
3233
if (false === filter_var($ip, FILTER_VALIDATE_IP)) {
33-
return Promise\reject(new \InvalidArgumentException('Given URI "' . $ip . '" does not contain a valid host IP'));
34+
return Promise\reject(new InvalidArgumentException('Given URI "' . $ip . '" does not contain a valid host IP'));
3435
}
3536

3637
// use context given in constructor
@@ -80,7 +81,7 @@ public function connect($uri)
8081
);
8182

8283
if (false === $socket) {
83-
return Promise\reject(new \RuntimeException(
84+
return Promise\reject(new RuntimeException(
8485
sprintf("Connection to %s failed: %s", $uri, $errstr),
8586
$errno
8687
));
@@ -106,7 +107,7 @@ private function waitForStreamOnce($stream)
106107
if (false === stream_socket_get_name($stream, true)) {
107108
fclose($stream);
108109

109-
$reject(new \RuntimeException('Connection refused'));
110+
$reject(new RuntimeException('Connection refused'));
110111
} else {
111112
$resolve(new Connection($stream, $loop));
112113
}
@@ -115,7 +116,7 @@ private function waitForStreamOnce($stream)
115116
$loop->removeWriteStream($stream);
116117
fclose($stream);
117118

118-
throw new \RuntimeException('Cancelled while waiting for TCP/IP connection to be established');
119+
throw new RuntimeException('Cancelled while waiting for TCP/IP connection to be established');
119120
});
120121
}
121122
}

0 commit comments

Comments
 (0)