aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-08 12:07:42 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-08 12:07:42 +0100
commit3d6ca0e2b55a6c6a04f483d9d115d6b44c906244 (patch)
treef9515e1088f6a96aa3416ee8234d69b484be3e54
parentdfd3cbd4d8356e44f624988c38666e09b56a3cee (diff)
downloadSocket-3d6ca0e2b55a6c6a04f483d9d115d6b44c906244.zip
Socket-3d6ca0e2b55a6c6a04f483d9d115d6b44c906244.tar.gz
Socket-3d6ca0e2b55a6c6a04f483d9d115d6b44c906244.tar.bz2
chore(php) Update to PHP 7.
-rw-r--r--Source/Client.php111
-rw-r--r--Source/Connection/Connection.php345
-rw-r--r--Source/Connection/Group.php60
-rw-r--r--Source/Connection/Handler.php84
-rw-r--r--Source/Exception/BrokenPipe.php5
-rw-r--r--Source/Exception/Exception.php7
-rw-r--r--Source/Node.php40
-rw-r--r--Source/Server.php127
-rw-r--r--Source/Socket.php94
-rw-r--r--Source/Transport.php30
-rw-r--r--Test/Unit/Client.php47
-rw-r--r--Test/Unit/Connection/Connection.php127
-rw-r--r--Test/Unit/Connection/Group.php51
-rw-r--r--Test/Unit/Connection/Handler.php71
-rw-r--r--Test/Unit/Exception/BrokenPipe.php5
-rw-r--r--Test/Unit/Exception/Exception.php5
-rw-r--r--Test/Unit/Node.php9
-rw-r--r--Test/Unit/Server.php69
-rw-r--r--Test/Unit/Socket.php23
-rw-r--r--Test/Unit/Transport.php46
20 files changed, 432 insertions, 924 deletions
diff --git a/Source/Client.php b/Source/Client.php
index 009c903..0484127 100644
--- a/Source/Client.php
+++ b/Source/Client.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,93 +45,66 @@ use Hoa\Stream;
* Class \Hoa\Socket\Client.
*
* Established a client connection.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Client extends Connection
{
/**
* Open client socket asynchronously.
- *
- * @const int
*/
- const ASYNCHRONOUS = STREAM_CLIENT_ASYNC_CONNECT;
+ public const ASYNCHRONOUS = STREAM_CLIENT_ASYNC_CONNECT;
/**
* Open client socket connection.
- *
- * @const int
*/
- const CONNECT = STREAM_CLIENT_CONNECT;
+ public const CONNECT = STREAM_CLIENT_CONNECT;
/**
* Client socket should remain persistent between page loads.
- *
- * @const int
*/
- const PERSISTENT = STREAM_CLIENT_PERSISTENT;
+ public const PERSISTENT = STREAM_CLIENT_PERSISTENT;
/**
* Encryption: SSLv2.
- *
- * @const int
*/
- const ENCRYPTION_SSLv2 = STREAM_CRYPTO_METHOD_SSLv2_CLIENT;
+ public const ENCRYPTION_SSLv2 = STREAM_CRYPTO_METHOD_SSLv2_CLIENT;
/**
* Encryption: SSLv3.
- *
- * @const int
*/
- const ENCRYPTION_SSLv3 = STREAM_CRYPTO_METHOD_SSLv3_CLIENT;
+ public const ENCRYPTION_SSLv3 = STREAM_CRYPTO_METHOD_SSLv3_CLIENT;
/**
* Encryption: SSLv2.3.
- *
- * @const int
*/
- const ENCRYPTION_SSLv23 = STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
+ public const ENCRYPTION_SSLv23 = STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
/**
* Encryption: TLS.
- *
- * @const int
*/
- const ENCRYPTION_TLS = STREAM_CRYPTO_METHOD_TLS_CLIENT;
+ public const ENCRYPTION_TLS = STREAM_CRYPTO_METHOD_TLS_CLIENT;
/**
* Encryption: TLSv1.0.
- *
- * @const int
*/
- const ENCRYPTION_TLSv1_0 = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT;
+ public const ENCRYPTION_TLSv1_0 = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT;
/**
* Encryption: TLSv1.1.
- *
- * @const int
*/
- const ENCRYPTION_TLSv1_1 = STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
+ public const ENCRYPTION_TLSv1_1 = STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
/**
* Encryption: TLSv1.2.
- *
- * @const int
*/
- const ENCRYPTION_TLSv1_2 = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
+ public const ENCRYPTION_TLSv1_2 = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
/**
* Encryption: ANY
- *
- * @const int
*/
- const ENCRYPTION_ANY = STREAM_CRYPTO_METHOD_ANY_CLIENT;
+ public const ENCRYPTION_ANY = STREAM_CRYPTO_METHOD_ANY_CLIENT;
/**
* Stack of connections.
- *
- * @var array
*/
protected $_stack = [];
@@ -137,18 +112,12 @@ class Client extends Connection
/**
* Start a connection.
- *
- * @param string $socket Socket URI.
- * @param int $timeout Timeout.
- * @param int $flag Flag, see the child::* constants.
- * @param string $context Context ID (please, see the
- * \Hoa\Stream\Context class).
*/
public function __construct(
- $socket,
- $timeout = 30,
- $flag = self::CONNECT,
- $context = null
+ string $socket,
+ int $timeout = 30,
+ int $flag = self::CONNECT,
+ string $context = null
) {
parent::__construct($socket, $timeout, self::CONNECT | $flag, $context);
@@ -157,13 +126,8 @@ class Client extends Connection
/**
* Open the stream and return the associated resource.
- *
- * @param string $streamName Socket URI.
- * @param \Hoa\Stream\Context $context Context.
- * @return resource
- * @throws \Hoa\Socket\Exception
*/
- protected function &_open($streamName, Stream\Context $context = null)
+ protected function &_open(string $streamName, Stream\Context $context = null)
{
if (null === $context) {
$connection = @stream_socket_client(
@@ -210,10 +174,8 @@ class Client extends Connection
/**
* Close the current stream.
- *
- * @return bool
*/
- protected function _close()
+ protected function _close(): bool
{
if (true === $this->isPersistent()) {
return false;
@@ -224,10 +186,8 @@ class Client extends Connection
/**
* Select connections.
- *
- * @return \Hoa\Socket\Client
*/
- public function select()
+ public function select(): self
{
$read = $this->getStack();
$write = null;
@@ -244,12 +204,8 @@ class Client extends Connection
/**
* Consider another client when selecting connection.
- *
- * @param \Hoa\Socket\Connection $other Other client.
- * @return \Hoa\Socket\Client
- * @throws \Hoa\Socket\Exception
*/
- public function consider(Connection $other)
+ public function consider(Connection $other): self
{
if (!($other instanceof self)) {
throw new Exception(
@@ -272,21 +228,16 @@ class Client extends Connection
/**
* Check if the current node belongs to a specific server.
- *
- * @param \Hoa\Socket\Connection $server Server.
- * @return bool
*/
- public function is(Connection $server)
+ public function is(Connection $server): bool
{
return $this->getStream() === $server->getStream();
}
/**
* Set and get the current selected connection.
- *
- * @return \Hoa\Socket\Node
*/
- public function current()
+ public function current(): Node
{
$current = parent::_current();
@@ -295,40 +246,32 @@ class Client extends Connection
/**
* Check if the connection is connected or not.
- *
- * @return bool
*/
- public function isConnected()
+ public function isConnected(): bool
{
return (bool) ($this->getFlag() & self::CONNECT);
}
/**
* Check if the connection is asynchronous or not.
- *
- * @return bool
*/
- public function isAsynchronous()
+ public function isAsynchronous(): bool
{
return (bool) ($this->getFlag() & self::ASYNCHRONOUS);
}
/**
* Check if the connection is persistent or not.
- *
- * @return bool
*/
- public function isPersistent()
+ public function isPersistent(): bool
{
return (bool) ($this->getFlag() & self::PERSISTENT);
}
/**
* Return internal node stack.
- *
- * @return array
*/
- protected function getStack()
+ protected function getStack(): array
{
return $this->_stack;
}
diff --git a/Source/Connection/Connection.php b/Source/Connection/Connection.php
index fca7e6a..c73d0b7 100644
--- a/Source/Connection/Connection.php
+++ b/Source/Connection/Connection.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,119 +46,81 @@ use Hoa\Stream;
* Class \Hoa\Socket\Connection.
*
* Abstract connection, useful for client and server.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
-abstract class Connection
- extends Stream
- implements Stream\IStream\In,
- Stream\IStream\Out,
- Stream\IStream\Pathable,
- \Iterator
+abstract class Connection extends Stream implements Stream\IStream\In, Stream\IStream\Out, Stream\IStream\Pathable, \Iterator
{
/**
* Read data out-of-band.
- *
- * @const int
*/
- const READ_OUT_OF_BAND = STREAM_OOB;
+ public const READ_OUT_OF_BAND = STREAM_OOB;
/**
* Read data but do not consume them.
- *
- * @const int
*/
- const READ_PEEK = STREAM_PEEK;
+ public const READ_PEEK = STREAM_PEEK;
/**
* Socket.
- *
- * @var \Hoa\Socket
*/
protected $_socket = null;
/**
* Timeout.
- *
- * @var int
*/
protected $_timeout = 30;
/**
* Flag.
- *
- * @var int
*/
protected $_flag = 0;
/**
* Context ID.
- *
- * @var string
*/
protected $_context = null;
/**
* Node name.
- *
- * @var string
*/
- protected $_nodeName = 'Hoa\Socket\Node';
+ protected $_nodeName = Socket\Node::class;
/**
* Current node.
- *
- * @var \Hoa\Socket\Node
*/
protected $_node = null;
/**
* List of nodes (connections) when selecting.
- *
- * @var array
*/
protected $_nodes = [];
/**
* Whether the stream is quiet.
- *
- * @var bool
*/
protected $_quiet = false;
/**
* Whether the stream is mute.
- *
- * @var bool
*/
protected $_mute = false;
/**
* Whether the stream is disconnected.
- *
- * @var bool
*/
protected $_disconnect = true;
/**
* Whether we should consider remote address or not.
- *
- * @var bool
*/
protected $_remote = false;
/**
* Remote address.
- *
- * @var string
*/
protected $_remoteAddress = null;
/**
* Temporize selected connections when selecting.
- *
- * @var array
*/
protected $_iterator = [];
@@ -164,14 +128,8 @@ abstract class Connection
/**
* Start a connection.
- *
- * @param string $socket Socket URI.
- * @param int $timeout Timeout.
- * @param int $flag Flag, see the child::* constants.
- * @param string $context Context ID (please, see the
- * \Hoa\Stream\Context class).
*/
- public function __construct($socket, $timeout, $flag, $context = null)
+ public function __construct(string $socket, int $timeout, int $flag, string $context = null)
{
// Children could setSocket() before __construct.
if (null !== $socket) {
@@ -187,10 +145,8 @@ abstract class Connection
/**
* Connect.
- *
- * @return \Hoa\Socket\Connection
*/
- public function connect()
+ public function connect(): self
{
parent::__construct(
$this->getSocket()->__toString(),
@@ -203,41 +159,29 @@ abstract class Connection
/**
* Select connections.
- *
- * @return \Hoa\Socket\Connection
*/
- abstract public function select();
+ abstract public function select(): self;
/**
* Consider another connection when selecting connection.
- *
- * @param \Hoa\Socket\Connection $other Other connection.
- * @return \Hoa\Socket\Connection
*/
- abstract public function consider(Connection $other);
+ abstract public function consider(self $other): self;
/**
* Check if the current node belongs to a specific server.
- *
- * @param \Hoa\Socket\Connection $connection Connection.
- * @return bool
*/
- abstract public function is(Connection $connection);
+ abstract public function is(self $connection): bool;
/**
* Get iterator values.
- *
- * @return array
*/
- protected function &getIteratorValues()
+ protected function &getIteratorValues(): array
{
return $this->_iterator;
}
/**
* Set the current selected connection.
- *
- * @return resource
*/
protected function _current()
{
@@ -249,17 +193,13 @@ abstract class Connection
/**
* Set and get the current selected connection.
- *
- * @return \Hoa\Socket\Node
*/
//abstract public function current();
/**
* Get the current selected connection index.
- *
- * @return int
*/
- public function key()
+ public function key(): int
{
return key($this->getIteratorValues());
}
@@ -267,31 +207,25 @@ abstract class Connection
/**
* Advance the internal pointer of the connection iterator and return the
* current selected connection.
- *
- * @return mixed
*/
- public function next()
+ public function next(): void
{
- return next($this->getIteratorValues());
+ next($this->getIteratorValues());
}
/**
* Rewind the internal iterator pointer and the first connection.
- *
- * @return mixed
*/
- public function rewind()
+ public function rewind(): void
{
- return reset($this->getIteratorValues());
+ reset($this->getIteratorValues());
}
/**
* Check if there is a current connection after calls to the rewind() or the
* next() methods.
- *
- * @return bool
*/
- public function valid()
+ public function valid(): bool
{
$iteratorValues = &$this->getIteratorValues();
@@ -317,10 +251,8 @@ abstract class Connection
/**
* Disable further receptions.
- *
- * @return bool
*/
- public function quiet()
+ public function quiet(): bool
{
return $this->_quiet =
stream_socket_shutdown($this->getStream(), STREAM_SHUT_RD);
@@ -328,10 +260,8 @@ abstract class Connection
/**
* Disable further transmissions.
- *
- * @return bool
*/
- public function mute()
+ public function mute(): bool
{
return $this->_mute =
stream_socket_shutdown($this->getStream(), STREAM_SHUT_WR);
@@ -339,10 +269,8 @@ abstract class Connection
/**
* Disable further receptions and transmissions, i.e. disconnect.
- *
- * @return bool
*/
- public function quietAndMute()
+ public function quietAndMute(): bool
{
return $this->_disconnect =
stream_socket_shutdown($this->getStream(), STREAM_SHUT_RDWR);
@@ -350,24 +278,16 @@ abstract class Connection
/**
* Disconnect.
- *
- * @return void
*/
- public function disconnect()
+ public function disconnect(): void
{
$this->_disconnect = $this->close();
-
- return;
}
/**
* Set socket.
- *
- * @param string $socketUri Socket URI.
- * @return \Hoa\Socket
- * @throws \Hoa\Socket\Exception
*/
- protected function setSocket($socketUri)
+ protected function setSocket(string $socketUri): ?Socket
{
if (false === $pos = strpos($socketUri, '://')) {
$socket = new Socket($socketUri);
@@ -394,11 +314,8 @@ abstract class Connection
/**
* Set timeout.
- *
- * @param int $timeout Timeout.
- * @return int
*/
- protected function setTimeout($timeout)
+ protected function setTimeout(int $timeout): int
{
$old = $this->_timeout;
$this->_timeout = $timeout;
@@ -408,11 +325,8 @@ abstract class Connection
/**
* Set flag.
- *
- * @param int $flag Flag.
- * @return int
*/
- protected function setFlag($flag)
+ protected function setFlag(int $flag): int
{
$old = $this->_flag;
$this->_flag = $flag;
@@ -422,11 +336,8 @@ abstract class Connection
/**
* Set context.
- *
- * @param string $context Context ID.
- * @return string
*/
- protected function setContext($context)
+ protected function setContext(string $context): ?string
{
$old = $this->_context;
$this->_context = $context;
@@ -436,11 +347,8 @@ abstract class Connection
/**
* Set node name.
- *
- * @param string $node Node name.
- * @return string
*/
- public function setNodeName($node)
+ public function setNodeName(string $node): string
{
$old = $this->_nodeName;
$this->_nodeName = $node;
@@ -450,11 +358,8 @@ abstract class Connection
/**
* Whether we should consider remote address or not.
- *
- * @param bool $consider Should we consider remote address or not.
- * @return bool
*/
- public function considerRemoteAddress($consider)
+ public function considerRemoteAddress(bool $consider): bool
{
$old = $this->_remote;
$this->_remote = $consider;
@@ -464,19 +369,12 @@ abstract class Connection
/**
* Enable or disable encryption.
- *
- * @param bool $enable Whether enable encryption.
- * @param int $type Type of encryption (please, see
- * children ENCRYPTION_* constants).
- * @param resource $sessionStream Seed the stream with settings from
- * this session stream.
- * @return bool
*/
public function enableEncryption(
- $enable,
- $type = null,
+ bool $enable,
+ int $type = null,
$sessionStream = null
- ) {
+ ): bool {
$currentNode = $this->getCurrentNode();
if (null === $currentNode) {
@@ -508,10 +406,8 @@ abstract class Connection
/**
* Check if the connection is encrypted or not.
- *
- * @return mixed
*/
- public function isEncrypted()
+ public function isEncrypted(): bool
{
$currentNode = $this->getCurrentNode();
@@ -524,131 +420,104 @@ abstract class Connection
/**
* Get socket.
- *
- * @return \Hoa\Socket
*/
- public function getSocket()
+ public function getSocket(): ?Socket
{
return $this->_socket;
}
/**
* Get timeout.
- *
- * @return int
*/
- public function getTimeout()
+ public function getTimeout(): int
{
return $this->_timeout;
}
/**
* Get flag.
- *
- * @return int
*/
- public function getFlag()
+ public function getFlag(): int
{
return $this->_flag;
}
/**
* Get context.
- *
- * @return string
*/
- public function getContext()
+ public function getContext(): ?string
{
return $this->_context;
}
/**
* Get node name.
- *
- * @return string
*/
- public function getNodeName()
+ public function getNodeName(): string
{
return $this->_nodeName;
}
/**
* Get node ID.
- *
- * @param resource $resource Resource.
- * @return string
*/
- protected function getNodeId($resource)
+ protected function getNodeId($resource): string
{
return md5((int) $resource);
}
/**
* Get current node.
- *
- * @return \Hoa\Socket\Node
*/
- public function getCurrentNode()
+ public function getCurrentNode(): ?Socket\Node
{
return $this->_node;
}
/**
* Get nodes list.
- *
- * @return array
*/
- public function getNodes()
+ public function getNodes(): array
{
return $this->_nodes;
}
/**
* Check if the stream is quiet.
- *
- * @return bool
*/
- public function isQuiet()
+ public function isQuiet(): bool
{
return $this->_quiet;
}
/**
* Check if the stream is mute.
- *
- * @return bool
*/
- public function isMute()
+ public function isMute(): bool
{
return $this->_mute;
}
/**
* Check if the stream is disconnected.
- *
- * @return bool
*/
- public function isDisconnected()
+ public function isDisconnected(): bool
{
return false !== $this->_disconnect;
}
/**
* Check if we should consider remote address or not.
- *
- * @return bool
*/
- public function isRemoteAddressConsidered()
+ public function isRemoteAddressConsidered(): bool
{
return $this->_remote;
}
/**
* Get remote address.
- *
- * @return string
*/
- public function getRemoteAddress()
+ public function getRemoteAddress(): string
{
return $this->_remoteAddress;
}
@@ -657,13 +526,8 @@ abstract class Connection
* Read n characters.
* Warning: if this method returns false, it means that the buffer is empty.
* You should use the Hoa\Stream::setStreamBlocking(true) method.
- *
- * @param int $length Length.
- * @param int $flags Flags.
- * @return string
- * @throws \Hoa\Socket\Exception
*/
- public function read($length, $flags = 0)
+ public function read(int $length, int $flags = 0): string
{
if (null === $this->getStream()) {
throw new Socket\Exception(
@@ -702,11 +566,8 @@ abstract class Connection
/**
* Alias of $this->read().
- *
- * @param int $length Length.
- * @return string
*/
- public function readString($length)
+ public function readString(int $length): string
{
return $this->read($length);
}
@@ -714,42 +575,32 @@ abstract class Connection
/**
* Read a character.
* It is equivalent to $this->read(1).
- *
- * @return string
*/
- public function readCharacter()
+ public function readCharacter(): string
{
return $this->read(1);
}
/**
* Read a boolean.
- *
- * @return bool
*/
- public function readBoolean()
+ public function readBoolean(): bool
{
return (bool) $this->read(1);
}
/**
* Read an integer.
- *
- * @param int $length Length.
- * @return int
*/
- public function readInteger($length = 1)
+ public function readInteger(int $length = 1): int
{
return (int) $this->read($length);
}
/**
* Read a float.
- *
- * @param int $length Length.
- * @return float
*/
- public function readFloat($length = 1)
+ public function readFloat(int $length = 1): float
{
return (float) $this->read($length);
}
@@ -757,21 +608,16 @@ abstract class Connection
/**
* Read an array.
* Alias of the $this->scanf() method.
- *
- * @param string $format Format (see printf's formats).
- * @return array
*/
- public function readArray($format = null)
+ public function readArray(string $format = null): array
{
return $this->scanf($format);
}
/**
* Read a line.
- *
- * @return string
*/
- public function readLine()
+ public function readLine(): string
{
if (true === $this->isEncrypted()) {
return rtrim(fgets($this->getStream(), 1 << 15), "\n");
@@ -782,36 +628,24 @@ abstract class Connection
/**
* Read all, i.e. read as much as possible.
- *
- * @param int $offset Offset (not used).
- * @return string
*/
- public function readAll($offset = -1)
+ public function readAll(int $offset = -1): string
{
return stream_get_contents($this->getStream());
}
/**
* Parse input from a stream according to a format.
- *
- * @param string $format Format (see printf's formats).
- * @return array
*/
- public function scanf($format)
+ public function scanf(string $format): array
{
return sscanf($this->readAll(), $format);
}
/**
* Write n characters.
- *
- * @param string $string String.
- * @param int $length Length.
- * @return mixed
- * @throws \Hoa\Socket\Exception
- * @throws \Hoa\Socket\Exception\BrokenPipe
*/
- public function write($string, $length)
+ public function write(string $string, int $length)
{
if (null === $this->getStream()) {
throw new Socket\Exception(
@@ -837,7 +671,7 @@ abstract class Connection
$out = fwrite($this->getStream(), $string, $length);
} else {
if (false === $this->isRemoteAddressConsidered() ||
- null === $remote = $this->getRemoteAddress()) {
+ null === $remote = $this->getRemoteAddress()) {
$out = @stream_socket_sendto($this->getStream(), $string);
} else {
$out = @stream_socket_sendto(
@@ -861,11 +695,8 @@ abstract class Connection
/**
* Write a string.
- *
- * @param string $string String.
- * @return mixed
*/
- public function writeString($string)
+ public function writeString(string $string)
{
$string = (string) $string;
@@ -874,33 +705,24 @@ abstract class Connection
/**
* Write a character.
- *
- * @param string $char Character.
- * @return mixed
*/
- public function writeCharacter($char)
+ public function writeCharacter(string $char)
{
return $this->write((string) $char[0], 1);
}
/**
* Write a boolean.
- *
- * @param bool $boolean Boolean.
- * @return mixed
*/
- public function writeBoolean($boolean)
+ public function writeBoolean(bool $boolean)
{
return $this->write((string) (bool) $boolean, 1);
}
/**
* Write an integer.
- *
- * @param int $integer Integer.
- * @return mixed
*/
- public function writeInteger($integer)
+ public function writeInteger(int $integer)
{
$integer = (string) (int) $integer;
@@ -909,24 +731,18 @@ abstract class Connection
/**
* Write a float.
- *
- * @param float $float Float.
- * @return mixed
*/
- public function writeFloat($float)
- {
- $float = (string) (float) $float;
+ public function writeFloat(float $float)
+ {
+ $float = (string) (float) $float;
- return $this->write($float, strlen($float));
- }
+ return $this->write($float, strlen($float));
+ }
/**
* Write a line.
- *
- * @param string $line Line.
- * @return mixed
*/
- public function writeLine($line)
+ public function writeLine(string $line)
{
if (false === $n = strpos($line, "\n")) {
return $this->write($line . "\n", strlen($line) + 1);
@@ -939,9 +755,6 @@ abstract class Connection
/**
* Write an array.
- *
- * @param array $array Array.
- * @return mixed
*/
public function writeArray(array $array)
{
@@ -952,52 +765,40 @@ abstract class Connection
/**
* Write all, i.e. as much as possible.
- *
- * @param string $string String.
- * @return mixed
*/
- public function writeAll($string)
+ public function writeAll(string $string)
{
return $this->write($string, strlen($string));
}
/**
* Truncate a file to a given length.
- *
- * @param int $size Size.
- * @return bool
*/
- public function truncate($size)
+ public function truncate(int $size): bool
{
return false;
}
/**
* Test for end-of-file.
- *
- * @return bool
*/
- public function eof()
+ public function eof(): bool
{
return feof($this->getStream());
}
/**
* Get filename component of path.
- *
- * @return string
*/
- public function getBasename()
+ public function getBasename(): string
{
return basename($this->getSocket()->__toString());
}
/**
* Get directory name component of path.
- *
- * @return string
*/
- public function getDirname()
+ public function getDirname(): string
{
return dirname($this->getSocket()->__toString());
}
@@ -1006,4 +807,4 @@ abstract class Connection
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Socket\Connection\Connection');
+Consistency::flexEntity(Connection::class);
diff --git a/Source/Connection/Group.php b/Source/Connection/Group.php
index ccd259a..fb505c4 100644
--- a/Source/Connection/Group.php
+++ b/Source/Connection/Group.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,16 +45,11 @@ use Hoa\Socket;
*
* Represent a group of connection handlers.
* Add semantics around Hoa\Socket\Connection\Handler.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Group implements \ArrayAccess, \IteratorAggregate, \Countable
{
/**
* All connections.
- *
- * @var array
*/
protected $_connections = [];
@@ -60,22 +57,16 @@ class Group implements \ArrayAccess, \IteratorAggregate, \Countable
/**
* Check if a connection offset exists.
- *
- * @param mixed $offset Offset.
- * @return bool
*/
- public function offsetExists($offset)
+ public function offsetExists($offset): bool
{
return true === array_key_exists($offset, $this->_connections);
}
/**
* Get a specific connection.
- *
- * @param mixed $offset Offset.
- * @return \Hoa\Socket\Connection\Handler
*/
- public function offsetGet($offset)
+ public function offsetGet($offset): ?Handler
{
if (false === $this->offsetExists($offset)) {
return null;
@@ -86,14 +77,8 @@ class Group implements \ArrayAccess, \IteratorAggregate, \Countable
/**
* Add a connection.
- *
- * @param mixed $offset Offset.
- * @param \Hoa\Socket\Connection\Handler $connection Connection
- * (handler).
- * @return void
- * @throws \Hoa\Socket\Exception
*/
- public function offsetSet($offset, $connection)
+ public function offsetSet($offset, Handler $connection): void
{
if (!($connection instanceof Handler)) {
throw new Socket\Exception(
@@ -112,56 +97,40 @@ class Group implements \ArrayAccess, \IteratorAggregate, \Countable
if (1 < count($this)) {
$this->getFirstConnection()->merge($connection);
}
-
- return;
}
/**
* Nothing (not allowed).
- *
- * @param mixed $offset Offset.
- * @return void
- * @throws \Hoa\Socket\Exception
*/
- public function offsetUnset($offset)
+ public function offsetUnset($offset): void
{
throw new Socket\Exception(
'This operation is not allowed: you cannot unset a connection ' .
'from a group.',
1
);
-
- return;
}
/**
* Get iterator of all declared connections.
- *
- * @return \ArrayIterator
*/
- public function getIterator()
+ public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->_connections);
}
/**
* Count number of declared connections.
- *
- * @return int
*/
- public function count()
+ public function count(): int
{
return count($this->_connections);
}
/**
* Semantics alias of $this->offsetSet(null, $connection).
- *
- * @param \Hoa\Socket\Connection\Handler $connection Connection
- * (handler).
- * @return \Hoa\Socket\Connection\Group
*/
- public function merge(Handler $connection)
+ public function merge(Handler $connection): self
{
$this[] = $connection;
@@ -170,11 +139,8 @@ class Group implements \ArrayAccess, \IteratorAggregate, \Countable
/**
* Run the group of connections.
- *
- * @return void
- * @throws \Hoa\Socket\Exception
*/
- public function run()
+ public function run(): void
{
if (0 === count($this)) {
throw new Socket\Exception(
@@ -183,16 +149,14 @@ class Group implements \ArrayAccess, \IteratorAggregate, \Countable
);
}
- return $this->getFirstConnection()->run();
+ $this->getFirstConnection()->run();
}
/**
* Get the first declared connection (where other connections have been
* merged).
- *
- * @return \Hoa\Socket\Connection\Handler
*/
- public function getFirstConnection()
+ public function getFirstConnection(): Handler
{
return $this[key($this->_connections)];
}
diff --git a/Source/Connection/Handler.php b/Source/Connection/Handler.php
index a25cab0..9e56120 100644
--- a/Source/Connection/Handler.php
+++ b/Source/Connection/Handler.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,30 +47,21 @@ use Hoa\Socket;
* This class provides a connection handler: a complete connection skeleton. We
* are able to run() a connection (client or server), to merge() with other ones
* and to send messages in different ways (A -> A, A -> B, A -> *\A etc.).
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
abstract class Handler
{
/**
* Original connection.
- *
- * @var \Hoa\Socket\Connection
*/
protected $_originalConnection = null;
/**
* Current connection.
- *
- * @var \Hoa\Socket\Connection
*/
protected $_connection = null;
/**
* All other connections that have been merged.
- *
- * @var array
*/
protected $_connections = [];
@@ -76,8 +69,6 @@ abstract class Handler
/**
* Constructor. Must be called.
- *
- * @param \Hoa\Socket\Connection $connection Connection.
*/
public function __construct(Connection $connection)
{
@@ -89,11 +80,8 @@ abstract class Handler
/**
* Set current connection.
- *
- * @param \Hoa\Socket\Connection $connection Connection.
- * @return \Hoa\Socket\Connection
*/
- protected function setConnection(Connection $connection)
+ protected function setConnection(Connection $connection): ?Connection
{
$old = $this->_connection;
$this->_connection = $connection;
@@ -103,30 +91,24 @@ abstract class Handler
/**
* Get original connection.
- *
- * @return \Hoa\Socket\Connection
*/
- protected function getOriginalConnection()
+ protected function getOriginalConnection(): ?Connection
{
return $this->_originalConnection;
}
/**
* Get current connection.
- *
- * @return \Hoa\Socket\Connection
*/
- public function getConnection()
+ public function getConnection(): ?Connection
{
return $this->_connection;
}
/**
* Get all merged connections.
- *
- * @return array
*/
- public function getMergedConnections()
+ public function getMergedConnections(): array
{
return $this->_connections;
}
@@ -139,18 +121,13 @@ abstract class Handler
* // body
*
* The body is given by this method.
- *
- * @param \Hoa\Socket\Node $node Node.
- * @return void
*/
- abstract protected function _run(Socket\Node $node);
+ abstract protected function _run(Socket\Node $node): void;
/**
* Run the connection.
- *
- * @return void
*/
- public function run()
+ public function run(): void
{
$connection = $this->getConnection();
@@ -197,8 +174,6 @@ abstract class Handler
} while (SUCCEED);
$connection->disconnect();
-
- return;
}
/**
@@ -207,11 +182,8 @@ abstract class Handler
* Hoa\Socket\Connection::consider() and Hoa\Socket\Connection::is() methods
* are helpful but this whole class eases the merge of “high-level”
* connections.
- *
- * @param \Hoa\Socket\Connection\Handler $other Connection to merge.
- * @return \Hoa\Socket\Connection\Handler
*/
- public function merge(self $other)
+ public function merge(self $other): self
{
$thisConnection = $this->getConnection();
$otherConnection = $other->getConnection();
@@ -231,22 +203,13 @@ abstract class Handler
* The sending dedicated part of the self::send() method.
* If the send() method is overrided with more arguments, this method could
* return a function: it works like a currying.
- *
- * @param string $message Message.
- * @param \Hoa\Socket\Node $node Node (if null, current node).
- * @return void
*/
- abstract protected function _send($message, Socket\Node $node);
+ abstract protected function _send(string $message, Socket\Node $node);
/**
* Send a message to a specific node.
- *
- * @param string $message Message.
- * @param \Hoa\Socket\Node $node Node (if null, current node).
- * current node).
- * @return mixed
*/
- public function send($message, Socket\Node $node = null)
+ public function send(string $message, Socket\Node $node = null)
{
if (null === $node) {
$node = $this->getConnection()->getCurrentNode();
@@ -269,9 +232,9 @@ abstract class Handler
if ($send instanceof \Closure) {
$self = $this;
- return function () use (&$send, &$old, &$self) {
+ return function (...$arguments) use (&$send, &$old, &$self) {
try {
- $out = call_user_func_array($send, func_get_args());
+ $out = $send(...$arguments);
} finally {
$self->getConnection()->_setStream($old);
}
@@ -288,12 +251,8 @@ abstract class Handler
/**
* Broadcast a message, i.e. send the message to all other nodes except the
* current one.
- *
- * @param string $message Message.
- * @param … … …
- * @return void
*/
- public function broadcast($message)
+ public function broadcast(string $message)
{
$currentNode = $this->getConnection()->getCurrentNode();
$arguments = func_get_args();
@@ -304,26 +263,19 @@ abstract class Handler
}
);
- return call_user_func_array([$this, 'broadcastIf'], $arguments);
+ return $this->broadcastIf(...$arguments);
}
/**
* Broadcast a message to a subset of nodes that fulfill a predicate.
- *
- * @param \Closure $predicate Predicate. Take a node in argument.
- * @param string $message Message.
- * @param … … …
- * @return void
- * @throws \Hoa\Exception\Group
*/
- public function broadcastIf(\Closure $predicate, $message)
+ public function broadcastIf(\Closure $predicate, string $message): void
{
$connection = $this->getConnection();
$currentSocket = $this->getOriginalConnection()->getSocket();
$arguments = array_slice(func_get_args(), 2);
array_unshift($arguments, $message, null);
- $callable = [$this, 'send'];
$exceptions = new HoaException\Group(
'Message cannot be sent to some nodes.'
);
@@ -333,7 +285,7 @@ abstract class Handler
$node->getConnection()->getSocket() === $currentSocket) {
$arguments[1] = $node;
try {
- call_user_func_array($callable, $arguments);
+ $this->send(...$arguments);
} catch (Socket\Exception $e) {
$exceptions[$node->getId()] = $e;
}
@@ -343,7 +295,5 @@ abstract class Handler
if (0 < $exceptions->count()) {
throw $exceptions;
}
-
- return;
}
}
diff --git a/Source/Exception/BrokenPipe.php b/Source/Exception/BrokenPipe.php
index d3c789a..5072e29 100644
--- a/Source/Exception/BrokenPipe.php
+++ b/Source/Exception/BrokenPipe.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,9 +42,6 @@ namespace Hoa\Socket\Exception;
* Class \Hoa\Socket\Exception\BrokenPipe.
*
* Extending the \Hoa\Socket\Exception\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class BrokenPipe extends Exception
{
diff --git a/Source/Exception/Exception.php b/Source/Exception/Exception.php
index 428bfdc..e1d5ea3 100644
--- a/Source/Exception/Exception.php
+++ b/Source/Exception/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,9 +45,6 @@ use Hoa\Exception as HoaException;
* Class \Hoa\Socket\Exception\Exception.
*
* Extending the \Hoa\Exception\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Exception extends HoaException
{
@@ -54,4 +53,4 @@ class Exception extends HoaException
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Socket\Exception\Exception');
+Consistency::flexEntity(Exception::class);
diff --git a/Source/Node.php b/Source/Node.php
index f14eedc..8acdec0 100644
--- a/Source/Node.php
+++ b/Source/Node.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,37 +42,26 @@ namespace Hoa\Socket;
* Class \Hoa\Socket\Node.
*
* Represent a generic node.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Node
{
/**
* Node's ID.
- *
- * @var string
*/
protected $_id = null;
/**
* Node's socket resource.
- *
- * @var resource
*/
private $_socket = null;
/**
* Get server.
- *
- * @var \Hoa\Socket\Connection
*/
private $_connection = null;
/**
* Encryption type.
- *
- * @var int
*/
protected $_encryptionType = null;
@@ -78,12 +69,8 @@ class Node
/**
* Constructor.
- *
- * @param string $id ID.
- * @param resource $socket Socket.
- * @param \Hoa\Socket\Connection $connection Connection.
*/
- public function __construct($id, $socket, Connection $connection)
+ public function __construct(string $id, $socket, Connection $connection)
{
$this->_id = $id;
$this->_socket = $socket;
@@ -94,18 +81,14 @@ class Node
/**
* Get node's ID.
- *
- * @return string
*/
- public function getId()
+ public function getId(): string
{
return $this->_id;
}
/**
* Get node's socket resource.
- *
- * @return resource
*/
public function getSocket()
{
@@ -114,23 +97,16 @@ class Node
/**
* Get connection.
- *
- * @return \Hoa\Socket\Connection
*/
- public function getConnection()
+ public function getConnection(): Connection
{
return $this->_connection;
}
/**
* Set encryption type.
- *
- * @param int $type Type of encryption (please, see ENCRYPTION_*
- * constants from Hoa\Socket\Client and
- * Hoa\Socket\Server).
- * @return int
*/
- public function setEncryptionType($type)
+ public function setEncryptionType(int $type): ?int
{
$old = $this->_encryptionType;
$this->_encryptionType = $type;
@@ -140,10 +116,8 @@ class Node
/**
* Get encryption type.
- *
- * @return int
*/
- public function getEncryptionType()
+ public function getEncryptionType(): ?int
{
return $this->_encryptionType;
}
diff --git a/Source/Server.php b/Source/Server.php
index 6d7ac86..e0b5a38 100644
--- a/Source/Server.php
+++ b/Source/Server.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,107 +45,76 @@ use Hoa\Stream;
* Class \Hoa\Socket\Server.
*
* Established a server connection.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Server extends Connection
{
/**
* Tell a stream to bind to the specified target.
- *
- * @const int
*/
- const BIND = STREAM_SERVER_BIND;
+ public const BIND = STREAM_SERVER_BIND;
/**
* Tell a stream to start listening on the socket.
- *
- * @const int
*/
- const LISTEN = STREAM_SERVER_LISTEN;
+ public const LISTEN = STREAM_SERVER_LISTEN;
/**
* Encryption: SSLv2.
- *
- * @const int
*/
- const ENCRYPTION_SSLv2 = STREAM_CRYPTO_METHOD_SSLv2_SERVER;
+ public const ENCRYPTION_SSLv2 = STREAM_CRYPTO_METHOD_SSLv2_SERVER;
/**
* Encryption: SSLv3.
- *
- * @const int
*/
- const ENCRYPTION_SSLv3 = STREAM_CRYPTO_METHOD_SSLv3_SERVER;
+ public const ENCRYPTION_SSLv3 = STREAM_CRYPTO_METHOD_SSLv3_SERVER;
/**
* Encryption: SSLv2.3.
- *
- * @const int
*/
- const ENCRYPTION_SSLv23 = STREAM_CRYPTO_METHOD_SSLv23_SERVER;
+ public const ENCRYPTION_SSLv23 = STREAM_CRYPTO_METHOD_SSLv23_SERVER;
/**
* Encryption: TLS.
- *
- * @const int
*/
- const ENCRYPTION_TLS = STREAM_CRYPTO_METHOD_TLS_SERVER;
+ public const ENCRYPTION_TLS = STREAM_CRYPTO_METHOD_TLS_SERVER;
/**
* Encryption: TLSv1.0.
- *
- * @const int
*/
- const ENCRYPTION_TLSv1_0 = STREAM_CRYPTO_METHOD_TLSv1_0_SERVER;
+ public const ENCRYPTION_TLSv1_0 = STREAM_CRYPTO_METHOD_TLSv1_0_SERVER;
/**
* Encryption: TLSv1.1.
- *
- * @const int
*/
- const ENCRYPTION_TLSv1_1 = STREAM_CRYPTO_METHOD_TLSv1_1_SERVER;
+ public const ENCRYPTION_TLSv1_1 = STREAM_CRYPTO_METHOD_TLSv1_1_SERVER;
/**
* Encryption: TLSv1.2.
- *
- * @const int
*/
- const ENCRYPTION_TLSv1_2 = STREAM_CRYPTO_METHOD_TLSv1_2_SERVER;
+ public const ENCRYPTION_TLSv1_2 = STREAM_CRYPTO_METHOD_TLSv1_2_SERVER;
/**
* Encryption: ANY
- *
- * @const int
*/
- const ENCRYPTION_ANY = STREAM_CRYPTO_METHOD_ANY_SERVER;
+ public const ENCRYPTION_ANY = STREAM_CRYPTO_METHOD_ANY_SERVER;
/**
* Master connection.
- *
- * @var resource
*/
protected $_master = null;
/**
* All considered server.
- *
- * @var array
*/
protected $_servers = [];
/**
* Masters connection.
- *
- * @var array
*/
protected $_masters = [];
/**
* Stack of connections.
- *
- * @var array
*/
protected $_stack = [];
@@ -151,19 +122,12 @@ class Server extends Connection
/**
* Start a connection.
- *
- * @param string $socket Socket URI.
- * @param int $timeout Timeout.
- * @param int $flag Flag, see the child::* constants.
- * @param string $context Context ID (please, see the
- * \Hoa\Stream\Context class).
- * @throws \Hoa\Socket\Exception
*/
public function __construct(
- $socket,
- $timeout = 30,
- $flag = -1,
- $context = null
+ string $socket,
+ int $timeout = 30,
+ int $flag = -1,
+ string $context = null
) {
$this->setSocket($socket);
$socket = $this->getSocket();
@@ -210,13 +174,8 @@ class Server extends Connection
/**
* Open the stream and return the associated resource.
- *
- * @param string $streamName Socket URI.
- * @param \Hoa\Stream\Context $context Context.
- * @return resource
- * @throws \Hoa\Socket\Exception
*/
- protected function &_open($streamName, Stream\Context $context = null)
+ protected function &_open(string $streamName, Stream\Context $context = null)
{
if (null === $context) {
$this->_master = @stream_socket_server(
@@ -253,10 +212,8 @@ class Server extends Connection
/**
* Close the current stream.
- *
- * @return bool
*/
- protected function _close()
+ protected function _close(): bool
{
$current = $this->getStream();
@@ -284,11 +241,8 @@ class Server extends Connection
/**
* Connect and accept the first connection.
- *
- * @return \Hoa\Socket\Server
- * @throws \Hoa\Socket\Exception
*/
- public function connect()
+ public function connect(): self
{
parent::connect();
@@ -308,21 +262,16 @@ class Server extends Connection
/**
* Connect but wait for select and accept new connections.
- *
- * @return \Hoa\Socket\Server
*/
- public function connectAndWait()
+ public function connectAndWait(): self
{
return parent::connect();
}
/**
* Select connections.
- *
- * @return \Hoa\Socket\Server
- * @throws \Hoa\Socket\Exception
*/
- public function select()
+ public function select(): self
{
$read = $this->getStack();
$write = null;
@@ -362,11 +311,8 @@ class Server extends Connection
/**
* Consider another server when selecting connection.
- *
- * @param \Hoa\Socket\Connection $other Other server.
- * @return \Hoa\Socket\Server
*/
- public function consider(Connection $other)
+ public function consider(Connection $other): self
{
if ($other instanceof Client) {
if (true === $other->isDisconnected()) {
@@ -392,21 +338,16 @@ class Server extends Connection
/**
* Check if the current node belongs to a specific server.
- *
- * @param \Hoa\Socket\Connection $server Server.
- * @return bool
*/
- public function is(Connection $server)
+ public function is(Connection $server): bool
{
return $this->getCurrentNode()->getConnection() === $server;
}
/**
* Set and get the current selected connection.
- *
- * @return \Hoa\Socket\Node
*/
- public function current()
+ public function current(): Node
{
$current = parent::_current();
$id = $this->getNodeId($current);
@@ -420,50 +361,40 @@ class Server extends Connection
/**
* Check if the server bind or not.
- *
- * @return bool
*/
- public function isBinding()
+ public function isBinding(): bool
{
return (bool) ($this->getFlag() & self::BIND);
}
/**
* Check if the server is listening or not.
- *
- * @return bool
*/
- public function isListening()
+ public function isListening(): bool
{
return (bool) ($this->getFlag() & self::LISTEN);
}
/**
* Return internal considered servers.
- *
- * @return array
*/
- protected function getServers()
+ protected function getServers(): array
{
return $this->_servers;
}
/**
* Return internal master connections.
- *
- * @return array
*/
- protected function getMasters()
+ protected function getMasters(): array
{
return $this->_masters;
}
/**
* Return internal node stack.
- *
- * @return array
*/
- protected function &getStack()
+ protected function &getStack(): array
{
return $this->_stack;
}
diff --git a/Source/Socket.php b/Source/Socket.php
index a4542ce..b71b4f3 100644
--- a/Source/Socket.php
+++ b/Source/Socket.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -42,82 +44,59 @@ use Hoa\Consistency;
* Class \Hoa\Socket.
*
* Socket analyzer.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Socket
{
/**
* Address type: IPv6.
- *
- * @const int
*/
- const ADDRESS_IPV6 = 0;
+ public const ADDRESS_IPV6 = 0;
/**
* Address type: IPv4.
- *
- * @const int
*/
- const ADDRESS_IPV4 = 1;
+ public const ADDRESS_IPV4 = 1;
/**
* Address type: domain.
- *
- * @const int
*/
- const ADDRESS_DOMAIN = 2;
+ public const ADDRESS_DOMAIN = 2;
/**
* Address type: path.
- *
- * @const int
*/
- const ADDRESS_PATH = 3;
+ public const ADDRESS_PATH = 3;
/**
* Address.
- *
- * @var string
*/
protected $_address = null;
/**
* Address type. Please, see the self::ADDRESS_* constants.
- *
- * @var int
*/
protected $_addressType = 0;
/**
* Port.
- *
- * @var int
*/
protected $_port = -1;
/**
* Transport.
- *
- * @var string
*/
protected $_transport = null;
/**
* Whether the socket is secured or not.
- *
- * @var bool
*/
protected $_secured = false;
/**
* Constructor.
- *
- * @param string $uri URI.
*/
- public function __construct($uri)
+ public function __construct(string $uri)
{
$this->setURI($uri);
@@ -126,12 +105,8 @@ class Socket
/**
* Set URI.
- *
- * @param string $uri URI.
- * @return string
- * @throws \Hoa\Socket\Exception
*/
- public function setURI($uri)
+ protected function setURI(string $uri): void
{
$m = preg_match(
'#(?<scheme>[^:]+)://' .
@@ -140,7 +115,8 @@ class Socket
'(?<domain>[^:]+)(?::(?<domain_port>\d+))?$|' .
'(?<ipv6>.+)$)#',
$uri,
- $matches);
+ $matches
+ );
if (0 === $m) {
throw new Exception(
@@ -198,18 +174,12 @@ class Socket
$uri
);
}
-
- return;
}
/**
* Set the port.
- *
- * @param int $port Port.
- * @return int
- * @throws \Hoa\Socket\Exception
*/
- protected function setPort($port)
+ protected function setPort(int $port): int
{
if ($port < 0) {
throw new Exception(
@@ -227,18 +197,14 @@ class Socket
/**
* Set the transport.
- *
- * @param string $transport Transport (TCP, UDP etc.).
- * @return string
- * @throws \Hoa\Socket\Exception
*/
- protected function setTransport($transport)
+ protected function setTransport(string $transport): ?string
{
$transport = strtolower($transport);
if (false === Transport::exists($transport)) {
throw new Exception(
- 'Transport %s is not enabled on this machin.',
+ 'Transport %s is not enabled on this machine.',
3,
$transport
);
@@ -252,80 +218,64 @@ class Socket
/**
* Get the address.
- *
- * @return string
*/
- public function getAddress()
+ public function getAddress(): ?string
{
return $this->_address;
}
/**
* Get the address type.
- *
- * @return int
*/
- public function getAddressType()
+ public function getAddressType(): int
{
return $this->_addressType;
}
/**
* Check if a port was declared.
- *
- * @return string
*/
- public function hasPort()
+ public function hasPort(): bool
{
return -1 != $this->getPort();
}
/**
* Get the port.
- *
- * @return int
*/
- public function getPort()
+ public function getPort(): int
{
return $this->_port;
}
/**
* Check if a transport was declared.
- *
- * @return bool
*/
- public function hasTransport()
+ public function hasTransport(): bool
{
return null !== $this->getTransport();
}
/**
* Get the transport.
- *
- * @return string
*/
- public function getTransport()
+ public function getTransport(): ?string
{
return $this->_transport;
}
/**
* Check if the socket is secured or not.
- *
- * @return bool
*/
- public function isSecured()
+ public function isSecured(): bool
{
return $this->_secured;
}
/**
* Get a string that represents the socket address.
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
$out = null;
@@ -350,4 +300,4 @@ class Socket
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Socket\Socket');
+Consistency::flexEntity(Socket::class);
diff --git a/Source/Transport.php b/Source/Transport.php
index 617bc49..c13b0ad 100644
--- a/Source/Transport.php
+++ b/Source/Transport.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,16 +45,11 @@ namespace Hoa\Socket;
* kind `scheme://uri`. A callable is associated to a `scheme` and represents a
* factory building valid `Hoa\Socket\Socket` instances (so with `tcp://` or
* `udp://` “native” schemes).
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Transport
{
/**
* Additionnal transports (scheme to callable).
- *
- * @var array
*/
protected static $_transports = [];
@@ -60,10 +57,8 @@ class Transport
/**
* Get all enabled transports.
- *
- * @return array
*/
- public static function get()
+ public static function get(): array
{
return array_merge(
stream_get_transports(),
@@ -73,11 +68,8 @@ class Transport
/**
* Check if a transport exists.
- *
- * @param string $transport Transport to check.
- * @return bool
*/
- public static function exists($transport)
+ public static function exists(string $transport): bool
{
return in_array(strtolower($transport), static::get());
}
@@ -85,26 +77,16 @@ class Transport
/**
* Register a new transport.
* Note: It is possible to override a standard transport.
- *
- * @param string $transport Transport name.
- * @param callable $factory Associated factory to build a valid
- * `Hoa\Socket\Socket` object.
- * @return void
*/
- public static function register($transport, callable $factory)
+ public static function register(string $transport, callable $factory): void
{
static::$_transports[$transport] = $factory;
-
- return;
}
/**
* Get the factory associated to a specific transport.
- *
- * @param string $transport Transport.
- * @return callable
*/
- public static function getFactory($transport)
+ public static function getFactory(string $transport): callable
{
if (false === static::exists($transport) ||
!isset(static::$_transports[$transport])) {
diff --git a/Test/Unit/Client.php b/Test/Unit/Client.php
index f9b2724..d494b8c 100644
--- a/Test/Unit/Client.php
+++ b/Test/Unit/Client.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite for the client object.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Client extends Test\Unit\Suite
{
- public function case_is_a_connection()
+ public function case_is_a_connection(): void
{
$this
->given($this->mockGenerator->orphanize('__construct'))
@@ -60,7 +61,7 @@ class Client extends Test\Unit\Suite
->isInstanceOf('Hoa\Socket\Connection');
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -92,7 +93,7 @@ class Client extends Test\Unit\Suite
->isEqualTo($context);
}
- public function case_open_cannot_join()
+ public function case_open_cannot_join(): void
{
$self = $this;
@@ -121,7 +122,7 @@ class Client extends Test\Unit\Suite
return false;
}
)
- ->exception(function () use ($self, $client, $streamName) {
+ ->exception(function () use ($self, $client, $streamName): void {
$self->invoke($client)->_open($streamName);
})
->isInstanceOf('Hoa\Socket\Exception')
@@ -130,7 +131,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_open_returns_an_error()
+ public function case_open_returns_an_error(): void
{
$self = $this;
@@ -159,7 +160,7 @@ class Client extends Test\Unit\Suite
return false;
}
)
- ->exception(function () use ($self, $client, $streamName) {
+ ->exception(function () use ($self, $client, $streamName): void {
$self->invoke($client)->_open($streamName);
})
->isInstanceOf('Hoa\Socket\Exception')
@@ -168,7 +169,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_open()
+ public function case_open(): void
{
$self = $this;
@@ -228,7 +229,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($node);
}
- public function case_open_with_context()
+ public function case_open_with_context(): void
{
$self = $this;
@@ -292,7 +293,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($node);
}
- public function case_close_persistent_connection()
+ public function case_close_persistent_connection(): void
{
$this
->given(
@@ -307,7 +308,7 @@ class Client extends Test\Unit\Suite
->isFalse();
}
- public function case_close()
+ public function case_close(): void
{
$self = $this;
@@ -337,7 +338,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_select()
+ public function case_select(): void
{
$self = $this;
@@ -348,7 +349,7 @@ class Client extends Test\Unit\Suite
$timeout = 42,
$this->calling($client)->getTimeout = $timeout,
- $this->function->stream_select = function (&$_read, &$_write, &$_except, $_timeout, $_ttimeout) use ($self, &$called, $timeout) {
+ $this->function->stream_select = function (&$_read, &$_write, &$_except, $_timeout, $_ttimeout) use ($self, &$called, $timeout): void {
$called = true;
$self
@@ -376,7 +377,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_consider_not_a_client()
+ public function case_consider_not_a_client(): void
{
$this
->given(
@@ -385,18 +386,18 @@ class Client extends Test\Unit\Suite
$this->mockGenerator->orphanize('__construct'),
$other = new \Mock\Hoa\Socket\Server()
)
- ->exception(function () use ($client, $other) {
+ ->exception(function () use ($client, $other): void {
$client->consider($other);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_consider_disconnected_client()
+ public function case_consider_disconnected_client(): void
{
$this->_case_consider(true);
}
- public function case_consider()
+ public function case_consider(): void
{
$this->_case_consider(false);
}
@@ -416,7 +417,7 @@ class Client extends Test\Unit\Suite
$this->calling($node)->getId = 'foo',
$this->calling($other)->isDisconnected = $disconnected,
$this->calling($other)->getCurrentNode = $node,
- $this->calling($other)->connect = function () use (&$called) {
+ $this->calling($other)->connect = function () use (&$called): void {
$called = true;
},
@@ -443,14 +444,14 @@ class Client extends Test\Unit\Suite
->isEqualTo($node);
}
- public function case_is()
+ public function case_is(): void
{
$this
->_case_is('foo', 'foo')
->isTrue();
}
- public function case_is_not()
+ public function case_is_not(): void
{
$this
->_case_is('foo', 'bar')
@@ -476,19 +477,19 @@ class Client extends Test\Unit\Suite
->boolean($result);
}
- public function case_is_connected()
+ public function case_is_connected(): void
{
$this
->_case_flag_is(SUT::CONNECT, 'isConnected');
}
- public function case_is_asynchronous()
+ public function case_is_asynchronous(): void
{
$this
->_case_flag_is(SUT::ASYNCHRONOUS, 'isAsynchronous');
}
- public function case_is_persistent()
+ public function case_is_persistent(): void
{
$this
->_case_flag_is(SUT::PERSISTENT, 'isPersistent');
diff --git a/Test/Unit/Connection/Connection.php b/Test/Unit/Connection/Connection.php
index d88a416..b8aaaa1 100644
--- a/Test/Unit/Connection/Connection.php
+++ b/Test/Unit/Connection/Connection.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Mock\Hoa\Socket\Connection as SUT;
*
* Test suite of the connection class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Connection extends Test\Unit\Suite
{
- public function case_interfaces()
+ public function case_interfaces(): void
{
$this
->given($this->mockGenerator->orphanize('__construct'))
@@ -64,7 +65,7 @@ class Connection extends Test\Unit\Suite
->isInstanceOf('Iterator');
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -96,7 +97,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($context);
}
- public function case_connect()
+ public function case_connect(): void
{
$this
->given(
@@ -105,7 +106,7 @@ class Connection extends Test\Unit\Suite
$flag = 153,
$connection = new SUT($socket, $timeout, $flag),
- $this->calling($connection)->open = function () use (&$called) {
+ $this->calling($connection)->open = function () use (&$called): void {
$called = true;
},
$oldDisconnected = $connection->isDisconnected()
@@ -120,7 +121,7 @@ class Connection extends Test\Unit\Suite
->isFalse();
}
- public function case__current()
+ public function case__current(): void
{
$self = $this;
@@ -149,7 +150,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_iterator()
+ public function case_iterator(): void
{
$self = $this;
@@ -158,21 +159,21 @@ class Connection extends Test\Unit\Suite
$this->mockGenerator->orphanize('__construct'),
$connection = new \Mock\Hoa\Socket\Test\Unit\Connection\ConnectionIterator(),
- $this->calling($connection)->_setStream[1] = function ($current) use ($self, &$called0) {
+ $this->calling($connection)->_setStream[1] = function ($current) use ($self, &$called0): void {
$called0 = true;
$self
->string($current)
->isEqualTo('foo');
},
- $this->calling($connection)->_setStream[2] = function ($current) use ($self, &$called1) {
+ $this->calling($connection)->_setStream[2] = function ($current) use ($self, &$called1): void {
$called1 = true;
$self
->string($current)
->isEqualTo('bar');
},
- $this->calling($connection)->_setStream[3] = function ($current) use ($self, &$called2) {
+ $this->calling($connection)->_setStream[3] = function ($current) use ($self, &$called2): void {
$called2 = true;
$self
@@ -192,7 +193,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_quiet()
+ public function case_quiet(): void
{
$this->_case_shutdown('quiet', STREAM_SHUT_RD, 'isQuiet');
}
@@ -207,7 +208,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_shutdown('quietAndMute', STREAM_SHUT_RDWR, 'isDisconnected');
}
- public function _case_shutdown($method, $how, $isMethod)
+ public function _case_shutdown($method, $how, $isMethod): void
{
$self = $this;
@@ -240,7 +241,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_disconnect()
+ public function case_disconnect(): void
{
$this
->given(
@@ -251,7 +252,7 @@ class Connection extends Test\Unit\Suite
$connection->connect(),
$this->calling($connection)->open = null,
- $this->calling($connection)->_close = function () use (&$called) {
+ $this->calling($connection)->_close = function () use (&$called): void {
$called = true;
}
)
@@ -265,7 +266,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_set_socket_not_a_protocol()
+ public function case_set_socket_not_a_protocol(): void
{
$this
->given(
@@ -273,13 +274,13 @@ class Connection extends Test\Unit\Suite
$connection = new SUT(),
$socketUri = 'foobar'
)
- ->exception(function () use ($connection, $socketUri) {
+ ->exception(function () use ($connection, $socketUri): void {
$this->invoke($connection)->setSocket($socketUri);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_set_socket()
+ public function case_set_socket(): void
{
$this
->given(
@@ -306,7 +307,7 @@ class Connection extends Test\Unit\Suite
->isFalse();
}
- public function case_set_timeout()
+ public function case_set_timeout(): void
{
$this
->given(
@@ -322,7 +323,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($timeout);
}
- public function case_set_flag()
+ public function case_set_flag(): void
{
$this
->given(
@@ -338,7 +339,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($flag);
}
- public function case_set_context()
+ public function case_set_context(): void
{
$this
->given(
@@ -354,7 +355,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($context);
}
- public function case_set_node_name()
+ public function case_set_node_name(): void
{
$this
->given(
@@ -370,7 +371,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($nodeName);
}
- public function case_consider_remote_address()
+ public function case_consider_remote_address(): void
{
$this
->given(
@@ -386,7 +387,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($consider);
}
- public function case_enable_encryption_without_current_node()
+ public function case_enable_encryption_without_current_node(): void
{
$this
->given(
@@ -403,7 +404,7 @@ class Connection extends Test\Unit\Suite
->isFalse();
}
- public function case_enable_encryption_without_type()
+ public function case_enable_encryption_without_type(): void
{
$self = $this;
@@ -442,7 +443,7 @@ class Connection extends Test\Unit\Suite
->isFalse();
}
- public function case_enable_encryption_without_session_stream()
+ public function case_enable_encryption_without_session_stream(): void
{
$self = $this;
@@ -459,7 +460,7 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getCurrentNode = $node,
$this->calling($connection)->getStream = $stream,
- $this->calling($node)->setEncryptionType = function ($_type) use ($self, &$called0, $type) {
+ $this->calling($node)->setEncryptionType = function ($_type) use ($self, &$called0, $type): void {
$called0 = true;
$self
@@ -492,7 +493,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_enable_encryption()
+ public function case_enable_encryption(): void
{
$self = $this;
@@ -510,7 +511,7 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getCurrentNode = $node,
$this->calling($connection)->getStream = $stream,
- $this->calling($node)->setEncryptionType = function ($_type) use ($self, &$called0, $type) {
+ $this->calling($node)->setEncryptionType = function ($_type) use ($self, &$called0, $type): void {
$called0 = true;
$self
@@ -545,7 +546,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_is_encrypted_after_a_successful_encryption()
+ public function case_is_encrypted_after_a_successful_encryption(): void
{
$this
->given(
@@ -563,7 +564,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_get_node_id()
+ public function case_get_node_id(): void
{
$this
->given(
@@ -577,7 +578,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo(md5((int) $resource));
}
- public function case_read_on_a_null_stream()
+ public function case_read_on_a_null_stream(): void
{
$this
->given(
@@ -586,13 +587,13 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getStream = null
)
- ->exception(function () use ($connection) {
+ ->exception(function () use ($connection): void {
$connection->read(42);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_read_a_negative_length()
+ public function case_read_a_negative_length(): void
{
$this
->given(
@@ -601,13 +602,13 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getStream = 'foo'
)
- ->exception(function () use ($connection) {
+ ->exception(function () use ($connection): void {
$connection->read(-1);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_read_encrypted_node()
+ public function case_read_encrypted_node(): void
{
$self = $this;
@@ -641,7 +642,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_read_without_remote_address_considered()
+ public function case_read_without_remote_address_considered(): void
{
$self = $this;
@@ -680,7 +681,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_read()
+ public function case_read(): void
{
$self = $this;
@@ -722,7 +723,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo('1.2.3.4');
}
- public function case_read_string()
+ public function case_read_string(): void
{
$this
->given(
@@ -736,7 +737,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo('foo');
}
- public function case_read_character()
+ public function case_read_character(): void
{
$this
->given($output = 'foobar')
@@ -747,7 +748,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo('f');
}
- public function case_read_boolean_true()
+ public function case_read_boolean_true(): void
{
$this
->given($output = '1')
@@ -758,7 +759,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_read_boolean_false()
+ public function case_read_boolean_false(): void
{
$this
->given($output = '0')
@@ -769,7 +770,7 @@ class Connection extends Test\Unit\Suite
->isFalse();
}
- public function case_read_integer()
+ public function case_read_integer(): void
{
$this
->given($output = '42foobar')
@@ -780,7 +781,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo(42);
}
- public function case_read_float()
+ public function case_read_float(): void
{
$this
->given($output = '4.2foobar')
@@ -791,7 +792,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo(4.2);
}
- public function case_read_array()
+ public function case_read_array(): void
{
$this
->given($output = 'foo bar')
@@ -805,7 +806,7 @@ class Connection extends Test\Unit\Suite
]);
}
- public function case_read_line_with_encryption()
+ public function case_read_line_with_encryption(): void
{
$self = $this;
@@ -837,7 +838,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_read_line_without_encryption()
+ public function case_read_line_without_encryption(): void
{
$self = $this;
@@ -869,7 +870,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_read_all()
+ public function case_read_all(): void
{
$this
->given($output = 'foobar' . "\n")
@@ -880,7 +881,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo($output);
}
- public function case_scanf()
+ public function case_scanf(): void
{
$this
->given($output = 'foo bar')
@@ -912,7 +913,7 @@ class Connection extends Test\Unit\Suite
);
}
- public function case_write_on_a_null_stream()
+ public function case_write_on_a_null_stream(): void
{
$this
->given(
@@ -921,13 +922,13 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getStream = null
)
- ->exception(function () use ($connection) {
+ ->exception(function () use ($connection): void {
$connection->write('foo', 3);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_write_a_negative_length()
+ public function case_write_a_negative_length(): void
{
$this
->given(
@@ -937,13 +938,13 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getStream = $stream
)
- ->exception(function () use ($connection) {
+ ->exception(function () use ($connection): void {
$connection->write('foo', -1);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_write_on_encrypted_node()
+ public function case_write_on_encrypted_node(): void
{
$self = $this;
@@ -980,7 +981,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_write_without_remote_address_considered()
+ public function case_write_without_remote_address_considered(): void
{
$self = $this;
@@ -1017,7 +1018,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_write_without_remote_address_considered_broken_pipe()
+ public function case_write_without_remote_address_considered_broken_pipe(): void
{
$self = $this;
@@ -1035,13 +1036,13 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->isRemoteAddressConsidered = false,
$this->function->stream_socket_sendto = -1
)
- ->exception(function () use ($connection, $string, $length) {
+ ->exception(function () use ($connection, $string, $length): void {
$connection->write($string, $length);
})
->isInstanceOf('Hoa\Socket\Exception\BrokenPipe');
}
- public function case_write()
+ public function case_write(): void
{
$self = $this;
@@ -1084,7 +1085,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_write_broken_pipe()
+ public function case_write_broken_pipe(): void
{
$self = $this;
@@ -1104,13 +1105,13 @@ class Connection extends Test\Unit\Suite
$this->calling($connection)->getRemoteAddress = $remote,
$this->function->stream_socket_sendto = -1
)
- ->exception(function () use ($connection, $string, $length) {
+ ->exception(function () use ($connection, $string, $length): void {
$connection->write($string, $length);
})
->isInstanceOf('Hoa\Socket\Exception\BrokenPipe');
}
- public function case_base_name()
+ public function case_base_name(): void
{
$this
->given(
@@ -1125,7 +1126,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo('bar');
}
- public function case_base_name_of_a_domain()
+ public function case_base_name_of_a_domain(): void
{
$this
->given(
@@ -1140,7 +1141,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo('hoa-project.net:80');
}
- public function case_directory_name()
+ public function case_directory_name(): void
{
$this
->given(
@@ -1155,7 +1156,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo('tcp://hoa-project.net:80/foo');
}
- public function case_directory_name_of_a_domain()
+ public function case_directory_name_of_a_domain(): void
{
$this
->given(
diff --git a/Test/Unit/Connection/Group.php b/Test/Unit/Connection/Group.php
index b4eea51..f9a980c 100644
--- a/Test/Unit/Connection/Group.php
+++ b/Test/Unit/Connection/Group.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite of the connection group.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Group extends Test\Unit\Suite
{
- public function case_interfaces()
+ public function case_interfaces(): void
{
$this
->when($result = new SUT())
@@ -61,7 +62,7 @@ class Group extends Test\Unit\Suite
->isInstanceOf('Countable');
}
- public function case_offset_exists()
+ public function case_offset_exists(): void
{
$this
->given(
@@ -76,7 +77,7 @@ class Group extends Test\Unit\Suite
->isTrue();
}
- public function case_offset_does_not_exist()
+ public function case_offset_does_not_exist(): void
{
$this
->given($group = new SUT())
@@ -86,7 +87,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_get()
+ public function case_offset_get(): void
{
$this
->given(
@@ -102,7 +103,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_offset_get_an_undefined_offset()
+ public function case_offset_get_an_undefined_offset(): void
{
$this
->given($group = new SUT())
@@ -112,17 +113,17 @@ class Group extends Test\Unit\Suite
->isNull();
}
- public function case_offset_set_not_a_connection()
+ public function case_offset_set_not_a_connection(): void
{
$this
->given($group = new SUT())
- ->exception(function () use ($group) {
+ ->exception(function () use ($group): void {
$group->offsetSet(null, 42);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_offset_set_with_a_null_offset()
+ public function case_offset_set_with_a_null_offset(): void
{
$this
->given(
@@ -143,7 +144,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_offset_set()
+ public function case_offset_set(): void
{
$this
->given(
@@ -164,7 +165,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_offset_set_with_the_same_key()
+ public function case_offset_set_with_the_same_key(): void
{
$this
->given(
@@ -187,7 +188,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($connectionB);
}
- public function case_offset_set_another_connection()
+ public function case_offset_set_another_connection(): void
{
$self = $this;
@@ -196,7 +197,7 @@ class Group extends Test\Unit\Suite
$this->mockGenerator->orphanize('__construct'),
$connectionA = new \Mock\Hoa\Socket\Connection\Handler(),
$connectionB = new \Mock\Hoa\Socket\Connection\Handler(),
- $this->calling($connectionA)->merge = function (LUT\Connection\Handler $connection) use ($self, &$called, $connectionB) {
+ $this->calling($connectionA)->merge = function (LUT\Connection\Handler $connection) use ($self, &$called, $connectionB): void {
$called = true;
$self
@@ -226,17 +227,17 @@ class Group extends Test\Unit\Suite
->isTrue();
}
- public function case_offset_unset()
+ public function case_offset_unset(): void
{
$this
->given($group = new SUT())
- ->exception(function () use ($group) {
+ ->exception(function () use ($group): void {
$group->offsetUnset('foo');
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_get_empty_iterator()
+ public function case_get_empty_iterator(): void
{
$this
->given($group = new SUT())
@@ -247,7 +248,7 @@ class Group extends Test\Unit\Suite
->hasSize(0);
}
- public function case_get_iterator()
+ public function case_get_iterator(): void
{
$this
->given(
@@ -262,7 +263,7 @@ class Group extends Test\Unit\Suite
->hasSize(1);
}
- public function case_count_zero()
+ public function case_count_zero(): void
{
$this
->given($group = new SUT())
@@ -272,7 +273,7 @@ class Group extends Test\Unit\Suite
->isEqualTo(0);
}
- public function case_count()
+ public function case_count(): void
{
$this
->given(
@@ -288,7 +289,7 @@ class Group extends Test\Unit\Suite
->isEqualTo(2);
}
- public function case_merge()
+ public function case_merge(): void
{
$this
->given(
@@ -309,17 +310,17 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_run_no_connection()
+ public function case_run_no_connection(): void
{
$this
->given($group = new SUT())
- ->exception(function () use ($group) {
+ ->exception(function () use ($group): void {
$group->run();
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_run()
+ public function case_run(): void
{
$this
->given(
@@ -328,7 +329,7 @@ class Group extends Test\Unit\Suite
$group = new SUT(),
$group[] = new \Mock\Hoa\Socket\Connection\Handler(),
$group[] = new \Mock\Hoa\Socket\Connection\Handler(),
- $this->calling($group[0])->run = function () use (&$called) {
+ $this->calling($group[0])->run = function () use (&$called): void {
$called = true;
return;
@@ -342,7 +343,7 @@ class Group extends Test\Unit\Suite
->isTrue();
}
- public function case_get_first_connection()
+ public function case_get_first_connection(): void
{
$this
->given(
diff --git a/Test/Unit/Connection/Handler.php b/Test/Unit/Connection/Handler.php
index c144a08..95a82ad 100644
--- a/Test/Unit/Connection/Handler.php
+++ b/Test/Unit/Connection/Handler.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Mock\Hoa\Socket\Connection\Handler as SUT;
*
* Test suite of the connection handler.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Handler extends Test\Unit\Suite
{
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -63,7 +64,7 @@ class Handler extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_get_original_connection()
+ public function case_get_original_connection(): void
{
$this
->given(
@@ -77,7 +78,7 @@ class Handler extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_get_merged_connections()
+ public function case_get_merged_connections(): void
{
$self = $this;
@@ -97,7 +98,7 @@ class Handler extends Test\Unit\Suite
->isEqualTo([$handlerB]);
}
- public function case_run_connect_and_wait()
+ public function case_run_connect_and_wait(): void
{
$this
->given(
@@ -105,10 +106,10 @@ class Handler extends Test\Unit\Suite
$connection = new \Mock\Hoa\Socket\Server(),
$handler = new SUT($connection),
- $this->calling($connection)->connectAndWait = function () use (&$connectCalled) {
+ $this->calling($connection)->connectAndWait = function () use (&$connectCalled): void {
$connectCalled = true;
},
- $this->calling($connection)->disconnect = function () use (&$disconnectCalled) {
+ $this->calling($connection)->disconnect = function () use (&$disconnectCalled): void {
$disconnectCalled = true;
},
$this->calling($connection)->select = [],
@@ -125,7 +126,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_run_connect()
+ public function case_run_connect(): void
{
$this
->given(
@@ -133,10 +134,10 @@ class Handler extends Test\Unit\Suite
$connection = new \Mock\Hoa\Socket\Connection(),
$handler = new SUT($connection),
- $this->calling($connection)->connect = function () use (&$connectCalled) {
+ $this->calling($connection)->connect = function () use (&$connectCalled): void {
$connectCalled = true;
},
- $this->calling($connection)->disconnect = function () use (&$disconnectCalled) {
+ $this->calling($connection)->disconnect = function () use (&$disconnectCalled): void {
$disconnectCalled = true;
},
$this->calling($connection)->select = [],
@@ -153,7 +154,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_run_node_on_the_current_handler()
+ public function case_run_node_on_the_current_handler(): void
{
$self = $this;
@@ -182,7 +183,7 @@ class Handler extends Test\Unit\Suite
return false;
},
- $this->calling($handlerA)->_run = function (LUT\Node $node) use ($self, &$runCalled, $nodeX) {
+ $this->calling($handlerA)->_run = function (LUT\Node $node) use ($self, &$runCalled, $nodeX): void {
$runCalled = true;
$self
@@ -202,7 +203,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_run_node_on_another_handler()
+ public function case_run_node_on_another_handler(): void
{
$self = $this;
@@ -231,10 +232,10 @@ class Handler extends Test\Unit\Suite
return true;
},
- $this->calling($handlerA)->_run = function (LUT\Node $node) use (&$runCalledA) {
+ $this->calling($handlerA)->_run = function (LUT\Node $node) use (&$runCalledA): void {
$runCalledA = true;
},
- $this->calling($handlerB)->_run = function (LUT\Node $node) use ($self, &$runCalledB, $nodeX) {
+ $this->calling($handlerB)->_run = function (LUT\Node $node) use ($self, &$runCalledB, $nodeX): void {
$runCalledB = true;
$self
@@ -256,7 +257,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_run_when_connection_failed_to_detect_the_node()
+ public function case_run_when_connection_failed_to_detect_the_node(): void
{
$self = $this;
@@ -281,10 +282,10 @@ class Handler extends Test\Unit\Suite
$this->calling($connectionB)->getCurrentNode = $nodeX,
$this->calling($nodeX)->getSocket = $resourceY,
- $this->calling($handlerA)->_run = function (LUT\Node $node) use (&$runCalledA) {
+ $this->calling($handlerA)->_run = function (LUT\Node $node) use (&$runCalledA): void {
$runCalledA = true;
},
- $this->calling($handlerB)->_run = function (LUT\Node $node) use ($self, &$runCalledB, $nodeX) {
+ $this->calling($handlerB)->_run = function (LUT\Node $node) use ($self, &$runCalledB, $nodeX): void {
$runCalledB = true;
$self
@@ -304,7 +305,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_merge()
+ public function case_merge(): void
{
$self = $this;
@@ -316,7 +317,7 @@ class Handler extends Test\Unit\Suite
$connectionB = new \Mock\Hoa\Socket\Connection(),
$handlerB = new SUT($connectionB),
- $this->calling($connectionA)->consider = function (LUT\Connection $connection) use ($self, &$called, $connectionB) {
+ $this->calling($connectionA)->consider = function (LUT\Connection $connection) use ($self, &$called, $connectionB): void {
$called = true;
$self
@@ -334,7 +335,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_merge_a_server()
+ public function case_merge_a_server(): void
{
$self = $this;
@@ -348,7 +349,7 @@ class Handler extends Test\Unit\Suite
$connectionB = new \Mock\Hoa\Socket\Server(),
$handlerB = new \Mock\Handlerz($connectionB),
- $this->calling($handlerB)->setConnection = function (LUT\Connection $connection) use ($self, &$called, $connectionA) {
+ $this->calling($handlerB)->setConnection = function (LUT\Connection $connection) use ($self, &$called, $connectionA): void {
$called = true;
$self
@@ -366,7 +367,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_send_on_nonexistent_node()
+ public function case_send_on_nonexistent_node(): void
{
$this
->given(
@@ -382,7 +383,7 @@ class Handler extends Test\Unit\Suite
->isNull();
}
- public function case_send_on_unspecified_node()
+ public function case_send_on_unspecified_node(): void
{
$self = $this;
@@ -444,7 +445,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_send_broken_pipe()
+ public function case_send_broken_pipe(): void
{
$self = $this;
@@ -484,7 +485,7 @@ class Handler extends Test\Unit\Suite
$this->calling($node)->getSocket = $resource,
$this->calling($handler)->_send->throw = $exception
)
- ->exception(function () use ($handler, $message, $node) {
+ ->exception(function () use ($handler, $message, $node): void {
$handler->send($message, $node);
})
->isIdenticalTo($exception)
@@ -494,7 +495,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_send()
+ public function case_send(): void
{
$self = $this;
@@ -555,7 +556,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_send_on_closure()
+ public function case_send_on_closure(): void
{
$self = $this;
@@ -606,7 +607,7 @@ class Handler extends Test\Unit\Suite
};
}
)
- ->when(function () use (&$result, $handler, $message, $node) {
+ ->when(function () use (&$result, $handler, $message, $node): void {
$result = $handler->send($message, $node);
return;
@@ -622,7 +623,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_broadcast()
+ public function case_broadcast(): void
{
$self = $this;
@@ -640,7 +641,7 @@ class Handler extends Test\Unit\Suite
$this->calling($connection)->getCurrentNode = $nodeX,
- $this->calling($handler)->broadcastIf = function (\Closure $predicate, $message) use ($self, &$called, $nodeX, $nodeY) {
+ $this->calling($handler)->broadcastIf = function (\Closure $predicate, $message) use ($self, &$called, $nodeX, $nodeY): void {
$called = true;
$self
@@ -667,7 +668,7 @@ class Handler extends Test\Unit\Suite
->isTrue();
}
- public function case_broadcast_if_broken_pipe()
+ public function case_broadcast_if_broken_pipe(): void
{
$self = $this;
@@ -700,7 +701,7 @@ class Handler extends Test\Unit\Suite
$this->calling($handler)->send->throw = $exception
)
- ->exception(function () use ($handler, $predicate, $message) {
+ ->exception(function () use ($handler, $predicate, $message): void {
$handler->broadcastIf($predicate, $message, 'bar', 'baz');
})
->isInstanceOf('Hoa\Exception\Group')
@@ -712,7 +713,7 @@ class Handler extends Test\Unit\Suite
->isIdenticalTo($exception);
}
- public function case_broadcast_if()
+ public function case_broadcast_if(): void
{
$self = $this;
@@ -738,7 +739,7 @@ class Handler extends Test\Unit\Suite
$this->calling($nodeY)->getConnection = $connection,
- $this->calling($handler)->send = function ($message, LUT\Node $node, $extra1, $extra2) use ($self, &$called, $nodeY) {
+ $this->calling($handler)->send = function ($message, LUT\Node $node, $extra1, $extra2) use ($self, &$called, $nodeY): void {
++$called;
$self
diff --git a/Test/Unit/Exception/BrokenPipe.php b/Test/Unit/Exception/BrokenPipe.php
index 882dcca..515d93e 100644
--- a/Test/Unit/Exception/BrokenPipe.php
+++ b/Test/Unit/Exception/BrokenPipe.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,12 +46,11 @@ use Hoa\Test;
*
* Test suite of the broken pipe exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class BrokenPipe extends Test\Unit\Suite
{
- public function case_hoa_socket_exception()
+ public function case_hoa_socket_exception(): void
{
$this
->when($result = new SUT('foo', 0))
diff --git a/Test/Unit/Exception/Exception.php b/Test/Unit/Exception/Exception.php
index b587063..88a3013 100644
--- a/Test/Unit/Exception/Exception.php
+++ b/Test/Unit/Exception/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,12 +46,11 @@ use Hoa\Test;
*
* Test suite of the exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Exception extends Test\Unit\Suite
{
- public function case_hoa_exception()
+ public function case_hoa_exception(): void
{
$this
->when($result = new SUT('foo', 0))
diff --git a/Test/Unit/Node.php b/Test/Unit/Node.php
index eae9069..d149b61 100644
--- a/Test/Unit/Node.php
+++ b/Test/Unit/Node.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite for the node object.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Node extends Test\Unit\Suite
{
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -70,7 +71,7 @@ class Node extends Test\Unit\Suite
->isIdenticalTo($connection);
}
- public function case_set_encryption_type()
+ public function case_set_encryption_type(): void
{
$this
->given(
@@ -88,7 +89,7 @@ class Node extends Test\Unit\Suite
->isEqualTo(LUT\Server::ENCRYPTION_SSLv23);
}
- public function case_get_encryption_type()
+ public function case_get_encryption_type(): void
{
$this
->given(
diff --git a/Test/Unit/Server.php b/Test/Unit/Server.php
index 1f34f21..c38db90 100644
--- a/Test/Unit/Server.php
+++ b/Test/Unit/Server.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite for the server object.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Server extends Test\Unit\Suite
{
- public function case_is_a_connection()
+ public function case_is_a_connection(): void
{
$this
->given($this->mockGenerator->orphanize('__construct'))
@@ -60,7 +61,7 @@ class Server extends Test\Unit\Suite
->isInstanceOf('Hoa\Socket\Connection');
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -92,7 +93,7 @@ class Server extends Test\Unit\Suite
->isEqualTo($context);
}
- public function case_constructor_no_flag_with_tcp()
+ public function case_constructor_no_flag_with_tcp(): void
{
$this
->given(
@@ -108,7 +109,7 @@ class Server extends Test\Unit\Suite
->isEqualTo(SUT::BIND | SUT::LISTEN);
}
- public function case_constructor_no_flag_with_udp()
+ public function case_constructor_no_flag_with_udp(): void
{
$this
->given(
@@ -124,7 +125,7 @@ class Server extends Test\Unit\Suite
->isEqualTo(SUT::BIND);
}
- public function case_constructor_with_flag_and_tcp()
+ public function case_constructor_with_flag_and_tcp(): void
{
$this
->given(
@@ -141,7 +142,7 @@ class Server extends Test\Unit\Suite
->isEqualTo(SUT::BIND | SUT::LISTEN);
}
- public function case_constructor_with_flag_and_udp()
+ public function case_constructor_with_flag_and_udp(): void
{
$this
->given(
@@ -158,7 +159,7 @@ class Server extends Test\Unit\Suite
->isEqualTo($flag);
}
- public function case_constructor_with_flag_and_udp_listen_not_allowed()
+ public function case_constructor_with_flag_and_udp_listen_not_allowed(): void
{
$this
->given(
@@ -166,13 +167,13 @@ class Server extends Test\Unit\Suite
$timeout = 42,
$flag = SUT::LISTEN
)
- ->exception(function () use ($socket, $timeout, $flag) {
+ ->exception(function () use ($socket, $timeout, $flag): void {
new SUT($socket, $timeout, $flag);
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_open_cannot_join()
+ public function case_open_cannot_join(): void
{
$self = $this;
@@ -197,7 +198,7 @@ class Server extends Test\Unit\Suite
return false;
}
)
- ->exception(function () use ($self, $server, $streamName) {
+ ->exception(function () use ($self, $server, $streamName): void {
$self->invoke($server)->_open($streamName);
})
->isInstanceOf('Hoa\Socket\Exception')
@@ -206,7 +207,7 @@ class Server extends Test\Unit\Suite
->isTrue();
}
- public function case_open()
+ public function case_open(): void
{
$self = $this;
@@ -262,7 +263,7 @@ class Server extends Test\Unit\Suite
->isIdenticalTo($result);
}
- public function case_open_with_context()
+ public function case_open_with_context(): void
{
$self = $this;
@@ -322,7 +323,7 @@ class Server extends Test\Unit\Suite
->isIdenticalTo($result);
}
- public function case_connect_timed_out()
+ public function case_connect_timed_out(): void
{
$self = $this;
@@ -346,7 +347,7 @@ class Server extends Test\Unit\Suite
return false;
}
)
- ->exception(function () use ($server) {
+ ->exception(function () use ($server): void {
$server->connect();
})
->isInstanceOf('Hoa\Socket\Exception')
@@ -354,7 +355,7 @@ class Server extends Test\Unit\Suite
->isTrue();
}
- public function case_connect()
+ public function case_connect(): void
{
$self = $this;
@@ -388,7 +389,7 @@ class Server extends Test\Unit\Suite
->isIdenticalTo($client);
}
- public function case_connect_and_wait()
+ public function case_connect_and_wait(): void
{
$self = $this;
@@ -416,7 +417,7 @@ class Server extends Test\Unit\Suite
->isNotEqualTo(true);
}
- public function case_select_not_a_master()
+ public function case_select_not_a_master(): void
{
$self = $this;
@@ -430,7 +431,7 @@ class Server extends Test\Unit\Suite
$oldIteratorValues = $this->invoke($server)->getIteratorValues(),
$this->calling($server)->getTimeout = $timeout,
- $this->function->stream_select = function (&$_read, &$_write, &$_except, $_timeout, $_ttimeout) use ($self, &$called, $stack, $timeout) {
+ $this->function->stream_select = function (&$_read, &$_write, &$_except, $_timeout, $_ttimeout) use ($self, &$called, $stack, $timeout): void {
$called = true;
$self
@@ -463,7 +464,7 @@ class Server extends Test\Unit\Suite
->isEqualTo(count($oldIteratorValues) + 1);
}
- public function case_select_timed_out()
+ public function case_select_timed_out(): void
{
$self = $this;
@@ -475,7 +476,7 @@ class Server extends Test\Unit\Suite
$timeout = 42,
$this->calling($server)->getTimeout = $timeout,
- $this->function->stream_select = function (&$_read, &$_write, &$_except, $_timeout, $_ttimeout) use ($self, &$called0, $stack, $timeout) {
+ $this->function->stream_select = function (&$_read, &$_write, &$_except, $_timeout, $_ttimeout) use ($self, &$called0, $stack, $timeout): void {
$called0 = true;
$self
@@ -500,7 +501,7 @@ class Server extends Test\Unit\Suite
return false;
}
)
- ->exception(function () use ($server) {
+ ->exception(function () use ($server): void {
$server->select();
})
->isInstanceOf('Hoa\Socket\Exception')
@@ -510,17 +511,17 @@ class Server extends Test\Unit\Suite
->isTrue();
}
- public function case_consider_client()
+ public function case_consider_client(): void
{
$this->_case_consider_client(false);
}
- public function case_consider_disconnected_client()
+ public function case_consider_disconnected_client(): void
{
$this->_case_consider_client(true);
}
- protected function _case_consider_client($disconnected)
+ protected function _case_consider_client($disconnected): void
{
$this
->given(
@@ -535,7 +536,7 @@ class Server extends Test\Unit\Suite
$oldStack = $this->invoke($server)->getStack(),
$this->calling($other)->isDisconnected = $disconnected,
- $this->calling($other)->connect = function () use (&$called) {
+ $this->calling($other)->connect = function () use (&$called): void {
$called = true;
}
)
@@ -560,17 +561,17 @@ class Server extends Test\Unit\Suite
->isEqualTo($disconnected ?: null);
}
- public function case_consider()
+ public function case_consider(): void
{
$this->_case_consider(false);
}
- public function case_consider_disconnected_other()
+ public function case_consider_disconnected_other(): void
{
$this->_case_consider(true);
}
- protected function _case_consider($disconnected)
+ protected function _case_consider($disconnected): void
{
$this
->given(
@@ -585,7 +586,7 @@ class Server extends Test\Unit\Suite
$oldStack = $this->invoke($server)->getStack(),
$this->calling($other)->isDisconnected = $disconnected,
- $this->calling($other)->connectAndWait = function () use (&$called) {
+ $this->calling($other)->connectAndWait = function () use (&$called): void {
$called = true;
}
)
@@ -610,7 +611,7 @@ class Server extends Test\Unit\Suite
->isEqualTo($disconnected ?: null);
}
- public function case_is()
+ public function case_is(): void
{
$this
->given(
@@ -621,7 +622,7 @@ class Server extends Test\Unit\Suite
->isTrue();
}
- public function case_is_not()
+ public function case_is_not(): void
{
$this
->given(
@@ -651,13 +652,13 @@ class Server extends Test\Unit\Suite
->boolean($result);
}
- public function case_is_binding()
+ public function case_is_binding(): void
{
$this
->_case_flag_is(SUT::BIND, 'isBinding');
}
- public function case_is_Listening()
+ public function case_is_Listening(): void
{
$this
->_case_flag_is(SUT::LISTEN, 'isListening');
diff --git a/Test/Unit/Socket.php b/Test/Unit/Socket.php
index 5d34ff3..089b0d8 100644
--- a/Test/Unit/Socket.php
+++ b/Test/Unit/Socket.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,7 +46,6 @@ use Hoa\Test;
*
* Test suite for the socket object.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Socket extends Test\Unit\Suite
@@ -166,20 +167,20 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_ipv6_disabled_by_STREAM_PF_INET6()
+ public function case_ipv6_disabled_by_STREAM_PF_INET6(): void
{
$this
->given(
$this->function->defined = false,
$this->function->function_exists = false
)
- ->exception(function () {
+ ->exception(function (): void {
new SUT('tcp://[2001:0db8:85a3::]:80');
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_ipv6_disabled_by_AF_INET6()
+ public function case_ipv6_disabled_by_AF_INET6(): void
{
$this
->given(
@@ -188,7 +189,7 @@ class Socket extends Test\Unit\Suite
return 'AF_INET6' !== $constantName;
}
)
- ->exception(function () {
+ ->exception(function (): void {
new SUT('tcp://[2001:0db8:85a3::]:80');
})
->isInstanceOf('Hoa\Socket\Exception');
@@ -207,16 +208,16 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_no_a_URI()
+ public function case_no_a_URI(): void
{
$this
- ->exception(function () {
+ ->exception(function (): void {
new SUT('foobar');
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_has_port()
+ public function case_has_port(): void
{
$this
->when($result = new SUT('tcp://hoa-project.net:80'))
@@ -225,7 +226,7 @@ class Socket extends Test\Unit\Suite
->isTrue();
}
- public function case_has_no_port()
+ public function case_has_no_port(): void
{
$this
->when($result = new SUT('tcp://hoa-project.net'))
@@ -234,7 +235,7 @@ class Socket extends Test\Unit\Suite
->isFalse();
}
- public function case_is_not_secured()
+ public function case_is_not_secured(): void
{
$this
->when($result = new SUT('tcp://hoa-project.net:80'))
@@ -243,7 +244,7 @@ class Socket extends Test\Unit\Suite
->isFalse();
}
- protected function _case_check($uri, $expect)
+ protected function _case_check($uri, $expect): void
{
$this
->given(
diff --git a/Test/Unit/Transport.php b/Test/Unit/Transport.php
index 2c1f887..ea10bbb 100644
--- a/Test/Unit/Transport.php
+++ b/Test/Unit/Transport.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite for the transport.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Transport extends Test\Unit\Suite
{
- public function case_get_standards()
+ public function case_get_standards(): void
{
$this
->given($standardTransports = stream_get_transports())
@@ -60,14 +61,16 @@ class Transport extends Test\Unit\Suite
->strictlyContainsValues($standardTransports);
}
- public function case_get_standards_and_vendors()
+ public function case_get_standards_and_vendors(): void
{
$this
->given(
$standardTransports = stream_get_transports(),
$vendorTransports = ['foo', 'bar'],
- SUT::register('foo', function () { }),
- SUT::register('bar', function () { })
+ SUT::register('foo', function (): void {
+ }),
+ SUT::register('bar', function (): void {
+ })
)
->when($result = SUT::get())
->then
@@ -80,7 +83,7 @@ class Transport extends Test\Unit\Suite
);
}
- public function case_exists_standards()
+ public function case_exists_standards(): void
{
$this
->given($this->function->stream_get_transports = ['tcp'])
@@ -90,12 +93,13 @@ class Transport extends Test\Unit\Suite
->isTrue();
}
- public function case_exists_standards_and_vendors()
+ public function case_exists_standards_and_vendors(): void
{
$this
->given(
$this->function->stream_get_transports = ['tcp'],
- SUT::register('foo', function () { })
+ SUT::register('foo', function (): void {
+ })
)
->when($result = SUT::exists('tcp'))
->then
@@ -108,12 +112,13 @@ class Transport extends Test\Unit\Suite
->isTrue();
}
- public function case_not_exists_standards_and_vendors()
+ public function case_not_exists_standards_and_vendors(): void
{
$this
->given(
$this->function->stream_get_transports = ['tcp'],
- SUT::register('foo', function () { })
+ SUT::register('foo', function (): void {
+ })
)
->when($result = SUT::exists('bar'))
->then
@@ -121,7 +126,7 @@ class Transport extends Test\Unit\Suite
->isFalse();
}
- public function case_exists_not_in_lower_case()
+ public function case_exists_not_in_lower_case(): void
{
$this
->given($this->function->stream_get_transports = ['tcp'])
@@ -131,7 +136,7 @@ class Transport extends Test\Unit\Suite
->isTrue();
}
- public function case_register()
+ public function case_register(): void
{
$this
->given(
@@ -139,7 +144,8 @@ class Transport extends Test\Unit\Suite
$transport = 'foo' . uniqid(),
$oldExists = SUT::exists($transport)
)
- ->when($result = SUT::register($transport, function () { }))
+ ->when($result = SUT::register($transport, function (): void {
+ }))
->then
->variable($result)
->isNull()
@@ -151,26 +157,26 @@ class Transport extends Test\Unit\Suite
->isEqualTo(count($oldGet) + 1);
}
- public function case_get_unknown_factory()
+ public function case_get_unknown_factory(): void
{
$this
->given($transport = 'foo' . uniqid())
- ->when(function () use (&$result, $transport) {
+ ->when(function () use (&$result, $transport): void {
$result = SUT::getFactory($transport);
})
->then
->object($result)
->isInstanceOf('Closure')
- ->exception(function () use ($result, $transport) {
+ ->exception(function () use ($result, $transport): void {
$result($transport . '://127.0.0.1:80');
})
->isInstanceOf('Hoa\Socket\Exception');
}
- public function case_get_standard_factory()
+ public function case_get_standard_factory(): void
{
$this
- ->when(function () use (&$result) {
+ ->when(function () use (&$result): void {
$result = SUT::getFactory('tcp');
})
->then
@@ -180,7 +186,7 @@ class Transport extends Test\Unit\Suite
->isEqualTo(new LUT('tcp://127.0.0.1:80'));
}
- public function case_get_vendor_factory()
+ public function case_get_vendor_factory(): void
{
$self = $this;
@@ -200,7 +206,7 @@ class Transport extends Test\Unit\Suite
},
SUT::register($transport, $factory)
)
- ->when(function () use (&$result, $transport) {
+ ->when(function () use (&$result, $transport): void {
$result = SUT::getFactory($transport);
})
->then