diff --git a/Sources/Actions/Admin/Find.php b/Sources/Actions/Admin/Find.php index 2c19b9c9fb6..d4ff43e1e7e 100644 --- a/Sources/Actions/Admin/Find.php +++ b/Sources/Actions/Admin/Find.php @@ -23,6 +23,7 @@ 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/BBCodeParser.php b/Sources/BBCodeParser.php index 572d82707b0..0e747a57a09 100644 --- a/Sources/BBCodeParser.php +++ b/Sources/BBCodeParser.php @@ -1143,7 +1143,7 @@ function ($a, $b) { * * @param string|bool $message The string to parse. * @param bool $smileys Whether to parse smileys. Default: true. - * @param string $cache_id The cache ID. + * @param string|int $cache_id The cache ID. * If $cache_id is left empty, an ID will be generated automatically. * Manually specifiying a ID is helpful in cases when an integration hook * wants to identify particular strings to act upon, but is otherwise @@ -1151,7 +1151,7 @@ function ($a, $b) { * @param array $parse_tags If set, only parses these tags rather than all of them. * @return string The parsed string. */ - public function parse(string $message, bool $smileys = true, string $cache_id = '', array $parse_tags = []): string + public function parse(string $message, bool $smileys = true, string|int $cache_id = '', array $parse_tags = []): string { // Don't waste cycles if (strval($message) === '') { diff --git a/Sources/Search/APIs/Custom.php b/Sources/Search/APIs/Custom.php index f0b8ba8e8e6..18fd18a7e2b 100644 --- a/Sources/Search/APIs/Custom.php +++ b/Sources/Search/APIs/Custom.php @@ -11,18 +11,21 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\Search\APIs; use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Search\SearchApi; use SMF\Utils; +use SMF\Search\SearchApiInterface; /** * Used for the "custom search index" option * Class Custom */ -class Custom extends SearchApi +class Custom extends SearchApi implements SearchApiInterface { /** * @var array Index settings @@ -71,7 +74,7 @@ public function __construct() /** * {@inheritDoc} */ - public function supportsMethod($methodName, $query_params = null): bool + public function supportsMethod(string $methodName, array $query_params = []): bool { $return = false; @@ -109,7 +112,7 @@ public function isValid(): bool /** * {@inheritDoc} */ - public function searchSort($a, $b): int + public function searchSort(string $a, string $b): int { global $excludedWords; @@ -122,7 +125,7 @@ public function searchSort($a, $b): int /** * {@inheritDoc} */ - public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded): void + public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsExclude, bool $isExcluded): void { $subwords = Utils::text2words($word, $this->min_word_length, true); @@ -136,7 +139,7 @@ public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, } foreach ($subwords as $subword) { - if (Utils::entityStrlen($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) { + if (Utils::entityStrlen((string) $subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) { $wordsSearch['indexed_words'][] = $subword; if ($isExcluded) { @@ -149,7 +152,7 @@ public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, /** * {@inheritDoc} */ - public function indexedWordQuery(array $words, array $search_data) + public function indexedWordQuery(array $words, array $search_data): mixed { $query_select = [ 'id_msg' => 'm.id_msg', @@ -202,7 +205,7 @@ public function indexedWordQuery(array $words, array $search_data) $count = 0; if (!empty($query_params['excluded_phrases']) && empty(Config::$modSettings['search_force_index'])) { - foreach ($query_params['excluded_phrases'] as $phrase) { + foreach ($query_params['excluded_phrases'] as $excludedWord) { $query_where[] = 'subject NOT ' . $this->query_match_type . ' {string:exclude_subject_words_' . $count . '}'; if ($this->query_match_type === 'RLIKE') { diff --git a/Sources/Search/APIs/Fulltext.php b/Sources/Search/APIs/Fulltext.php index 499d58fa11b..6b031a15fd0 100644 --- a/Sources/Search/APIs/Fulltext.php +++ b/Sources/Search/APIs/Fulltext.php @@ -11,18 +11,21 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\Search\APIs; use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Search\SearchApi; use SMF\Utils; +use SMF\Search\SearchApiInterface; /** * Class Fulltext * Used for fulltext index searching */ -class Fulltext extends SearchApi +class Fulltext extends SearchApi implements SearchApiInterface { /** * @var array Which words are banned @@ -60,7 +63,7 @@ public function __construct() /** * {@inheritDoc} */ - public function supportsMethod($methodName, $query_params = null): bool + public function supportsMethod(string $methodName, array $query_params = []): bool { $return = false; @@ -92,7 +95,7 @@ public function supportsMethod($methodName, $query_params = null): bool * * @return int The minimum word length */ - protected function _getMinWordLength() + protected function _getMinWordLength(): int { if (Config::$db_type == 'postgresql') { return 0; @@ -118,13 +121,13 @@ protected function _getMinWordLength() $min_word_length = 4; } - return $min_word_length; + return (int) $min_word_length; } /** * {@inheritDoc} */ - public function searchSort($a, $b): int + public function searchSort(string $a, string $b): int { global $excludedWords; @@ -137,7 +140,7 @@ public function searchSort($a, $b): int /** * {@inheritDoc} */ - public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded): void + public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsExclude, bool $isExcluded): void { $subwords = Utils::text2words($word, PHP_INT_MAX, false); @@ -168,7 +171,7 @@ public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, /** * {@inheritDoc} */ - public function indexedWordQuery(array $words, array $search_data) + public function indexedWordQuery(array $words, array $search_data): mixed { $query_select = [ 'id_msg' => 'm.id_msg', diff --git a/Sources/Search/APIs/Standard.php b/Sources/Search/APIs/Standard.php index f4d1bed09d2..26866ff3209 100644 --- a/Sources/Search/APIs/Standard.php +++ b/Sources/Search/APIs/Standard.php @@ -11,19 +11,22 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\Search\APIs; use SMF\Search\SearchApi; +use SMF\Search\SearchApiInterface; /** * Standard non full index, non custom index search */ -class Standard extends SearchApi +class Standard extends SearchApi implements SearchApiInterface { /** * {@inheritDoc} */ - public function supportsMethod($methodName, $query_params = null): bool + public function supportsMethod(string $methodName, array $query_params = []): bool { $return = false; diff --git a/Sources/Search/SearchApi.php b/Sources/Search/SearchApi.php index d99278da112..dbc0dd3b3e3 100644 --- a/Sources/Search/SearchApi.php +++ b/Sources/Search/SearchApi.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\Search; use SMF\BackwardCompatibility; @@ -22,6 +24,7 @@ use SMF\PackageManager\SubsPackage; use SMF\User; use SMF\Utils; +use SMF\Actions\Search; /** * Class SearchApi @@ -399,7 +402,7 @@ public function __construct() /** * {@inheritDoc} */ - public function supportsMethod($methodName, $query_params = []): bool + public function supportsMethod(string $methodName, array $query_params = []): bool { switch ($methodName) { case 'postRemoved': @@ -421,26 +424,28 @@ public function supportsMethod($methodName, $query_params = []): bool */ public function isValid(): bool { + return false; } /** * {@inheritDoc} */ - public function searchSort($a, $b): int + public function searchSort(string $a, string $b): int { + return 0; } /** * {@inheritDoc} */ - public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded): void + public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsExclude, bool $isExcluded): void { } /** * {@inheritDoc} */ - public function indexedWordQuery(array $words, array $search_data) + public function indexedWordQuery(array $words, array $search_data): mixed { } @@ -461,7 +466,7 @@ public function postModified(array &$msgOptions, array &$topicOptions, array &$p /** * {@inheritDoc} */ - public function postRemoved($id_msg): void + public function postRemoved(int $id_msg): void { $result = Db::$db->query( '', @@ -521,7 +526,7 @@ public function topicsRemoved(array $topics): void /** * {@inheritDoc} */ - public function topicsMoved(array $topics, $board_to): void + public function topicsMoved(array $topics, int $board_to): void { } @@ -539,7 +544,7 @@ public function initializeSearch(): void /** * {@inheritDoc} */ - public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray) + public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray): void { $update_cache = empty($_SESSION['search_cache']) || ($_SESSION['search_cache']['params'] != $this->compressParams()); @@ -1068,7 +1073,7 @@ protected function setSearchTerms(): void // .. first, we check for things like -"some words", but not "-some words". foreach ($matches[1] as $index => $word) { if ($word === '-') { - if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $this->blacklisted_words)) { $this->excludedWords[] = $word; } @@ -1079,7 +1084,7 @@ protected function setSearchTerms(): void // Now we look for -test, etc.... normaller. foreach ($wordArray as $index => $word) { if (strpos(trim($word), '-') === 0) { - if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { + if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $this->blacklisted_words)) { $this->excludedWords[] = $word; } diff --git a/Sources/Search/SearchApiInterface.php b/Sources/Search/SearchApiInterface.php index b049de81283..5a382c77eb4 100644 --- a/Sources/Search/SearchApiInterface.php +++ b/Sources/Search/SearchApiInterface.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\Search; use SMF\Msg; @@ -29,7 +31,7 @@ interface SearchApiInterface * @param array $query_params Any parameters for the query * @return bool Whether or not the specified method is supported */ - public function supportsMethod($methodName, $query_params = []): bool; + public function supportsMethod(string $methodName, array $query_params = []): bool; /** * Whether this method is valid for implementation or not. @@ -47,7 +49,7 @@ public function isValid(): bool; * @param string $b Word B * @return int An integer indicating how the words should be sorted */ - public function searchSort($a, $b): int; + public function searchSort(string $a, string $b): int; /** * Callback while preparing indexes for searching. @@ -57,7 +59,7 @@ public function searchSort($a, $b): int; * @param array $wordsExclude Words to exclude * @param bool $isExcluded Whether the specified word should be excluded */ - public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded): void; + public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsExclude, bool $isExcluded): void; /** * Search for indexed words. @@ -66,7 +68,7 @@ public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, * @param array $search_data An array of search data * @return mixed */ - public function indexedWordQuery(array $words, array $search_data); + public function indexedWordQuery(array $words, array $search_data): mixed; /** * Callback when a post is created. @@ -95,7 +97,7 @@ public function postModified(array &$msgOptions, array &$topicOptions, array &$p * * @param int $id_msg The ID of the post that was removed */ - public function postRemoved($id_msg): void; + public function postRemoved(int $id_msg): void; /** * Callback when a topic is removed. @@ -110,7 +112,7 @@ public function topicsRemoved(array $topics): void; * @param array $topics The ID(s) of the moved topic(s) * @param int $board_to The board that the topics were moved to */ - public function topicsMoved(array $topics, $board_to): void; + public function topicsMoved(array $topics, int $board_to): void; /** * Sets whatever properties are necessary in order to perform the search. @@ -134,7 +136,7 @@ public function initializeSearch(): void; * @param array $searchArray * @return mixed */ - public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray); + public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray): void; /** * Figures out which search result topics the user participated in. diff --git a/Sources/Search/SearchResult.php b/Sources/Search/SearchResult.php index 11067f2fde6..8160151dd80 100644 --- a/Sources/Search/SearchResult.php +++ b/Sources/Search/SearchResult.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\Search; use SMF\BackwardCompatibility; @@ -409,7 +411,7 @@ public function format(int $counter = 0, array $format_options = []): array * @param array $query_customizations Customizations to the SQL query. * @return Generator Iterating over result gives SearchResult instances. */ - public static function get($ids, array $query_customizations = []) + public static function get(/*int|array*/ $ids, array $query_customizations = [])/*: Generator*/ { $selects = $query_customizations['selects'] ?? [ 'm.*', diff --git a/Sources/WebFetch/APIs/CurlFetcher.php b/Sources/WebFetch/APIs/CurlFetcher.php index bce9611c016..5a550b4f1e0 100644 --- a/Sources/WebFetch/APIs/CurlFetcher.php +++ b/Sources/WebFetch/APIs/CurlFetcher.php @@ -10,6 +10,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\WebFetch\APIs; use SMF\Lang; @@ -193,14 +195,16 @@ public function __construct(array $options = [], int $max_redirect = 3) * - Calls setOptions() to set the curl opts array values based on the * defaults and user input. * - * @param string $url the site we are going to fetch + * @param string|Url $url the site we are going to fetch * @param array|string $post_data any post data as form name => value * @return object A reference to the object for method chaining. */ - public function request(string $url, array|string $post_data = []): object + public function request(string|Url $url, array|string $post_data = []): object { - $url = new Url($url, true); - $url->toAscii(); + if (!$url instanceof Url){ + $url = new Url($url, true); + $url->toAscii(); + } // If we can't do it, bail out. if (!function_exists('curl_init')) { @@ -232,7 +236,7 @@ public function request(string $url, array|string $post_data = []): object // Set the options and get it. $this->setOptions(); - $this->sendRequest(str_replace(' ', '%20', $url)); + $this->sendRequest(str_replace(' ', '%20', strval($url))); return $this; } diff --git a/Sources/WebFetch/APIs/FtpFetcher.php b/Sources/WebFetch/APIs/FtpFetcher.php index 8ad34687ca8..9d7edc23df0 100644 --- a/Sources/WebFetch/APIs/FtpFetcher.php +++ b/Sources/WebFetch/APIs/FtpFetcher.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\WebFetch\APIs; use SMF\Config; @@ -57,18 +59,18 @@ class FtpFetcher extends WebFetchApi public string $error_message = ''; /** - * @var int + * @var string * * The user name to connect with. */ - public int $user; + public string $user; /** - * @var int + * @var string * * The email address to connect with. */ - public int $email; + public string $email; /** * @var array @@ -101,13 +103,15 @@ public function __construct(?string $user = null, ?string $email = null) * - Optionally will post data to the page form if $post_data is supplied. * Passed arrays will be converted to a POST string joined with &'s. * - * @param string $url the site we are going to fetch + * @param string|Url $url the site we are going to fetch * @return object A reference to the object for method chaining. */ - public function request(string $url, array|string $post_data = []): object + public function request(string|Url $url, array|string $post_data = []): object { - $url = new Url($url, true); - $url->toAscii(); + if (!$url instanceof Url){ + $url = new Url($url, true); + $url->toAscii(); + } // Umm, this shouldn't happen? if (empty($url->scheme) || !in_array($url->scheme, ['ftp', 'ftps'])) { @@ -158,7 +162,7 @@ public function request(string $url, array|string $post_data = []): object // The server should now say something in acknowledgement. $ftp->check_response(150); - $this->response[0]['code'] = substr($this->last_message, 0, 3); + $this->response[0]['code'] = substr($ftp->last_message, 0, 3); $body = ''; @@ -170,7 +174,7 @@ public function request(string $url, array|string $post_data = []): object // All done, right? Good. $this->response[0]['success'] = $ftp->check_response(226); - $this->response[0]['code'] = substr($this->last_message, 0, 3); + $this->response[0]['code'] = substr($ftp->last_message, 0, 3); $ftp->close(); $this->response[0]['body'] = $body; diff --git a/Sources/WebFetch/APIs/SocketFetcher.php b/Sources/WebFetch/APIs/SocketFetcher.php index a387c7b216d..bbbfddaecd1 100644 --- a/Sources/WebFetch/APIs/SocketFetcher.php +++ b/Sources/WebFetch/APIs/SocketFetcher.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\WebFetch\APIs; use SMF\Lang; @@ -135,14 +137,16 @@ public function __destruct() * - Optionally will post data to the page form if $post_data is supplied. * Passed arrays will be converted to a POST string joined with &'s. * - * @param string $url the site we are going to fetch + * @param string|Url $url the site we are going to fetch * @param array|string $post_data any post data as form name => value * @return object A reference to the object for method chaining. */ - public function request(string $url, array|string $post_data = []): object + public function request(string|Url $url, array|string $post_data = []): object { - $url = new Url($url, true); - $url->toAscii(); + if (!$url instanceof Url){ + $url = new Url($url, true); + $url->toAscii(); + } // Umm, this shouldn't happen? if (empty($url->scheme) || !in_array($url->scheme, ['http', 'https'])) { @@ -243,7 +247,7 @@ public function request(string $url, array|string $post_data = []): object $this->current_redirect++; - return $this->request($location, $post_data); + return $this->request(strval($location), $post_data); } // Make sure we get a 200 OK. diff --git a/Sources/WebFetch/WebFetchApi.php b/Sources/WebFetch/WebFetchApi.php index 6eba083912a..04c44676738 100644 --- a/Sources/WebFetch/WebFetchApi.php +++ b/Sources/WebFetch/WebFetchApi.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\WebFetch; use SMF\BackwardCompatibility; @@ -80,8 +82,9 @@ abstract class WebFetchApi implements WebFetchApiInterface /** * {@inheritDoc} */ - public function request(string $url, array|string $post_data = []): object + public function request(string $url, array|string $post_data = []): ?object { + return null; } /** @@ -96,6 +99,7 @@ public function result(?string $area = null): mixed */ public function resultRaw(?int $response_number = null): array { + return []; } /*********************** diff --git a/Sources/WebFetch/WebFetchApiInterface.php b/Sources/WebFetch/WebFetchApiInterface.php index 2780f8ef905..1dbca2188e2 100644 --- a/Sources/WebFetch/WebFetchApiInterface.php +++ b/Sources/WebFetch/WebFetchApiInterface.php @@ -11,6 +11,8 @@ * @version 3.0 Alpha 1 */ +declare(strict_types=1); + namespace SMF\WebFetch; /** @@ -29,7 +31,7 @@ interface WebFetchApiInterface * @param array|string $post_data any post data as form name => value * @return object A reference to the object for method chaining. */ - public function request(string $url, array $post_data = []): object; + public function request(string $url, array $post_data = []): ?object; /** * Used to return the results to the caller.