Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react/dns": "^1.13",
"react/event-loop": "^1.2",
"react/promise": "^3.2 || ^2.6 || ^1.2.1",
"react/stream": "^1.4"
"react/stream": "3.x-dev as 1.666.666"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^7.5",
Expand Down
22 changes: 11 additions & 11 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,42 @@ public function __construct($resource, LoopInterface $loop)
$this->input->on('close', [$this, 'close']);
}

public function isReadable()
public function isReadable(): bool
{
return $this->input->isReadable();
}

public function isWritable()
public function isWritable(): bool
{
return $this->input->isWritable();
}

public function pause()
public function pause(): void
{
$this->input->pause();
}

public function resume()
public function resume(): void
{
$this->input->resume();
}

public function pipe(WritableStreamInterface $dest, array $options = [])
public function pipe(WritableStreamInterface $dest, array $options = []): WritableStreamInterface
{
return $this->input->pipe($dest, $options);
}

public function write($data)
public function write($data): bool
{
return $this->input->write($data);
}

public function end($data = null)
public function end($data = null): void
{
$this->input->end($data);
}

public function close()
public function close(): void
{
$this->input->close();
$this->handleClose();
Expand All @@ -132,7 +132,7 @@ public function handleClose()
@\stream_socket_shutdown($this->stream, \STREAM_SHUT_RDWR);
}

