From 5c801955630eea77dc50159f9906c7f325704cc9 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Thu, 21 Dec 2023 20:50:07 -0800 Subject: [PATCH] Fix PHP lint issues --- Sources/Actions/Admin/Find.php | 2 +- Sources/Cache/APIs/Apcu.php | 4 +-- Sources/Cache/APIs/FileBased.php | 11 +++--- Sources/Cache/APIs/MemcacheImplementation.php | 6 ++-- .../Cache/APIs/MemcachedImplementation.php | 6 ++-- Sources/Cache/APIs/Postgres.php | 6 ++-- Sources/Cache/APIs/Sqlite.php | 6 ++-- Sources/Cache/APIs/Zend.php | 6 ++-- Sources/Cache/CacheApi.php | 2 +- Sources/Cache/CacheApiInterface.php | 6 ++-- Sources/Db/APIs/MySQL.php | 29 ++++++++-------- Sources/Db/APIs/PostgreSQL.php | 34 +++++++++---------- Sources/Db/DatabaseApiInterface.php | 32 ++++++++--------- Sources/PackageManager/FtpConnection.php | 14 ++++---- Sources/PackageManager/PackageManager.php | 1 + Sources/PackageManager/SubsPackage.php | 9 +++-- Sources/PackageManager/XmlArray.php | 10 +++--- Sources/Search/APIs/Custom.php | 2 +- Sources/Search/APIs/Fulltext.php | 2 +- Sources/Search/SearchApi.php | 2 +- Sources/TOTP/Auth.php | 2 -- Sources/User.php | 4 +-- Sources/Utils.php | 2 +- Sources/WebFetch/APIs/CurlFetcher.php | 2 +- Sources/WebFetch/APIs/FtpFetcher.php | 2 +- Sources/WebFetch/APIs/SocketFetcher.php | 12 +++---- 26 files changed, 105 insertions(+), 109 deletions(-) diff --git a/Sources/Actions/Admin/Find.php b/Sources/Actions/Admin/Find.php index d4ff43e1e7..6a9d69ed63 100644 --- a/Sources/Actions/Admin/Find.php +++ b/Sources/Actions/Admin/Find.php @@ -20,10 +20,10 @@ use SMF\IntegrationHook; use SMF\Lang; use SMF\Menu; +use SMF\PackageManager\XmlArray; use SMF\User; use SMF\Utils; use SMF\WebFetch\WebFetchApi; -use SMF\PackageManager\XmlArray; /** * Provides the search functionality inside the admin control panel. diff --git a/Sources/Cache/APIs/Apcu.php b/Sources/Cache/APIs/Apcu.php index 0fcfed878f..282f921b6c 100644 --- a/Sources/Cache/APIs/Apcu.php +++ b/Sources/Cache/APIs/Apcu.php @@ -54,7 +54,7 @@ public function connect(): bool /** * {@inheritDoc} */ - public function getData(string $key, int|null $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); @@ -66,7 +66,7 @@ public function getData(string $key, int|null $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); diff --git a/Sources/Cache/APIs/FileBased.php b/Sources/Cache/APIs/FileBased.php index 3cb78b85a3..9586e48f4e 100644 --- a/Sources/Cache/APIs/FileBased.php +++ b/Sources/Cache/APIs/FileBased.php @@ -75,7 +75,7 @@ public function connect(): bool /** * {@inheritDoc} */ - public function getData(string $key, int|null $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $file = sprintf( '%s/data_%s.cache', @@ -98,7 +98,7 @@ public function getData(string $key, int|null $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $file = sprintf( '%s/data_%s.cache', @@ -109,8 +109,9 @@ public function putData(string $key, mixed $value, int|null $ttl = null): mixed if ($value === null) { @unlink($file); + return true; - } else { + } $cache_data = json_encode( [ 'expiration' => time() + $ttl, @@ -128,7 +129,7 @@ public function putData(string $key, mixed $value, int|null $ttl = null): mixed } return true; - } + } /** @@ -198,7 +199,7 @@ public function cacheSettings(array &$config_vars): void * @param string $dir A valid path * @return bool If this was successful or not. */ - public function setCachedir(string $dir = null): void + public function setCachedir(?string $dir = null): void { // If its invalid, use SMF's. if (is_null($dir) || !is_writable($dir)) { diff --git a/Sources/Cache/APIs/MemcacheImplementation.php b/Sources/Cache/APIs/MemcacheImplementation.php index 9b8d06c97a..f7e3f9b4cf 100644 --- a/Sources/Cache/APIs/MemcacheImplementation.php +++ b/Sources/Cache/APIs/MemcacheImplementation.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache\APIs; use Memcache; @@ -124,7 +124,7 @@ public function connect(): bool /** * {@inheritDoc} */ - public function getData(string $key, int $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); @@ -141,7 +141,7 @@ public function getData(string $key, int $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); diff --git a/Sources/Cache/APIs/MemcachedImplementation.php b/Sources/Cache/APIs/MemcachedImplementation.php index dfb1044c5e..ceeae0406f 100644 --- a/Sources/Cache/APIs/MemcachedImplementation.php +++ b/Sources/Cache/APIs/MemcachedImplementation.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache\APIs; use Memcached; @@ -130,7 +130,7 @@ protected function addServers(): bool /** * {@inheritDoc} */ - public function getData(string $key, int|null $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); @@ -147,7 +147,7 @@ public function getData(string $key, int|null $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); diff --git a/Sources/Cache/APIs/Postgres.php b/Sources/Cache/APIs/Postgres.php index e0076af4c9..f518313619 100644 --- a/Sources/Cache/APIs/Postgres.php +++ b/Sources/Cache/APIs/Postgres.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache\APIs; use SMF\Cache\CacheApi; @@ -137,7 +137,7 @@ public function isSupported(bool $test = false): bool /** * {@inheritDoc} */ - public function getData(string $key, int $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $result = pg_execute($this->db_connection, 'smf_cache_get_data', [$key, time()]); @@ -153,7 +153,7 @@ public function getData(string $key, int $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $ttl = time() + (int) ($ttl !== null ? $ttl : $this->ttl); diff --git a/Sources/Cache/APIs/Sqlite.php b/Sources/Cache/APIs/Sqlite.php index 310c3d9ea1..55210a085f 100755 --- a/Sources/Cache/APIs/Sqlite.php +++ b/Sources/Cache/APIs/Sqlite.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache\APIs; use SMF\Cache\CacheApi; @@ -85,7 +85,7 @@ public function isSupported(bool $test = false): bool /** * {@inheritDoc} */ - public function getData(string $key, int $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $query = 'SELECT value FROM cache WHERE key = \'' . $this->cacheDB->escapeString($key) . '\' AND ttl >= ' . time() . ' LIMIT 1'; $result = $this->cacheDB->query($query); @@ -102,7 +102,7 @@ public function getData(string $key, int $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $ttl = time() + (int) ($ttl !== null ? $ttl : $this->ttl); diff --git a/Sources/Cache/APIs/Zend.php b/Sources/Cache/APIs/Zend.php index fbcd95ce8b..aadb57ba4f 100644 --- a/Sources/Cache/APIs/Zend.php +++ b/Sources/Cache/APIs/Zend.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache\APIs; use SMF\Cache\CacheApi; @@ -51,7 +51,7 @@ public function connect(): bool /** * {@inheritDoc} */ - public function getData(string $key, int $ttl = null): mixed + public function getData(string $key, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); @@ -70,7 +70,7 @@ public function getData(string $key, int $ttl = null): mixed /** * {@inheritDoc} */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed + public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); diff --git a/Sources/Cache/CacheApi.php b/Sources/Cache/CacheApi.php index 98d9539ec5..a2c3bd5d77 100644 --- a/Sources/Cache/CacheApi.php +++ b/Sources/Cache/CacheApi.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache; use SMF\BackwardCompatibility; diff --git a/Sources/Cache/CacheApiInterface.php b/Sources/Cache/CacheApiInterface.php index 59951cd16b..63ba859d76 100644 --- a/Sources/Cache/CacheApiInterface.php +++ b/Sources/Cache/CacheApiInterface.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); - + namespace SMF\Cache; if (!defined('SMF')) { @@ -45,7 +45,7 @@ public function connect(): bool; * @return mixed The result from the cache, if there is no data or it is invalid, we return null. * @todo Separate existence checking into its own method */ - public function getData(string $key, int|null $ttl = null): mixed; + public function getData(string $key, ?int $ttl = null): mixed; /** * Stores a value, regardless of whether or not the key already exists (in @@ -58,7 +58,7 @@ public function getData(string $key, int|null $ttl = null): mixed; * @return mixed Whether or not we could save this to the cache. * @todo Separate deletion into its own method */ - public function putData(string $key, mixed $value, int|null $ttl = null): mixed; + public function putData(string $key, mixed $value, ?int $ttl = null): mixed; /** * Clean out the cache. diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index 8cecb56947..234344ea4d 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -120,7 +120,7 @@ class MySQL extends DatabaseApi implements DatabaseApiInterface /** * {@inheritDoc} */ - public function query(string $identifier, string $db_string, array $db_values = [], object $connection = null): object|bool + public function query(string $identifier, string $db_string, array $db_values = [], ?object $connection = null): object|bool { // Comments that are allowed in a query are preg_removed. $allowed_comments_from = [ @@ -256,7 +256,7 @@ public function query(string $identifier, string $db_string, array $db_values = /** * {@inheritDoc} */ - public function quote(string $db_string, array $db_values, object $connection = null): string + public function quote(string $db_string, array $db_values, ?object $connection = null): string { // Only bother if there's something to replace. if (strpos($db_string, '{') !== false) { @@ -305,13 +305,14 @@ public function fetch_all(object $request): array public function free_result(object $result): bool { mysqli_free_result($result); + return true; } /** * {@inheritDoc} */ - public function insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, object $connection = null): int|array|null + public function insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, ?object $connection = null): int|array|null { $connection = $connection ?? $this->connection; @@ -508,7 +509,7 @@ public function insert(string $method, string $table, array $columns, array $dat /** * {@inheritDoc} */ - public function insert_id(string $table, string $field = null, object $connection = null): int + public function insert_id(string $table, ?string $field = null, ?object $connection = null): int { // MySQL doesn't need the table or field information. return mysqli_insert_id($connection ?? $this->connection); @@ -541,7 +542,7 @@ public function num_fields(object $result): int /** * {@inheritDoc} */ - public function escape_string(string $string, object $connection = null): string + public function escape_string(string $string, ?object $connection = null): string { return mysqli_real_escape_string($connection ?? $this->connection, $string); } @@ -557,7 +558,7 @@ public function unescape_string(string $string): string /** * {@inheritDoc} */ - public function server_info(object $connection = null): string + public function server_info(?object $connection = null): string { return mysqli_get_server_info($connection ?? $this->connection); } @@ -565,7 +566,7 @@ public function server_info(object $connection = null): string /** * {@inheritDoc} */ - public function affected_rows(object $connection = null): int + public function affected_rows(?object $connection = null): int { return mysqli_affected_rows($connection ?? $this->connection); } @@ -573,7 +574,7 @@ public function affected_rows(object $connection = null): int /** * {@inheritDoc} */ - public function transaction(string $type = 'commit', object $connection = null): bool + public function transaction(string $type = 'commit', ?object $connection = null): bool { $type = strtoupper($type); @@ -603,7 +604,7 @@ public function error(object $connection): string /** * {@inheritDoc} */ - public function select(string $database, object $connection = null): bool + public function select(string $database, ?object $connection = null): bool { return mysqli_select_db($connection ?? $this->connection, $database); } @@ -639,7 +640,7 @@ public function is_resource(mixed $result): bool /** * {@inheritDoc} */ - public function ping(object $connection = null): bool + public function ping(?object $connection = null): bool { return mysqli_ping($connection ?? $this->connection); } @@ -1152,7 +1153,7 @@ public function allow_persistent(): bool /** * {@inheritDoc} */ - public function search_query(string $identifier, string $db_string, array $db_values = [], object $connection = null): object|bool + public function search_query(string $identifier, string $db_string, array $db_values = [], ?object $connection = null): object|bool { return $this->query($identifier, $db_string, $db_values, $connection); } @@ -1197,7 +1198,7 @@ public function create_word_search(string $size): void /** * {@inheritDoc} */ - public function search_language(): string|null + public function search_language(): ?string { return null; } @@ -1340,7 +1341,7 @@ public function add_index(string $table_name, array $index_info, array $paramete /** * {@inheritDoc} */ - public function calculate_type(string $type_name, int $type_size = null, bool $reverse = false): array + public function calculate_type(string $type_name, ?int $type_size = null, bool $reverse = false): array { // MySQL is actually the generic baseline. @@ -2274,7 +2275,7 @@ protected function replacement__callback(array $matches): string * @param int $line What line of $file the code which generated the error is on * @return void|array Returns an array with the file and line if $error_type is 'return' */ - protected function error_backtrace(string $error_message, string $log_message = '', string|int|bool $error_type = false, string $file = null, int $line = null): array|null + protected function error_backtrace(string $error_message, string $log_message = '', string|int|bool $error_type = false, ?string $file = null, ?int $line = null): ?array { if (empty($log_message)) { $log_message = $error_message; diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index 6cd5072802..450e905743 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -140,7 +140,7 @@ class PostgreSQL extends DatabaseApi implements DatabaseApiInterface /** * {@inheritDoc} */ - public function query(string $identifier, string $db_string, array $db_values = [], object $connection = null): object|bool + public function query(string $identifier, string $db_string, array $db_values = [], ?object $connection = null): object|bool { // Decide which connection to use. $connection = $connection ?? $this->connection; @@ -322,7 +322,7 @@ public function query(string $identifier, string $db_string, array $db_values = /** * {@inheritDoc} */ - public function quote(string $db_string, array $db_values, object $connection = null): string + public function quote(string $db_string, array $db_values, ?object $connection = null): string { // Only bother if there's something to replace. if (strpos($db_string, '{') !== false) { @@ -376,7 +376,7 @@ public function free_result(object $result): bool /** * {@inheritDoc} */ - public function insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, object $connection = null): int|array|null + public function insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, ?object $connection = null): int|array|null { $connection = $connection ?? $this->connection; @@ -533,7 +533,7 @@ public function insert(string $method, string $table, array $columns, array $dat /** * {@inheritDoc} */ - public function insert_id(string $table, string $field = null, object $connection = null): int + public function insert_id(string $table, ?string $field = null, ?object $connection = null): int { $table = str_replace('{db_prefix}', $this->prefix, $table); @@ -580,7 +580,7 @@ public function num_fields(object $result): int /** * {@inheritDoc} */ - public function escape_string(string $string, object $connection = null): string + public function escape_string(string $string, ?object $connection = null): string { return pg_escape_string($connection ?? $this->connection, $string); } @@ -596,7 +596,7 @@ public function unescape_string(string $string): string /** * {@inheritDoc} */ - public function server_info(object $connection = null): string + public function server_info(?object $connection = null): string { $version = pg_version(); @@ -606,7 +606,7 @@ public function server_info(object $connection = null): string /** * {@inheritDoc} */ - public function affected_rows(object $connection = null): int + public function affected_rows(?object $connection = null): int { if ($this->replace_result) { return $this->replace_result; @@ -622,7 +622,7 @@ public function affected_rows(object $connection = null): int /** * {@inheritDoc} */ - public function transaction(string $type = 'commit', object $connection = null): bool + public function transaction(string $type = 'commit', ?object $connection = null): bool { $type = strtoupper($type); @@ -631,12 +631,12 @@ public function transaction(string $type = 'commit', object $connection = null): $return = @pg_query($connection ?? $this->connection, $type); - if (is_bool($return)){ + if (is_bool($return)) { return $return; } - else { + return is_a($return, 'PgSql\Result'); - } + } return false; @@ -661,7 +661,7 @@ public function error(object $connection): string /** * {@inheritDoc} */ - public function select(string $database, object $connection = null): bool + public function select(string $database, ?object $connection = null): bool { return true; } @@ -697,7 +697,7 @@ public function is_resource(mixed $result): bool /** * {@inheritDoc} */ - public function ping(object $connection = null): bool + public function ping(?object $connection = null): bool { return pg_ping($connection ?? $this->connection); } @@ -1101,7 +1101,7 @@ public function allow_persistent(): bool /** * {@inheritDoc} */ - public function search_query(string $identifier, string $db_string, array $db_values = [], object $connection = null): object|bool + public function search_query(string $identifier, string $db_string, array $db_values = [], ?object $connection = null): object|bool { $replacements = [ 'create_tmp_log_search_topics' => [ @@ -1201,7 +1201,7 @@ public function create_word_search($size): void /** * {@inheritDoc} */ - public function search_language(): string|null + public function search_language(): ?string { if (!empty(Config::$modSettings['search_language'])) { $this->language_ftx = Config::$modSettings['search_language']; @@ -1372,7 +1372,7 @@ public function add_index(string $table_name, array $index_info, array $paramete /** * {@inheritDoc} */ - public function calculate_type(string $type_name, int $type_size = null, bool $reverse = false): array + public function calculate_type(string $type_name, ?int $type_size = null, bool $reverse = false): array { // Let's be sure it's lowercase MySQL likes both, others no. $type_name = strtolower($type_name); @@ -2386,7 +2386,7 @@ protected function replacement__callback(array $matches): string * @param int $line What line of $file the code which generated the error is on * @return void|array Returns an array with the file and line if $error_type is 'return' */ - protected function error_backtrace(string $error_message, string $log_message = '', string|int|bool $error_type = false, string $file = null, int $line = null): array|null + protected function error_backtrace(string $error_message, string $log_message = '', string|int|bool $error_type = false, ?string $file = null, ?int $line = null): ?array { if (empty($log_message)) { $log_message = $error_message; diff --git a/Sources/Db/DatabaseApiInterface.php b/Sources/Db/DatabaseApiInterface.php index 68e17454f8..5087330c83 100644 --- a/Sources/Db/DatabaseApiInterface.php +++ b/Sources/Db/DatabaseApiInterface.php @@ -29,7 +29,7 @@ interface DatabaseApiInterface * @param object $connection = null The connection to use (null to use $db_connection) * @return object|bool Returns a query result resource (for SELECT queries), true (for UPDATE queries) or false if the query failed. */ - public function query(string $identifier, string $db_string, array $db_values = [], object $connection = null): object|bool; + public function query(string $identifier, string $db_string, array $db_values = [], ?object $connection = null): object|bool; /** * Prepares a query string for execution, but does not perform the query. @@ -39,7 +39,7 @@ public function query(string $identifier, string $db_string, array $db_values = * @param object $connection = null The connection to use (null to use $db_connection). * @return string The string with the values inserted. */ - public function quote(string $db_string, array $db_values, object $connection = null): string; + public function quote(string $db_string, array $db_values, ?object $connection = null): string; /** * Fetch the next row of a result set as an enumerated array. @@ -78,11 +78,11 @@ public function free_result(object $result): bool; * @param array $columns An array of the columns we're inserting the data into. Should contain 'column' => 'datatype' pairs. * @param array $data The data to insert. * @param array $keys The keys for the table, needs to be not empty on replace mode. - * @param int returnmode 0 = nothing(default), 1 = last row id, 2 = all rows id as array. * @param object $connection = null The connection (if null, $db_connection is used). + * @param int returnmode 0 = nothing(default), 1 = last row id, 2 = all rows id as array. * @return int The ID of the most recently inserted row. */ - public function insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, object $connection = null): int|array|null; + public function insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, ?object $connection = null): int|array|null; /** * Gets the ID of the most recently inserted row. @@ -92,7 +92,7 @@ public function insert(string $method, string $table, array $columns, array $dat * @param object $connection = null The connection (if null, $db_connection is used) * @return int The ID of the most recently inserted row */ - public function insert_id(string $table, string $field = null, object $connection = null): int; + public function insert_id(string $table, ?string $field = null, ?object $connection = null): int; /** * Gets the number of rows in a result set. @@ -105,8 +105,8 @@ public function num_rows(object $result): int; /** * Adjusts the result pointer to an arbitrary row in a query result. * - * @param object $request A query result resource. * @param int $offset The row offset. + * @param object $request A query result resource. * @return bool True on success, or false on failuer. */ public function data_seek(object $result, int $offset): bool; @@ -123,11 +123,11 @@ public function num_fields(object $result): int; * Escapes special characters in a string for use in an SQL statement, * taking into account the current character set of the connection. * - * @param string The unescaped string. * @param object $connection = null The connection to use (null to use $db_connection). + * @param string The unescaped string. * @return string The escaped string. */ - public function escape_string(string $string, object $connection = null): string; + public function escape_string(string $string, ?object $connection = null): string; /** * Reverses the escape_string function. @@ -143,7 +143,7 @@ public function unescape_string(string $string): string; * @param object $connection The connection to use (if null, $db_connection is used) * @return string The server info. */ - public function server_info(object $connection = null): string; + public function server_info(?object $connection = null): string; /** * Gets the number of rows affected by the last query. @@ -153,7 +153,7 @@ public function server_info(object $connection = null): string; * @param object $connection A connection to use (if null, $db_connection is used) * @return int The number of affected rows. */ - public function affected_rows(object $connection = null): int; + public function affected_rows(?object $connection = null): int; /** * Do a transaction. @@ -162,7 +162,7 @@ public function affected_rows(object $connection = null): int; * @param object $connection The connection to use (if null, $db_connection is used) * @return bool True if successful, false otherwise */ - public function transaction(string $type = 'commit', object $connection = null): bool; + public function transaction(string $type = 'commit', ?object $connection = null): bool; /** * Get the last error message string. @@ -181,7 +181,7 @@ public function error(object $connection): string; * @param object $connection The connection object (if null, $db_connection is used) * @return bool Whether the database was selected */ - public function select(string $database, object $connection = null): bool; + public function select(string $database, ?object $connection = null): bool; /** * Escape the LIKE wildcards so that they match the character and not the wildcard. @@ -207,7 +207,7 @@ public function is_resource(mixed $result): bool; * @param object $connection The connection object (if null, $db_connection is used) * @return bool True on success, or false on failure. */ - public function ping(object $connection = null): bool; + public function ping(?object $connection = null): bool; /** * Save errors in the database safely. @@ -332,7 +332,7 @@ public function allow_persistent(): bool; * @param object $connection The current DB connection resource * @return resource The query result resource from $this->query() */ - public function search_query(string $identifier, string $db_string, array $db_values = [], object $connection = null): object|bool; + public function search_query(string $identifier, string $db_string, array $db_values = [], ?object $connection = null): object|bool; /** * This function will tell you whether this database type supports this search type. @@ -354,7 +354,7 @@ public function create_word_search(string $size): void; * * @return string|null The PostgreSQL search language, or null for MySQL. */ - public function search_language(): string|null; + public function search_language(): ?string; /******************************************* * Methods that formerly lived in DbPackages @@ -392,7 +392,7 @@ public function add_index(string $table_name, array $index_info, array $paramete * @param bool $reverse * @return array An array containing the appropriate type and size for this DB type */ - public function calculate_type(string $type_name, int $type_size = null, bool $reverse = false): array; + public function calculate_type(string $type_name, ?int $type_size = null, bool $reverse = false): array; /** * Change a column. You only need to specify the column attributes that are changing. diff --git a/Sources/PackageManager/FtpConnection.php b/Sources/PackageManager/FtpConnection.php index b37f0b16fe..4119ff3a28 100644 --- a/Sources/PackageManager/FtpConnection.php +++ b/Sources/PackageManager/FtpConnection.php @@ -56,9 +56,8 @@ public function __construct( int $ftp_port = 21, string $ftp_user = 'anonymous', #[\SensitiveParameter] - string $ftp_pass = 'ftpclient@simplemachines.org' - ) - { + string $ftp_pass = 'ftpclient@simplemachines.org', + ) { // Initialize variables. $this->connection = 'no_connection'; $this->error = false; @@ -82,9 +81,8 @@ public function connect( int $ftp_port = 21, string $ftp_user = 'anonymous', #[\SensitiveParameter] - string $ftp_pass = 'ftpclient@simplemachines.org' - ): void - { + string $ftp_pass = 'ftpclient@simplemachines.org', + ): void { if (strpos($ftp_server, 'ftp://') === 0) { $ftp_server = substr($ftp_server, 6); } elseif (strpos($ftp_server, 'ftps://') === 0) { @@ -400,7 +398,7 @@ public function list_dir(string $ftp_path = '', bool $search = false): string|bo * @param string $listing A directory listing or null to generate one * @return string|bool The name of the file or false if it wasn't found */ - public function locate(string $file, string $listing = null): string|bool + public function locate(string $file, ?string $listing = null): string|bool { if ($listing === null) { $listing = $this->list_dir('', true); @@ -478,7 +476,7 @@ public function create_dir(string $ftp_dir): bool * @param string $lookup_file The name of a file in the specified path * @return array An array of detected info - username, path from FTP root and whether or not the current path was found */ - public function detect_path(string $filesystem_path, string $lookup_file = null): array + public function detect_path(string $filesystem_path, ?string $lookup_file = null): array { $username = ''; diff --git a/Sources/PackageManager/PackageManager.php b/Sources/PackageManager/PackageManager.php index 3eddf91028..edcfbc5a4c 100644 --- a/Sources/PackageManager/PackageManager.php +++ b/Sources/PackageManager/PackageManager.php @@ -2047,6 +2047,7 @@ public function permissions(): void // If we're submitting then let's move on to another function to keep things cleaner.. if (isset($_POST['action_changes'])) { $this->PackagePermissionsAction(); + return; } diff --git a/Sources/PackageManager/SubsPackage.php b/Sources/PackageManager/SubsPackage.php index 6a711c06f3..48a6d69702 100644 --- a/Sources/PackageManager/SubsPackage.php +++ b/Sources/PackageManager/SubsPackage.php @@ -342,7 +342,7 @@ public static function read_tgz_data(string $data, ?string $destination, bool $s * @param array $files_to_extract * @return mixed If destination is null, return a short array of a few file details optionally delimited by $files_to_extract. If $single_file is true, return contents of a file as a string; false otherwise */ - public static function read_zip_data(string $data, string $destination, bool $single_file = false, bool $overwrite = false, array $files_to_extract = null): mixed + public static function read_zip_data(string $data, string $destination, bool $single_file = false, bool $overwrite = false, ?array $files_to_extract = null): mixed { umask(0); @@ -943,7 +943,7 @@ public static function list_restoreFiles(mixed $dummy1, mixed $dummy2, mixed $du * @param bool $return Whether to return an array of file info if there's an error * @return array An array of file info */ - public static function packageRequireFTP(string $destination_url, ?array $files = null,bool $return = false): array + public static function packageRequireFTP(string $destination_url, ?array $files = null, bool $return = false): array { // Try to make them writable the manual way. if ($files !== null) { @@ -2933,9 +2933,8 @@ public static function package_chmod(string $filename, string $perm_state = 'wri */ public static function package_crypt( #[\SensitiveParameter] - string $pass - ): string - { + string $pass, + ): string { $n = strlen($pass); $salt = session_id(); diff --git a/Sources/PackageManager/XmlArray.php b/Sources/PackageManager/XmlArray.php index 26f579134e..33dee015ad 100644 --- a/Sources/PackageManager/XmlArray.php +++ b/Sources/PackageManager/XmlArray.php @@ -51,7 +51,7 @@ class XmlArray * @param int $level The debug level. Specifies whether notices should be generated for missing elements and attributes. * @param bool $is_clone default false. If is_clone is true, the XmlArray is cloned from another - used internally only. */ - public function __construct(string|array $data, bool $auto_trim = false, int $level = null, bool $is_clone = false) + public function __construct(string|array $data, bool $auto_trim = false, ?int $level = null, bool $is_clone = false) { // If we're using this try to get some more memory. Config::setMemoryLimit('32M'); @@ -195,7 +195,7 @@ public function path(string $path, bool $return_full = false): XmlArray|string|f // Create the right type of class... $newClass = get_class($this); - // Return a new XmlArray for the result. + // Return a new XmlArray for the result. return $array === false ? false : new $newClass($array, $this->trim, $this->debug_level, true); } @@ -301,7 +301,7 @@ public function set(string $path): array * @param string $path The path to the element. (optional) * @return string Xml-formatted string. */ - public function create_xml(string $path = null): string + public function create_xml(?string $path = null): string { // Was a path specified? If so, use that array. if ($path !== null) { @@ -331,7 +331,7 @@ public function create_xml(string $path = null): string * @param string $path The path to output. * @return array An array of XML data */ - public function to_array(string $path = null): array + public function to_array(?string $path = null): array { // Are we doing a specific path? if ($path !== null) { @@ -508,7 +508,7 @@ protected function _parse(string $data): array * @param null|int $indent How many levels to indent the elements (null = no indent) * @return string The formatted XML */ - protected function _xml(array $array, null|int $indent): string + protected function _xml(array $array, ?int $indent): string { $indentation = $indent !== null ? ' ' . str_repeat(' ', $indent) : ''; diff --git a/Sources/Search/APIs/Custom.php b/Sources/Search/APIs/Custom.php index 18fd18a7e2..832d7a8270 100644 --- a/Sources/Search/APIs/Custom.php +++ b/Sources/Search/APIs/Custom.php @@ -18,8 +18,8 @@ use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Search\SearchApi; -use SMF\Utils; use SMF\Search\SearchApiInterface; +use SMF\Utils; /** * Used for the "custom search index" option diff --git a/Sources/Search/APIs/Fulltext.php b/Sources/Search/APIs/Fulltext.php index 6b031a15fd..9e6a71dec5 100644 --- a/Sources/Search/APIs/Fulltext.php +++ b/Sources/Search/APIs/Fulltext.php @@ -18,8 +18,8 @@ use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Search\SearchApi; -use SMF\Utils; use SMF\Search\SearchApiInterface; +use SMF\Utils; /** * Class Fulltext diff --git a/Sources/Search/SearchApi.php b/Sources/Search/SearchApi.php index aba983dd3c..6ccb6485b9 100644 --- a/Sources/Search/SearchApi.php +++ b/Sources/Search/SearchApi.php @@ -15,6 +15,7 @@ namespace SMF\Search; +use SMF\Actions\Search; use SMF\BackwardCompatibility; use SMF\Config; use SMF\Db\DatabaseApi as Db; @@ -24,7 +25,6 @@ use SMF\PackageManager\SubsPackage; use SMF\User; use SMF\Utils; -use SMF\Actions\Search; /** * Class SearchApi diff --git a/Sources/TOTP/Auth.php b/Sources/TOTP/Auth.php index a993e387a5..bbacdd54f4 100644 --- a/Sources/TOTP/Auth.php +++ b/Sources/TOTP/Auth.php @@ -23,8 +23,6 @@ namespace SMF\TOTP; -use SMF\Utils; - /** * Class Auth * diff --git a/Sources/User.php b/Sources/User.php index fa82dfc747..9b22fe2f51 100644 --- a/Sources/User.php +++ b/Sources/User.php @@ -14,13 +14,13 @@ namespace SMF; use SMF\Actions\Admin\ACP; +use SMF\Actions\Admin\Bans; use SMF\Actions\Login2; +use SMF\Actions\Logout; use SMF\Actions\Moderation\ReportedContent; use SMF\Cache\CacheApi; use SMF\Db\DatabaseApi as Db; use SMF\PersonalMessage\PM; -use SMF\Actions\Admin\Bans; -use SMF\Actions\Logout; /** * Represents a user, including both guests and registered members. diff --git a/Sources/Utils.php b/Sources/Utils.php index 2f72265551..03be77a5dd 100644 --- a/Sources/Utils.php +++ b/Sources/Utils.php @@ -13,7 +13,7 @@ namespace SMF; -use SMF\Db\DatabaseApi AS Db; +use SMF\Db\DatabaseApi as Db; /** * Holds some widely used stuff, like $context and $smcFunc. diff --git a/Sources/WebFetch/APIs/CurlFetcher.php b/Sources/WebFetch/APIs/CurlFetcher.php index d3a2537b74..541231983c 100644 --- a/Sources/WebFetch/APIs/CurlFetcher.php +++ b/Sources/WebFetch/APIs/CurlFetcher.php @@ -201,7 +201,7 @@ public function __construct(array $options = [], int $max_redirect = 3) */ public function request(string|Url $url, array|string $post_data = []): object { - if (!$url instanceof Url){ + if (!$url instanceof Url) { $url = new Url($url, true); $url->toAscii(); } diff --git a/Sources/WebFetch/APIs/FtpFetcher.php b/Sources/WebFetch/APIs/FtpFetcher.php index fa2c1bf761..1e09b496b2 100644 --- a/Sources/WebFetch/APIs/FtpFetcher.php +++ b/Sources/WebFetch/APIs/FtpFetcher.php @@ -108,7 +108,7 @@ public function __construct(?string $user = null, ?string $email = null) */ public function request(string|Url $url, array|string $post_data = []): self { - if (!$url instanceof Url){ + if (!$url instanceof Url) { $url = new Url($url, true); $url->toAscii(); } diff --git a/Sources/WebFetch/APIs/SocketFetcher.php b/Sources/WebFetch/APIs/SocketFetcher.php index 8a1b8148be..918a8205e2 100644 --- a/Sources/WebFetch/APIs/SocketFetcher.php +++ b/Sources/WebFetch/APIs/SocketFetcher.php @@ -164,7 +164,7 @@ public function __destruct() */ public function request(string|Url $url, array|string $post_data = []): object { - if (!$url instanceof Url){ + if (!$url instanceof Url) { $url = new Url($url, true); $url->toAscii(); } @@ -305,6 +305,7 @@ public function request(string|Url $url, array|string $post_data = []): object // Try to see if this is a chunked data $length = hexdec($line); + if (!is_int($length)) { break; } @@ -318,8 +319,7 @@ public function request(string|Url $url, array|string $post_data = []): object do { if (isset($content_length)) { $data = fread($this->fp, $content_length); - } - else { + } else { $data = fread($this->fp, $length); } @@ -334,10 +334,8 @@ public function request(string|Url $url, array|string $post_data = []): object if ($length <= 0 || feof($this->fp)) { break; } - } - while (true); - } - while (true); + } while (true); + } while (true); } else { if (isset($content_length)) { while (!feof($this->fp) && strlen($body) < $content_length) {