Revert "Revert "Update code style""

This reverts commit 96ae68f27d.
This commit is contained in:
DariusIII
2024-09-13 22:11:13 +02:00
parent 2170d2e263
commit e5782ae554
10 changed files with 52 additions and 83 deletions
+20 -51
View File
@@ -71,8 +71,6 @@ class IRCClient
/**
* Buffer contents.
*
* @var string
*/
protected ?string $_buffer = null;
@@ -89,12 +87,12 @@ class IRCClient
protected array $_channelData = [];
/**
* Nick name when we log in.
* Nickname when we log in.
*/
protected string $_nickName;
/**
* User name when we log in.
* Username when we log in.
*/
protected string $_userName;
@@ -150,11 +148,7 @@ class IRCClient
*/
public function setSocketTimeout(int $timeout)
{
if (! is_numeric($timeout)) {
echo 'ERROR: IRC socket timeout must be a number!'.PHP_EOL;
} else {
$this->_socket_timeout = $timeout;
}
$this->_socket_timeout = $timeout;
}
/**
@@ -164,11 +158,7 @@ class IRCClient
*/
public function setConnectionTimeout(int $timeout)
{
if (! is_numeric($timeout)) {
echo 'ERROR: IRC connection timeout must be a number!'.PHP_EOL;
} else {
$this->_remote_connection_timeout = $timeout;
}
$this->_remote_connection_timeout = $timeout;
}
/**
@@ -176,11 +166,7 @@ class IRCClient
*/
public function setConnectionRetries(int $retries)
{
if (! is_numeric($retries)) {
echo 'ERROR: IRC connection retries must be a number!'.PHP_EOL;
} else {
$this->_reconnectRetries = $retries;
}
$this->_reconnectRetries = $retries;
}
/**
@@ -190,11 +176,7 @@ class IRCClient
*/
public function setReConnectDelay(int $delay)
{
if (! is_numeric($delay)) {
echo 'ERROR: IRC reconnect delay must be a number!'.PHP_EOL;
} else {
$this->_reconnectDelay = $delay;
}
$this->_reconnectDelay = $delay;
}
/**
@@ -211,18 +193,12 @@ class IRCClient
$socket_string = $transport.'://'.$hostname.':'.$port;
if ($socket_string !== $this->_remote_socket_string || ! $this->_connected()) {
if (! \is_string($hostname) || $hostname === '') {
if ($hostname === '') {
echo 'ERROR: IRC host name must not be empty!'.PHP_EOL;
return false;
}
if (! is_numeric($port)) {
echo 'ERROR: IRC port must be a number!'.PHP_EOL;
return false;
}
$this->_remote_host = $hostname;
$this->_remote_port = $port;
$this->_remote_transport = $transport;
@@ -278,7 +254,7 @@ class IRCClient
$this->_realName = $realName;
$this->_password = $password;
if (($password !== null && ! empty($password)) && ! $this->_writeSocket('PASSWORD '.$password)) {
if (empty($password) && ! $this->_writeSocket('PASSWORD '.$password)) {
return false;
}
@@ -336,12 +312,7 @@ class IRCClient
return true;
}
/**
* Quit from IRC.
*
* @param string $message Optional disconnect message.
*/
public function quit(string $message = null): bool
public function quit(?string $message = null): bool
{
if ($this->_connected()) {
$this->_writeSocket('QUIT'.($message === null ? '' : ' :'.$message));
@@ -354,7 +325,7 @@ class IRCClient
/**
* Read the incoming buffer in a loop.
*/
public function readIncoming()
public function readIncoming(): void
{
while (true) {
$this->_readSocket();
@@ -418,9 +389,7 @@ class IRCClient
* Implementation.
* Extended classes will use this function to parse the messages in the channel using $this->_channelData.
*/
protected function processChannelMessages()
{
}
protected function processChannelMessages() {}
/**
* Join a channel.
@@ -435,7 +404,7 @@ class IRCClient
*/
protected function _pong(string $host)
{
if ($this->_writeSocket('PONG '.$host) === false) {
if (! $this->_writeSocket('PONG '.$host)) {
$this->_reconnect();
}
@@ -448,7 +417,7 @@ class IRCClient
/**
* Send PING to a host.
*/
protected function _ping(string $host)
protected function _ping(string $host): void
{
$pong = $this->_writeSocket('PING '.$host);
@@ -466,13 +435,13 @@ class IRCClient
/**
* Attempt to reconnect to IRC.
*/
protected function _reconnect()
protected function _reconnect(): void
{
if (! $this->connect($this->_remote_host, $this->_remote_port, $this->_remote_tls)) {
exit('FATAL: Could not reconnect to ('.$this->_remote_host.') after ('.$this->_reconnectRetries.') tries.'.PHP_EOL);
}
if ($this->_alreadyLoggedIn === false) {
if (! $this->_alreadyLoggedIn) {
if (! $this->login($this->_nickName, $this->_userName, $this->_realName, $this->_password)) {
exit('FATAL: Could not log in to ('.$this->_remote_host.')!'.PHP_EOL);
}
@@ -484,7 +453,7 @@ class IRCClient
/**
* Read response from the IRC server.
*/
protected function _readSocket()
protected function _readSocket(): void
{
$buffer = '';
do {
@@ -530,10 +499,10 @@ class IRCClient
/**
* Write a single character to the socket.
*
* @param string (char) $character A single character.
* @param string $character(char) $character A single character.
* @return int|bool Number of bytes written or false.
*/
protected function _writeSocketChar($character)
protected function _writeSocketChar(string $character): bool|int
{
return @fwrite($this->_socket, $character);
}
@@ -541,7 +510,7 @@ class IRCClient
/**
* Initiate stream socket to IRC server.
*/
protected function _initiateStream()
protected function _initiateStream(): void
{
$this->_closeStream();
@@ -564,7 +533,7 @@ class IRCClient
/**
* Close the socket.
*/
protected function _closeStream()
protected function _closeStream(): void
{
if ($this->_socket !== null) {
$this->_socket = null;