public function getRemoteAddress()
public function getRemoteAddress(): ?string
{
if (!\is_resource($this->stream)) {
return null;
Expand All @@ -141,7 +141,7 @@ public function getRemoteAddress()
return $this->parseAddress(\stream_socket_get_name($this->stream, true));
}

public function getLocalAddress()
public function getLocalAddress(): ?string
{
if (!\is_resource($this->stream)) {
return null;
Expand All @@ -150,7 +150,7 @@ public function getLocalAddress()
return $this->parseAddress(\stream_socket_get_name($this->stream, false));
}

private function parseAddress($address)
private function parseAddress($address): ?string
{
if ($address === false) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ interface ConnectionInterface extends DuplexStreamInterface
*
* @return ?string remote address (URI) or null if unknown
*/
public function getRemoteAddress();
public function getRemoteAddress(): ?string;

/**
* Returns the full local address (full URI with scheme, IP and port) where this connection has been established with
Expand Down Expand Up @@ -115,5 +115,5 @@ public function getRemoteAddress();
* @return ?string local address (URI) or null if unknown
* @see self::getRemoteAddress()
*/
public function getLocalAddress();
public function getLocalAddress(): ?string;
}
5 changes: 3 additions & 2 deletions src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use React\Dns\Resolver\Factory as DnsFactory;
use React\Dns\Resolver\ResolverInterface;
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
use function React\Promise\reject;

/**
Expand Down Expand Up @@ -146,7 +147,7 @@ public function __construct(array $context = [], ?LoopInterface $loop = null)
}
}

public function connect($uri)
public function connect($uri): PromiseInterface
{
$scheme = 'tcp';
if (\strpos($uri, '://') !== false) {
Expand All @@ -173,7 +174,7 @@ public function connect($uri)
* @return string
* @internal
*/
public static function uri(array $parts, $host, $ip)
public static function uri(array $parts, $host, $ip): string
{
$uri = '';

Expand Down
4 changes: 3 additions & 1 deletion src/ConnectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Socket;

use React\Promise\PromiseInterface;

/**
* The `ConnectorInterface` is responsible for providing an interface for
* establishing streaming connections, such as a normal TCP/IP connection.
Expand Down Expand Up @@ -55,5 +57,5 @@ interface ConnectorInterface
* Resolves with a `ConnectionInterface` on success or rejects with an `Exception` on error.
* @see ConnectionInterface
*/
public function connect($uri);
public function connect($uri): PromiseInterface;
}
2 changes: 1 addition & 1 deletion src/DnsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(ConnectorInterface $connector, ResolverInterface $re
$this->resolver = $resolver;
}

public function connect($uri)
public function connect($uri): PromiseInterface
{
$original = $uri;
if (\strpos($uri, '://') === false) {
Expand Down
10 changes: 5 additions & 5 deletions src/FdServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function __construct($fd, ?LoopInterface $loop = null)
$this->resume();
}

public function getAddress()
public function getAddress(): ?string
{
if (!\is_resource($this->master)) {
return null;
Expand All @@ -167,7 +167,7 @@ public function getAddress()
return 'tcp://' . $address;
}

public function pause()
public function pause(): void
{
if (!$this->listening) {
return;
Expand All @@ -177,7 +177,7 @@ public function pause()
$this->listening = false;
}

public function resume()
public function resume(): void
{
if ($this->listening || !\is_resource($this->master)) {
return;
Expand All @@ -195,7 +195,7 @@ public function resume()
$this->listening = true;
}

public function close()
public function close(): void
{
if (!\is_resource($this->master)) {
return;
Expand All @@ -207,7 +207,7 @@ public function close()
}

/** @internal */
public function handleConnection($socket)
public function handleConnection($socket): void
{
$connection = new Connection($socket, $this->loop);
$connection->unix = $this->unix;
Expand Down
4 changes: 3 additions & 1 deletion src/FixedUriConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Socket;

use React\Promise\PromiseInterface;

/**
* Decorates an existing Connector to always use a fixed, preconfigured URI
*
Expand Down Expand Up @@ -34,7 +36,7 @@ public function __construct($uri, ConnectorInterface $connector)
$this->connector = $connector;
}

public function connect($_)
public function connect($_): PromiseInterface
{
return $this->connector->connect($this->uri);
}
Expand Down
23 changes: 13 additions & 10 deletions src/HappyEyeBallsConnectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class HappyEyeBallsConnectionBuilder
public $lastError6;
public $lastError4;

public function __construct(LoopInterface $loop, ConnectorInterface $connector, ResolverInterface $resolver, $uri, $host, $parts)
public function __construct(LoopInterface $loop, ConnectorInterface $connector, ResolverInterface $resolver, string $uri, string $host, array $parts)
{
$this->loop = $loop;
$this->connector = $connector;
Expand All @@ -64,7 +64,7 @@ public function __construct(LoopInterface $loop, ConnectorInterface $connector,
$this->parts = $parts;
}

public function connect()
public function connect(): PromiseInterface
{
return new Promise(function ($resolve, $reject) {
$lookupResolve = function ($type) use ($resolve, $reject) {
Expand Down Expand Up @@ -123,7 +123,7 @@ public function connect()
* always resolves with a list of IP addresses on success or an empty
* list on error.
*/
public function resolve($type, $reject)
public function resolve(int $type, callable $reject): PromiseInterface
{
return $this->resolver->resolveAll($this->host, $type)->then(null, function (\Exception $e) use ($type, $reject) {
unset($this->resolverPromises[$type]);
Expand Down Expand Up @@ -159,7 +159,7 @@ public function resolve($type, $reject)
/**
* @internal
*/
public function check($resolve, $reject)
public function check(callable $resolve, callable $reject)
{
$ip = \array_shift($this->connectQueue);

Expand All @@ -168,13 +168,13 @@ public function check($resolve, $reject)
\end($this->connectionPromises);
$index = \key($this->connectionPromises);

$this->connectionPromises[$index]->then(function ($connection) use ($index, $resolve) {
$this->connectionPromises[$index]->then(function ($connection) use ($index, $resolve): void {
unset($this->connectionPromises[$index]);

$this->cleanUp();

$resolve($connection);
}, function (\Exception $e) use ($index, $ip, $resolve, $reject) {
}, function (\Exception $e) use ($index, $ip, $resolve, $reject): void {
unset($this->connectionPromises[$index]);

$this->failureCount++;
Expand Down Expand Up @@ -228,8 +228,9 @@ public function check($resolve, $reject)

/**
* @internal
* @return PromiseInterface<ConnectionInterface>
*/
public function attemptConnection($ip)
public function attemptConnection($ip): PromiseInterface
{
$uri = Connector::uri($this->parts, $this->host, $ip);

Expand All @@ -239,7 +240,7 @@ public function attemptConnection($ip)
/**
* @internal
*/
public function cleanUp()
public function cleanUp(): void
{
// clear list of outstanding IPs to avoid creating new connections
$this->connectQueue = [];
Expand Down Expand Up @@ -267,7 +268,7 @@ public function cleanUp()
/**
* @internal
*/
public function hasBeenResolved()
public function hasBeenResolved(): bool
{
foreach ($this->resolved as $typeHasBeenResolved) {
if ($typeHasBeenResolved === false) {
Expand All @@ -286,6 +287,8 @@ public function hasBeenResolved()
* @link https://tools.ietf.org/html/rfc8305#section-4
*
* @internal
*
* @param array<string> $ips
*/
public function mixIpsIntoConnectQueue(array $ips)
{
Expand All @@ -307,7 +310,7 @@ public function mixIpsIntoConnectQueue(array $ips)
* @internal
* @return string
*/
public function error()
public function error(): string
{
if ($this->lastError4 === $this->lastError6) {
$message = $this->lastError6;
Expand Down
3 changes: 2 additions & 1 deletion src/HappyEyeBallsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use React\Dns\Resolver\ResolverInterface;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
use function React\Promise\reject;

final class HappyEyeBallsConnector implements ConnectorInterface
Expand All @@ -20,7 +21,7 @@ public function __construct(?LoopInterface $loop, ConnectorInterface $connector,
$this->resolver = $resolver;
}

public function connect($uri)
public function connect($uri): PromiseInterface
{
$original = $uri;
if (\strpos($uri, '://') === false) {
Expand Down
16 changes: 8 additions & 8 deletions src/LimitingServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public function __construct(ServerInterface $server, $connectionLimit, $pauseOnL
*
* @return ConnectionInterface[]
*/
public function getConnections()
public function getConnections(): array
{
return $this->connections;
}

public function getAddress()
public function getAddress(): ?string
{
return $this->server->getAddress();
}

public function pause()
public function pause(): void
{
if (!$this->manuPaused) {
$this->manuPaused = true;
Expand All @@ -134,7 +134,7 @@ public function pause()
}
}

public function resume()
public function resume(): void
{
if ($this->manuPaused) {
$this->manuPaused = false;
Expand All @@ -145,13 +145,13 @@ public function resume()
}
}

public function close()
public function close(): void
{
$this->server->close();
}

/** @internal */
public function handleConnection(ConnectionInterface $connection)
public function handleConnection(ConnectionInterface $connection): void
{
// close connection if limit exceeded
if ($this->limit !== null && \count($this->connections) >= $this->limit) {
Expand All @@ -178,7 +178,7 @@ public function handleConnection(ConnectionInterface $connection)
}

/** @internal */
public function handleDisconnection(ConnectionInterface $connection)
public function handleDisconnection(ConnectionInterface $connection): void
{
unset($this->connections[\array_search($connection, $this->connections)]);

Expand All @@ -193,7 +193,7 @@ public function handleDisconnection(ConnectionInterface $connection)
}

/** @internal */
public function handleError(\Exception $error)
public function handleError(\Exception $error): void
{
$this->emit('error', [$error]);
}
Expand Down
Loading
Loading