From 7a2315a5e841a0bb52968307bcf07e5845d0ac8c Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 13 Sep 2024 22:22:20 +0200 Subject: [PATCH] Revert "Update code style" This reverts commit 3a39b0c76958d656feed41e7f55251668f47fc10. --- Blacklight/IRCClient.php | 71 +++++++++++++------ Blacklight/NNTP.php | 20 +++--- bootstrap/autoload.php | 22 +++--- resources/smarty/plugins/block.php.php | 4 +- .../smarty/plugins/function.getcatval.php | 4 +- .../function.html_options_multiple.php | 4 +- .../smarty/plugins/load_plugin_dependency.php | 2 +- .../smarty/plugins/modifier.fsize_format.php | 4 +- .../plugins/modifier.phpdate_format.php | 2 +- .../smarty/plugins/shared.make_timestamp.php | 2 +- 10 files changed, 83 insertions(+), 52 deletions(-) diff --git a/Blacklight/IRCClient.php b/Blacklight/IRCClient.php index 8932e5913..516c00a1d 100755 --- a/Blacklight/IRCClient.php +++ b/Blacklight/IRCClient.php @@ -71,6 +71,8 @@ class IRCClient /** * Buffer contents. + * + * @var string */ protected ?string $_buffer = null; @@ -87,12 +89,12 @@ class IRCClient protected array $_channelData = []; /** - * Nickname when we log in. + * Nick name when we log in. */ protected string $_nickName; /** - * Username when we log in. + * User name when we log in. */ protected string $_userName; @@ -148,7 +150,11 @@ class IRCClient */ public function setSocketTimeout(int $timeout) { - $this->_socket_timeout = $timeout; + if (! is_numeric($timeout)) { + echo 'ERROR: IRC socket timeout must be a number!'.PHP_EOL; + } else { + $this->_socket_timeout = $timeout; + } } /** @@ -158,7 +164,11 @@ class IRCClient */ public function setConnectionTimeout(int $timeout) { - $this->_remote_connection_timeout = $timeout; + if (! is_numeric($timeout)) { + echo 'ERROR: IRC connection timeout must be a number!'.PHP_EOL; + } else { + $this->_remote_connection_timeout = $timeout; + } } /** @@ -166,7 +176,11 @@ class IRCClient */ public function setConnectionRetries(int $retries) { - $this->_reconnectRetries = $retries; + if (! is_numeric($retries)) { + echo 'ERROR: IRC connection retries must be a number!'.PHP_EOL; + } else { + $this->_reconnectRetries = $retries; + } } /** @@ -176,7 +190,11 @@ class IRCClient */ public function setReConnectDelay(int $delay) { - $this->_reconnectDelay = $delay; + if (! is_numeric($delay)) { + echo 'ERROR: IRC reconnect delay must be a number!'.PHP_EOL; + } else { + $this->_reconnectDelay = $delay; + } } /** @@ -193,12 +211,18 @@ class IRCClient $socket_string = $transport.'://'.$hostname.':'.$port; if ($socket_string !== $this->_remote_socket_string || ! $this->_connected()) { - if ($hostname === '') { + if (! \is_string($hostname) || $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; @@ -254,7 +278,7 @@ class IRCClient $this->_realName = $realName; $this->_password = $password; - if (empty($password) && ! $this->_writeSocket('PASSWORD '.$password)) { + if (($password !== null && ! empty($password)) && ! $this->_writeSocket('PASSWORD '.$password)) { return false; } @@ -312,7 +336,12 @@ class IRCClient return true; } - public function quit(?string $message = null): bool + /** + * Quit from IRC. + * + * @param string $message Optional disconnect message. + */ + public function quit(string $message = null): bool { if ($this->_connected()) { $this->_writeSocket('QUIT'.($message === null ? '' : ' :'.$message)); @@ -325,7 +354,7 @@ class IRCClient /** * Read the incoming buffer in a loop. */ - public function readIncoming(): void + public function readIncoming() { while (true) { $this->_readSocket(); @@ -389,7 +418,9 @@ 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. @@ -404,7 +435,7 @@ class IRCClient */ protected function _pong(string $host) { - if (! $this->_writeSocket('PONG '.$host)) { + if ($this->_writeSocket('PONG '.$host) === false) { $this->_reconnect(); } @@ -417,7 +448,7 @@ class IRCClient /** * Send PING to a host. */ - protected function _ping(string $host): void + protected function _ping(string $host) { $pong = $this->_writeSocket('PING '.$host); @@ -435,13 +466,13 @@ class IRCClient /** * Attempt to reconnect to IRC. */ - protected function _reconnect(): void + protected function _reconnect() { 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) { + if ($this->_alreadyLoggedIn === false) { if (! $this->login($this->_nickName, $this->_userName, $this->_realName, $this->_password)) { exit('FATAL: Could not log in to ('.$this->_remote_host.')!'.PHP_EOL); } @@ -453,7 +484,7 @@ class IRCClient /** * Read response from the IRC server. */ - protected function _readSocket(): void + protected function _readSocket() { $buffer = ''; do { @@ -499,10 +530,10 @@ class IRCClient /** * Write a single character to the socket. * - * @param string $character(char) $character A single character. + * @param string (char) $character A single character. * @return int|bool Number of bytes written or false. */ - protected function _writeSocketChar(string $character): bool|int + protected function _writeSocketChar($character) { return @fwrite($this->_socket, $character); } @@ -510,7 +541,7 @@ class IRCClient /** * Initiate stream socket to IRC server. */ - protected function _initiateStream(): void + protected function _initiateStream() { $this->_closeStream(); @@ -533,7 +564,7 @@ class IRCClient /** * Close the socket. */ - protected function _closeStream(): void + protected function _closeStream() { if ($this->_socket !== null) { $this->_socket = null; diff --git a/Blacklight/NNTP.php b/Blacklight/NNTP.php index 2821a50d9..bf517ea20 100755 --- a/Blacklight/NNTP.php +++ b/Blacklight/NNTP.php @@ -111,9 +111,9 @@ class NNTP extends \Net_NNTP_Client parent::__construct(); $this->_echo = config('nntmux.echocli'); - $this->_tmux = new Tmux; + $this->_tmux = new Tmux(); $this->_nntpRetries = Settings::settingValue('..nntpretries') !== '' ? (int) Settings::settingValue('..nntpretries') : 0 + 1; - $this->colorCli = new ColorCLI; + $this->colorCli = new ColorCLI(); $this->_currentPort = config('nntmux_nntp.port'); $this->_currentServer = config('nntmux_nntp.server'); $this->_primaryNntpConnections = config('nntmux_nntp.main_nntp_connections'); @@ -521,7 +521,7 @@ class NNTP extends \Net_NNTP_Client $body = ''; $aConnected = false; - $nntp = ($alternate ? new self : null); + $nntp = ($alternate ? new self() : null); // Check if the msgIds are in an array. if (\is_array($identifiers)) { @@ -757,10 +757,10 @@ class NNTP extends \Net_NNTP_Client * @param string $subject string The subject. ie.: $subject = 'Test article'; * @param \Exception|string $body string The message. ie.: $message = 'This is only a test, please disregard.'; * @param string $from string The poster. ie.: $from = ''; - * @param $extra string Extra, separated by \r\n - * ie.: $extra = 'Organization: \r\nNNTP-Posting-Host: <127.0.0.1>'; - * @param $yEnc bool Encode the message with yEnc? - * @param $compress bool Compress the message with GZip? + * @param $extra string Extra, separated by \r\n + * ie.: $extra = 'Organization: \r\nNNTP-Posting-Host: <127.0.0.1>'; + * @param $yEnc bool Encode the message with yEnc? + * @param $compress bool Compress the message with GZip? * @return mixed On success : (bool) True. * On failure : (object) PEAR_Error. * @@ -942,7 +942,7 @@ class NNTP extends \Net_NNTP_Client * headers when XFeature GZip compression is enabled server side. * * @return \Blacklight\NNTP|array|string Our overridden function when compression is enabled. - * parent Parent function when no compression. + * parent Parent function when no compression. */ public function _getTextResponse(): NNTP|array|string { @@ -1280,8 +1280,8 @@ class NNTP extends \Net_NNTP_Client * @param int $port (optional) The port number to connect to, defaults to 119. * @param int $timeout (optional) How many seconds to wait before giving up when connecting. * @param int $socketTimeout (optional) How many seconds to wait before timing out the (blocked) socket. - * @return mixed (bool) On success: True when posting allowed, otherwise false. - * (object) On failure: pear_error + * @return mixed (bool) On success: True when posting allowed, otherwise false. + * (object) On failure: pear_error */ public function connect($host = null, $encryption = null, $port = null, $timeout = 15, $socketTimeout = 120) { diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index ed22ec486..c8f53a99c 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -1,17 +1,17 @@ make(); + $repository = RepositoryBuilder::createWithDefaultAdapters()->make(); -$dotenv = Dotenv::create($repository, dirname(__DIR__, 1), null)->load(); + $dotenv = Dotenv::create($repository, dirname(__DIR__, 1), null)->load(); -/** @var Kernel $kernel */ -$kernel = app(Kernel::class); -$kernel->bootstrap(); + /** @var Kernel $kernel */ + $kernel = app(Kernel::class); + $kernel->bootstrap(); diff --git a/resources/smarty/plugins/block.php.php b/resources/smarty/plugins/block.php.php index 44aeae824..76c054af0 100755 --- a/resources/smarty/plugins/block.php.php +++ b/resources/smarty/plugins/block.php.php @@ -7,8 +7,8 @@ /** * Smarty {php}{/php} block plugin. * - * @param string $content contents of the block - * @param object $template template object + * @param string $content contents of the block + * @param object $template template object * @param bool $ &$repeat repeat flag * @return string content re-formatted */ diff --git a/resources/smarty/plugins/function.getcatval.php b/resources/smarty/plugins/function.getcatval.php index 5ec5ba8db..4021c60f6 100755 --- a/resources/smarty/plugins/function.getcatval.php +++ b/resources/smarty/plugins/function.getcatval.php @@ -24,8 +24,8 @@ use App\Models\Category; * * @usage {getcatval category=BOOKS_COMICS} * - * @param string $params Name of constant whose value to return. - * @return Value of the specified Category constant. + *@param string $params Name of constant whose value to return. + *@return Value of the specified Category constant. */ function smarty_function_getcatval($params) { diff --git a/resources/smarty/plugins/function.html_options_multiple.php b/resources/smarty/plugins/function.html_options_multiple.php index f2741fe56..6ddc49d32 100755 --- a/resources/smarty/plugins/function.html_options_multiple.php +++ b/resources/smarty/plugins/function.html_options_multiple.php @@ -31,8 +31,8 @@ require_once 'load_plugin_dependency.php'; * @author Monte Ohrt * @author Ralf Strehle (minor optimization) * - * @param array $params parameters - * @param Smarty_Internal_Template $template template object + * @param array $params parameters + * @param Smarty_Internal_Template $template template object * @return string * * @uses smarty_function_escape_special_chars() diff --git a/resources/smarty/plugins/load_plugin_dependency.php b/resources/smarty/plugins/load_plugin_dependency.php index fa0943624..9c94a5926 100644 --- a/resources/smarty/plugins/load_plugin_dependency.php +++ b/resources/smarty/plugins/load_plugin_dependency.php @@ -7,7 +7,7 @@ function load_plugin_dependency($filename) global $smarty; if (! isset($smarty)) { - $smarty = new Smarty; + $smarty = new Smarty(); } switch (true) { diff --git a/resources/smarty/plugins/modifier.fsize_format.php b/resources/smarty/plugins/modifier.fsize_format.php index e49cc6382..90ee350e7 100755 --- a/resources/smarty/plugins/modifier.fsize_format.php +++ b/resources/smarty/plugins/modifier.fsize_format.php @@ -47,10 +47,10 @@ function smarty_modifier_fsize_format($size, $format = '', $precision = 2, $dec_ $sizes = array_reverse($sizes, true); } //~ get "human" filesize - foreach ($sizes as $unit => $bytes) { + foreach ($sizes as $unit => $bytes) { if ($size > $bytes || $unit == $format) { //~ return formatted size - return number_format($size / $bytes, $precision, $dec_point, $thousands_sep).' '.$unit; + return number_format($size / $bytes, $precision, $dec_point, $thousands_sep).' '.$unit; } //~ end if } //~ end foreach } //~ end function diff --git a/resources/smarty/plugins/modifier.phpdate_format.php b/resources/smarty/plugins/modifier.phpdate_format.php index b255e055e..aad198338 100755 --- a/resources/smarty/plugins/modifier.phpdate_format.php +++ b/resources/smarty/plugins/modifier.phpdate_format.php @@ -14,7 +14,7 @@ use Ytake\LaravelSmarty\Smarty; */ // Fix by nZEDb if (! isset($smarty)) { - $smarty = new Smarty; + $smarty = new Smarty(); } switch (true) { case is_string($smarty->getPluginsDir()) && is_dir($smarty->getPluginsDir()): diff --git a/resources/smarty/plugins/shared.make_timestamp.php b/resources/smarty/plugins/shared.make_timestamp.php index ec5276deb..af75c1204 100644 --- a/resources/smarty/plugins/shared.make_timestamp.php +++ b/resources/smarty/plugins/shared.make_timestamp.php @@ -9,7 +9,7 @@ * * @author Monte Ohrt * - * @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime() + * @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime() * @return int */ function smarty_make_timestamp($string)