From 3a39b0c76958d656feed41e7f55251668f47fc10 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 13 Sep 2024 12:37:51 +0200 Subject: [PATCH] Update code style --- 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, 52 insertions(+), 83 deletions(-) diff --git a/Blacklight/IRCClient.php b/Blacklight/IRCClient.php index 516c00a1d..8932e5913 100755 --- a/Blacklight/IRCClient.php +++ b/Blacklight/IRCClient.php @@ -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; diff --git a/Blacklight/NNTP.php b/Blacklight/NNTP.php index bf517ea20..2821a50d9 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 c8f53a99c..ed22ec486 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 76c054af0..44aeae824 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 4021c60f6..5ec5ba8db 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 6ddc49d32..f2741fe56 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 9c94a5926..fa0943624 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 90ee350e7..e49cc6382 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 aad198338..b255e055e 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 af75c1204..ec5276deb 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)