diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml index 68cdeef2ca..0ba0de5ed0 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/php-cs-fixer.yml @@ -31,4 +31,4 @@ jobs: - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: - args: --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }} \ No newline at end of file + args: --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no --allow-risky=yes ${{ env.PHPCS_EXTRA_ARGS }} \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 482ca86aca..4cd06e30d7 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -95,6 +95,10 @@ 'nullable_type_declaration' => ['syntax' => 'question_mark'], // Namespace notation. + 'native_function_invocation' => [ + 'include' => ['@compiler_optimized'], + 'scope' => 'namespaced', + ], 'no_leading_namespace_whitespace' => true, // Operator. diff --git a/Sources/Actions/Admin/ACP.php b/Sources/Actions/Admin/ACP.php index afa160dd2f..0d3f693cff 100644 --- a/Sources/Actions/Admin/ACP.php +++ b/Sources/Actions/Admin/ACP.php @@ -778,7 +778,7 @@ public function execute(): void // Is it valid? if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -814,7 +814,7 @@ public static function prepareDBSettingContext(array &$config_vars): void foreach ($config_vars as $config_var) { // HR? - if (!is_array($config_var)) { + if (!\is_array($config_var)) { Utils::$context['config_vars'][] = $config_var; } else { // If it has no name it doesn't have any purpose! @@ -878,10 +878,10 @@ public static function prepareDBSettingContext(array &$config_vars): void } Utils::$context['config_vars'][$config_var[1]] = [ - 'label' => $config_var['text_label'] ?? (Lang::$txt[$config_var[1]] ?? (isset($config_var[3]) && !is_array($config_var[3]) ? $config_var[3] : '')), + 'label' => $config_var['text_label'] ?? (Lang::$txt[$config_var[1]] ?? (isset($config_var[3]) && !\is_array($config_var[3]) ? $config_var[3] : '')), 'help' => isset(Lang::$helptxt[$config_var[1]]) ? $config_var[1] : '', 'type' => $config_var[0], - 'size' => !empty($config_var['size']) ? $config_var['size'] : (!empty($config_var[2]) && !is_array($config_var[2]) ? $config_var[2] : (in_array($config_var[0], ['int', 'float']) ? 6 : 0)), + 'size' => !empty($config_var['size']) ? $config_var['size'] : (!empty($config_var[2]) && !\is_array($config_var[2]) ? $config_var[2] : (\in_array($config_var[0], ['int', 'float']) ? 6 : 0)), 'data' => [], 'name' => $config_var[1], 'value' => $value, @@ -912,7 +912,7 @@ public static function prepareDBSettingContext(array &$config_vars): void } // If this is a select box handle any data. - if (!empty($config_var[2]) && is_array($config_var[2])) { + if (!empty($config_var[2]) && \is_array($config_var[2])) { // If we allow multiple selections, we need to adjust a few things. if ($config_var[0] == 'select' && !empty($config_var['multiple'])) { Utils::$context['config_vars'][$config_var[1]]['name'] .= '[]'; @@ -921,7 +921,7 @@ public static function prepareDBSettingContext(array &$config_vars): void } // If it's associative - if (isset($config_var[2][0]) && is_array($config_var[2][0])) { + if (isset($config_var[2][0]) && \is_array($config_var[2][0])) { Utils::$context['config_vars'][$config_var[1]]['data'] = $config_var[2]; } else { foreach ($config_var[2] as $key => $item) { @@ -930,7 +930,7 @@ public static function prepareDBSettingContext(array &$config_vars): void } if (empty($config_var['size']) && !empty($config_var['multiple'])) { - Utils::$context['config_vars'][$config_var[1]]['size'] = max(4, count($config_var[2])); + Utils::$context['config_vars'][$config_var[1]]['size'] = max(4, \count($config_var[2])); } } @@ -1007,7 +1007,7 @@ public static function prepareDBSettingContext(array &$config_vars): void $sectionTags = array_diff($bbcTags, Utils::$context['legacy_bbc']); } - $totalTags = count($sectionTags); + $totalTags = \count($sectionTags); $tagsPerColumn = ceil($totalTags / $numColumns); $col = 0; @@ -1081,7 +1081,7 @@ public static function saveSettings(array &$config_vars): void $settings_defs = Config::getSettingsDefs(); foreach ($settings_defs as $var => $def) { - if (!is_string($var)) { + if (!\is_string($var)) { continue; } @@ -1089,7 +1089,7 @@ public static function saveSettings(array &$config_vars): void $config_passwords[] = $var; } else { // Special handling if multiple types are allowed. - if (is_array($def['type'])) { + if (\is_array($def['type'])) { // Obviously, we don't need null here. $def['type'] = array_filter( $def['type'], @@ -1098,7 +1098,7 @@ function ($type) { }, ); - $type = count($def['type']) == 1 ? reset($def['type']) : 'multiple'; + $type = \count($def['type']) == 1 ? reset($def['type']) : 'multiple'; } else { $type = $def['type']; } @@ -1115,7 +1115,7 @@ function ($type) { case 'integer': // Some things saved as integers are presented as booleans foreach ($config_vars as $config_var) { - if (is_array($config_var) && $config_var[0] == $var) { + if (\is_array($config_var) && $config_var[0] == $var) { if ($config_var[3] == 'check') { $config_bools[] = $var; break 2; @@ -1141,7 +1141,7 @@ function ($type) { // Figure out which config vars we're saving here... foreach ($config_vars as $config_var) { - if (!is_array($config_var) || $config_var[2] != 'file') { + if (!\is_array($config_var) || $config_var[2] != 'file') { continue; } @@ -1164,15 +1164,15 @@ function ($type) { } } - if (!in_array($var_name, $config_bools) && !isset($_POST[$var_name])) { + if (!\in_array($var_name, $config_bools) && !isset($_POST[$var_name])) { continue; } - if (in_array($var_name, $config_passwords)) { + if (\in_array($var_name, $config_passwords)) { if (isset($_POST[$var_name][1]) && $_POST[$var_name][0] == $_POST[$var_name][1]) { $new_settings[$var_name] = $_POST[$var_name][0]; } - } elseif (in_array($var_name, $config_nums)) { + } elseif (\in_array($var_name, $config_nums)) { $new_settings[$var_name] = (int) $_POST[$var_name]; // If no min is specified, assume 0. This is done to avoid having to specify 'min => 0' for all settings where 0 is the min... @@ -1183,7 +1183,7 @@ function ($type) { if (isset($config_var['max'])) { $new_settings[$var_name] = min($config_var['max'], $new_settings[$var_name]); } - } elseif (in_array($var_name, $config_bools)) { + } elseif (\in_array($var_name, $config_bools)) { $new_settings[$var_name] = !empty($_POST[$var_name]); } elseif (isset($config_multis[$var_name])) { $is_acceptable_type = false; @@ -1215,7 +1215,7 @@ function ($type) { foreach ($config_vars as $config_var) { // We just saved the file-based settings, so skip their definitions. - if (!is_array($config_var) || $config_var[2] == 'file') { + if (!\is_array($config_var) || $config_var[2] == 'file') { continue; } @@ -1268,14 +1268,14 @@ public static function saveDBSettings(array &$config_vars): void $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; } // Select boxes! - elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) { + elseif ($var[0] == 'select' && \in_array($_POST[$var[1]], array_keys($var[2]))) { $setArray[$var[1]] = $_POST[$var[1]]; } elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != []) { // For security purposes we validate this line by line. $lOptions = []; foreach ($_POST[$var[1]] as $invar) { - if (in_array($invar, array_keys($var[2]))) { + if (\in_array($invar, array_keys($var[2]))) { $lOptions[] = $invar; } } @@ -1338,7 +1338,7 @@ public static function saveDBSettings(array &$config_vars): void } } // Text! - elseif (in_array($var[0], ['text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'])) { + elseif (\in_array($var[0], ['text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'])) { $setArray[$var[1]] = $_POST[$var[1]]; } // Passwords! @@ -1357,7 +1357,7 @@ public static function saveDBSettings(array &$config_vars): void if (!isset($_POST[$var[1] . '_enabledTags'])) { $_POST[$var[1] . '_enabledTags'] = []; - } elseif (!is_array($_POST[$var[1] . '_enabledTags'])) { + } elseif (!\is_array($_POST[$var[1] . '_enabledTags'])) { $_POST[$var[1] . '_enabledTags'] = [$_POST[$var[1] . '_enabledTags']]; } @@ -1393,13 +1393,13 @@ public static function getServerVersions(array $checkFor): array $versions = []; // Is GD available? If it is, we should show version information for it too. - if (in_array('gd', $checkFor) && function_exists('gd_info')) { + if (\in_array('gd', $checkFor) && \function_exists('gd_info')) { $temp = gd_info(); $versions['gd'] = ['title' => Lang::$txt['support_versions_gd'], 'version' => $temp['GD Version']]; } // Why not have a look at ImageMagick? If it's installed, we should show version information for it too. - if (in_array('imagemagick', $checkFor) && class_exists('Imagick')) { + if (\in_array('imagemagick', $checkFor) && class_exists('Imagick')) { $temp = new \Imagick(); $temp2 = $temp->getVersion(); $im_version = $temp2['versionString']; @@ -1412,7 +1412,7 @@ public static function getServerVersions(array $checkFor): array } // Now lets check for the Database. - if (in_array('db_server', $checkFor)) { + if (\in_array('db_server', $checkFor)) { if (!isset(Db::$db_connection) || Db::$db_connection === false) { Lang::load('Errors'); trigger_error(Lang::$txt['get_server_versions_no_database'], E_USER_NOTICE); @@ -1433,7 +1433,7 @@ public static function getServerVersions(array $checkFor): array foreach (CacheApi::detect() as $class_name => $cache_api) { $class_name_txt_key = strtolower($cache_api->getImplementationClassKeyName()); - if (in_array($class_name_txt_key, $checkFor)) { + if (\in_array($class_name_txt_key, $checkFor)) { $versions[$class_name_txt_key] = [ 'title' => Lang::$txt[$class_name_txt_key . '_cache'] ?? $class_name, 'version' => $cache_api->getVersion(), @@ -1441,7 +1441,7 @@ public static function getServerVersions(array $checkFor): array } } - if (in_array('php', $checkFor)) { + if (\in_array('php', $checkFor)) { $versions['php'] = [ 'title' => 'PHP', 'version' => PHP_VERSION, @@ -1449,7 +1449,7 @@ public static function getServerVersions(array $checkFor): array ]; } - if (in_array('server', $checkFor)) { + if (\in_array('server', $checkFor)) { $versions['server'] = [ 'title' => Lang::$txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE'], @@ -1746,7 +1746,7 @@ public static function emailAdmins(string $template, array $replacements = [], a // Any additional users we must email this to? if (!empty($additional_recipients)) { foreach ($additional_recipients as $recipient) { - if (in_array($recipient['email'], $emails_sent)) { + if (\in_array($recipient['email'], $emails_sent)) { continue; } @@ -1779,7 +1779,7 @@ public static function adminLogin(string $type = 'admin'): void // Validate what type of session check this is. $types = []; IntegrationHook::call('integrate_validateSession', [&$types]); - $type = in_array($type, $types) || $type == 'moderate' ? $type : 'admin'; + $type = \in_array($type, $types) || $type == 'moderate' ? $type : 'admin'; // They used a wrong password, log it and unset that. if (isset($_POST[$type . '_hash_pass']) || isset($_POST[$type . '_pass'])) { @@ -1878,11 +1878,11 @@ protected function setAdminAreas(): void array_walk_recursive( $this->admin_areas, function (&$value, $key) { - if (in_array($key, ['title', 'label'])) { + if (\in_array($key, ['title', 'label'])) { $value = Lang::$txt[$value] ?? $value; } - if (is_string($value)) { + if (\is_string($value)) { $value = strtr($value, [ '{scripturl}' => Config::$scripturl, '{boardurl}' => Config::$boardurl, @@ -1943,7 +1943,7 @@ function (&$value, $key) { */ protected static function adminLogin_outputPostVars(string $k, string|array $v): string { - if (!is_array($v)) { + if (!\is_array($v)) { return "\n" . ' '"', '<' => '<', '>' => '>']) . '">'; } diff --git a/Sources/Actions/Admin/AntiSpam.php b/Sources/Actions/Admin/AntiSpam.php index 1099b709ed..dbd04b302e 100644 --- a/Sources/Actions/Admin/AntiSpam.php +++ b/Sources/Actions/Admin/AntiSpam.php @@ -153,7 +153,7 @@ public function execute(): void foreach (Utils::$context['qa_languages'] as $lang_id => $dummy) { // If we had some questions for this language before, but don't now, delete everything from that language. - if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty(Utils::$context['qa_by_lang'][$lang_id])) { + if ((!isset($_POST['question'][$lang_id]) || !\is_array($_POST['question'][$lang_id])) && !empty(Utils::$context['qa_by_lang'][$lang_id])) { $changes['delete'] = array_merge($changes['delete'], Utils::$context['qa_by_lang'][$lang_id]); } @@ -188,7 +188,7 @@ public function execute(): void $question = Utils::htmlspecialchars(trim($question)); // Get the answers. Firstly check there actually might be some. - if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id])) { + if (!isset($_POST['answer'][$lang_id][$q_id]) || !\is_array($_POST['answer'][$lang_id][$q_id])) { if (isset(Utils::$context['question_answers'][$q_id])) { $changes['delete'][] = $q_id; } @@ -361,7 +361,7 @@ public static function getConfigVars(): array Lang::load('ManageSettings'); // Generate a sample registration image. - Utils::$context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); + Utils::$context['use_graphic_library'] = \in_array('gd', get_loaded_extensions()); $config_vars = [ ['check', 'reg_verification'], diff --git a/Sources/Actions/Admin/Attachments.php b/Sources/Actions/Admin/Attachments.php index 0ba92c8d20..d0aa276e7d 100644 --- a/Sources/Actions/Admin/Attachments.php +++ b/Sources/Actions/Admin/Attachments.php @@ -94,7 +94,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -139,7 +139,7 @@ public function attachmentSettings(): void !empty($_POST['use_subdirectories_for_attachments']) && !empty(Config::$modSettings['attachment_basedirectories']) ) { - if (!is_array(Config::$modSettings['attachment_basedirectories'])) { + if (!\is_array(Config::$modSettings['attachment_basedirectories'])) { Config::$modSettings['attachment_basedirectories'] = Utils::jsonDecode(Config::$modSettings['attachment_basedirectories'], true); } } else { @@ -149,17 +149,17 @@ public function attachmentSettings(): void if ( !empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) - && !in_array($_POST['basedirectory_for_attachments'], Config::$modSettings['attachment_basedirectories']) + && !\in_array($_POST['basedirectory_for_attachments'], Config::$modSettings['attachment_basedirectories']) ) { $currentAttachmentUploadDir = Config::$modSettings['currentAttachmentUploadDir']; - if (!in_array($_POST['basedirectory_for_attachments'], Config::$modSettings['attachmentUploadDir'])) { + if (!\in_array($_POST['basedirectory_for_attachments'], Config::$modSettings['attachmentUploadDir'])) { if (!Attachment::automanageCreateDirectory($_POST['basedirectory_for_attachments'])) { $_POST['basedirectory_for_attachments'] = Config::$modSettings['basedirectory_for_attachments']; } } - if (!in_array($_POST['basedirectory_for_attachments'], Config::$modSettings['attachment_basedirectories'])) { + if (!\in_array($_POST['basedirectory_for_attachments'], Config::$modSettings['attachment_basedirectories'])) { Config::$modSettings['attachment_basedirectories'][Config::$modSettings['currentAttachmentUploadDir']] = $_POST['basedirectory_for_attachments']; Config::updateModSettings([ @@ -545,7 +545,7 @@ public function maintain(): void Utils::$context['attachment_current_files'] = Lang::numberFormat((int) $current_dir_files, 0); - Utils::$context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; + Utils::$context['attach_multiple_dirs'] = \count($attach_dirs) > 1 ? true : false; Utils::$context['attach_dirs'] = $attach_dirs; @@ -810,7 +810,7 @@ public function repair(): void Utils::$context['repair_errors']['missing_thumbnail_parent']++; // If we are repairing remove the file from disk now. - if ($fix_errors && in_array('missing_thumbnail_parent', $to_fix)) { + if ($fix_errors && \in_array('missing_thumbnail_parent', $to_fix)) { $filename = Attachment::getFilePath((int) $row['id_attach']); @unlink($filename); } @@ -823,7 +823,7 @@ public function repair(): void Db::$db->free_result($result); // Do we need to delete what we have? - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { + if ($fix_errors && !empty($to_remove) && \in_array('missing_thumbnail_parent', $to_fix)) { Db::$db->query( '', 'DELETE FROM {db_prefix}attachments @@ -887,7 +887,7 @@ public function repair(): void Db::$db->free_result($result); // Do we need to delete what we have? - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { + if ($fix_errors && !empty($to_update) && \in_array('parent_missing_thumbnail', $to_fix)) { Db::$db->query( '', 'UPDATE {db_prefix}attachments @@ -957,7 +957,7 @@ public function repair(): void $errors_found[] = 'wrong_folder'; // Are we going to fix this now? - if ($fix_errors && in_array('wrong_folder', $to_fix)) { + if ($fix_errors && \in_array('wrong_folder', $to_fix)) { Db::$db->query( '', 'UPDATE {db_prefix}attachments @@ -983,7 +983,7 @@ public function repair(): void $errors_found[] = 'file_size_of_zero'; // Fixing? - if ($fix_errors && in_array('file_size_of_zero', $to_fix)) { + if ($fix_errors && \in_array('file_size_of_zero', $to_fix)) { $to_remove[] = $row['id_attach']; @unlink($filename); } @@ -992,7 +992,7 @@ public function repair(): void $errors_found[] = 'file_wrong_size'; // Fix it here? - if ($fix_errors && in_array('file_wrong_size', $to_fix)) { + if ($fix_errors && \in_array('file_wrong_size', $to_fix)) { Db::$db->query( '', 'UPDATE {db_prefix}attachments @@ -1007,19 +1007,19 @@ public function repair(): void } } - if (in_array('file_missing_on_disk', $errors_found)) { + if (\in_array('file_missing_on_disk', $errors_found)) { $to_fix[] = 'file_missing_on_disk'; } - if (in_array('file_size_of_zero', $errors_found)) { + if (\in_array('file_size_of_zero', $errors_found)) { $to_fix[] = 'file_size_of_zero'; } - if (in_array('file_wrong_size', $errors_found)) { + if (\in_array('file_wrong_size', $errors_found)) { $to_fix[] = 'file_wrong_size'; } - if (in_array('wrong_folder', $errors_found)) { + if (\in_array('wrong_folder', $errors_found)) { $to_fix[] = 'wrong_folder'; } @@ -1093,7 +1093,7 @@ public function repair(): void Utils::$context['repair_errors']['avatar_no_member']++; // If we are repairing remove the file from disk now. - if ($fix_errors && in_array('avatar_no_member', $to_fix)) { + if ($fix_errors && \in_array('avatar_no_member', $to_fix)) { if ($row['attachment_type'] == 1) { $filename = Config::$modSettings['custom_avatar_dir'] . '/' . $row['filename']; } else { @@ -1110,7 +1110,7 @@ public function repair(): void Db::$db->free_result($result); // Do we need to delete what we have? - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { + if ($fix_errors && !empty($to_remove) && \in_array('avatar_no_member', $to_fix)) { Db::$db->query( '', 'DELETE FROM {db_prefix}attachments @@ -1177,7 +1177,7 @@ public function repair(): void Utils::$context['repair_errors']['attachment_no_msg']++; // If we are repairing remove the file from disk now. - if ($fix_errors && in_array('attachment_no_msg', $to_fix)) { + if ($fix_errors && \in_array('attachment_no_msg', $to_fix)) { $filename = Attachment::getFilePath((int) $row['id_attach']); @unlink($filename); } @@ -1189,7 +1189,7 @@ public function repair(): void Db::$db->free_result($result); // Do we need to delete what we have? - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { + if ($fix_errors && !empty($to_remove) && \in_array('attachment_no_msg', $to_fix)) { Db::$db->query( '', 'DELETE FROM {db_prefix}attachments @@ -1223,7 +1223,7 @@ public function repair(): void foreach ($attach_dirs as $attach_dir) { if ($dir = @opendir($attach_dir)) { while ($file = readdir($dir)) { - if (in_array($file, ['.', '..', '.htaccess', 'index.php'])) { + if (\in_array($file, ['.', '..', '.htaccess', 'index.php'])) { continue; } @@ -1252,7 +1252,7 @@ public function repair(): void ); if (Db::$db->num_rows($request) == 0) { - if ($fix_errors && in_array('files_without_attachment', $to_fix)) { + if ($fix_errors && \in_array('files_without_attachment', $to_fix)) { @unlink($attach_dir . '/' . $file); } else { Utils::$context['repair_errors']['files_without_attachment']++; @@ -1262,7 +1262,7 @@ public function repair(): void Db::$db->free_result($request); } } else { - if ($fix_errors && in_array('files_without_attachment', $to_fix)) { + if ($fix_errors && \in_array('files_without_attachment', $to_fix)) { @unlink($attach_dir . '/' . $file); } else { Utils::$context['repair_errors']['files_without_attachment']++; @@ -1305,7 +1305,7 @@ public function paths(): void // Since this needs to be done eventually. if (!isset(Config::$modSettings['attachment_basedirectories'])) { Config::$modSettings['attachment_basedirectories'] = []; - } elseif (!is_array(Config::$modSettings['attachment_basedirectories'])) { + } elseif (!\is_array(Config::$modSettings['attachment_basedirectories'])) { Config::$modSettings['attachment_basedirectories'] = Utils::jsonDecode(Config::$modSettings['attachment_basedirectories'], true); } @@ -1330,7 +1330,7 @@ public function paths(): void // Sorry, these dirs are NOT valid $invalid_dirs = [Config::$boarddir, Theme::$current->settings['default_theme_dir'], Config::$sourcedir]; - if (in_array($path, $invalid_dirs)) { + if (\in_array($path, $invalid_dirs)) { $errors[] = $path . ': ' . Lang::$txt['attach_dir_invalid']; continue; @@ -1338,9 +1338,9 @@ public function paths(): void // Hmm, a new path maybe? // Don't allow empty paths - if (!array_key_exists($id, Config::$modSettings['attachmentUploadDir']) && !empty($path)) { + if (!\array_key_exists($id, Config::$modSettings['attachmentUploadDir']) && !empty($path)) { // or is it? - if (in_array($path, Config::$modSettings['attachmentUploadDir']) || in_array(Config::$boarddir . DIRECTORY_SEPARATOR . $path, Config::$modSettings['attachmentUploadDir'])) { + if (\in_array($path, Config::$modSettings['attachmentUploadDir']) || \in_array(Config::$boarddir . DIRECTORY_SEPARATOR . $path, Config::$modSettings['attachmentUploadDir'])) { $errors[] = $path . ': ' . Lang::$txt['attach_dir_duplicate_msg']; continue; @@ -1372,7 +1372,7 @@ public function paths(): void } // Update the base directory path - if (!empty(Config::$modSettings['attachment_basedirectories']) && array_key_exists($id, Config::$modSettings['attachment_basedirectories'])) { + if (!empty(Config::$modSettings['attachment_basedirectories']) && \array_key_exists($id, Config::$modSettings['attachment_basedirectories'])) { $base = Config::$modSettings['basedirectory_for_attachments'] == Config::$modSettings['attachmentUploadDir'][$id] ? $path : Config::$modSettings['basedirectory_for_attachments']; Config::$modSettings['attachment_basedirectories'][$id] = $path; @@ -1468,7 +1468,7 @@ public function paths(): void // Find the current directory if there's no value carried, if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) { - if (array_key_exists(Config::$modSettings['currentAttachmentUploadDir'], Config::$modSettings['attachmentUploadDir'])) { + if (\array_key_exists(Config::$modSettings['currentAttachmentUploadDir'], Config::$modSettings['attachmentUploadDir'])) { $_POST['current_dir'] = Config::$modSettings['currentAttachmentUploadDir']; } else { $_POST['current_dir'] = max(array_keys(Config::$modSettings['attachmentUploadDir'])); @@ -1484,7 +1484,7 @@ public function paths(): void || isset(Config::$modSettings['last_attachments_directory'][0]) ) ) { - if (!is_array(Config::$modSettings['last_attachments_directory'])) { + if (!\is_array(Config::$modSettings['last_attachments_directory'])) { Config::$modSettings['last_attachments_directory'] = Utils::jsonDecode(Config::$modSettings['last_attachments_directory'], true); } @@ -1523,7 +1523,7 @@ public function paths(): void } // Going back to just one path? - if (count($new_dirs) == 1) { + if (\count($new_dirs) == 1) { // We might need to reset the paths. This loop will just loop through once. foreach ($new_dirs as $id => $dir) { if ($id != 1) { @@ -1616,7 +1616,7 @@ public function paths(): void $current_dir = Config::$modSettings['currentAttachmentUploadDir']; - if (!in_array($_POST['new_base_dir'], Config::$modSettings['attachmentUploadDir'])) { + if (!\in_array($_POST['new_base_dir'], Config::$modSettings['attachmentUploadDir'])) { if (!Attachment::automanageCreateDirectory($_POST['new_base_dir'])) { $errors[] = $_POST['new_base_dir'] . ': ' . Lang::$txt['attach_dir_base_no_create']; } @@ -1624,7 +1624,7 @@ public function paths(): void Config::$modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], Config::$modSettings['attachmentUploadDir']); - if (!in_array($_POST['new_base_dir'], Config::$modSettings['attachment_basedirectories'])) { + if (!\in_array($_POST['new_base_dir'], Config::$modSettings['attachment_basedirectories'])) { Config::$modSettings['attachment_basedirectories'][Config::$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; } @@ -1649,7 +1649,7 @@ public function paths(): void } if (isset($_SESSION['errors'])) { - if (is_array($_SESSION['errors'])) { + if (\is_array($_SESSION['errors'])) { $errors = []; if (!empty($_SESSION['errors']['dir'])) { @@ -2109,7 +2109,7 @@ public static function attachConfigVars(): array if ( empty(Config::$modSettings['attachment_basedirectories']) && Config::$modSettings['currentAttachmentUploadDir'] == 1 - && count(Config::$modSettings['attachmentUploadDir']) == 1 + && \count(Config::$modSettings['attachmentUploadDir']) == 1 ) { Lang::$txt['attachmentUploadDir_path'] = Config::$modSettings['attachmentUploadDir'][1]; } @@ -2130,8 +2130,8 @@ public static function attachConfigVars(): array $testImg = get_extension_funcs('gd') || class_exists('Imagick'); // See if we can find if the server is set up to support the attachment limits - $post_max_kb = floor(Sapi::memoryReturnBytes(ini_get('post_max_size')) / 1024); - $file_max_kb = floor(Sapi::memoryReturnBytes(ini_get('upload_max_filesize')) / 1024); + $post_max_kb = floor(Sapi::memoryReturnBytes(\ini_get('post_max_size')) / 1024); + $file_max_kb = floor(Sapi::memoryReturnBytes(\ini_get('upload_max_filesize')) / 1024); $config_vars = [ ['title', 'attachment_manager_settings'], @@ -2143,7 +2143,7 @@ public static function attachConfigVars(): array ['select', 'automanage_attachments', [0 => Lang::$txt['attachments_normal'], 1 => Lang::$txt['attachments_auto_space'], 2 => Lang::$txt['attachments_auto_years'], 3 => Lang::$txt['attachments_auto_months'], 4 => Lang::$txt['attachments_auto_16']]], ['check', 'use_subdirectories_for_attachments', 'subtext' => Lang::$txt['use_subdirectories_for_attachments_note']], (empty(Config::$modSettings['attachment_basedirectories']) ? ['text', 'basedirectory_for_attachments', 40] : ['var_message', 'basedirectory_for_attachments', 'message' => 'basedirectory_for_attachments_path', 'invalid' => empty(Utils::$context['valid_basedirectory']), 'text_label' => (!empty(Utils::$context['valid_basedirectory']) ? Lang::$txt['basedirectory_for_attachments_current'] : Lang::getTxt('basedirectory_for_attachments_warning', ['scripturl' => Config::$scripturl]))]), - empty(Config::$modSettings['attachment_basedirectories']) && Config::$modSettings['currentAttachmentUploadDir'] == 1 && count(Config::$modSettings['attachmentUploadDir']) == 1 ? ['var_message', 'attachmentUploadDir_path', 'subtext' => Lang::$txt['attachmentUploadDir_multiple_configure'], 40, 'invalid' => !Utils::$context['valid_upload_dir'], 'text_label' => Lang::$txt['attachmentUploadDir'], 'message' => 'attachmentUploadDir_path'] : ['var_message', 'attach_current_directory', 'subtext' => Lang::$txt['attachmentUploadDir_multiple_configure'], 'message' => 'attachment_path', 'invalid' => empty(Utils::$context['valid_upload_dir']), 'text_label' => (!empty(Utils::$context['valid_upload_dir']) ? Lang::$txt['attach_current_dir'] : Lang::getTxt('attach_current_dir_warning', ['scripturl' => Config::$scripturl]))], + empty(Config::$modSettings['attachment_basedirectories']) && Config::$modSettings['currentAttachmentUploadDir'] == 1 && \count(Config::$modSettings['attachmentUploadDir']) == 1 ? ['var_message', 'attachmentUploadDir_path', 'subtext' => Lang::$txt['attachmentUploadDir_multiple_configure'], 40, 'invalid' => !Utils::$context['valid_upload_dir'], 'text_label' => Lang::$txt['attachmentUploadDir'], 'message' => 'attachmentUploadDir_path'] : ['var_message', 'attach_current_directory', 'subtext' => Lang::$txt['attachmentUploadDir_multiple_configure'], 'message' => 'attachment_path', 'invalid' => empty(Utils::$context['valid_upload_dir']), 'text_label' => (!empty(Utils::$context['valid_upload_dir']) ? Lang::$txt['attach_current_dir'] : Lang::getTxt('attach_current_dir_warning', ['scripturl' => Config::$scripturl]))], ['int', 'attachmentDirFileLimit', 'subtext' => Lang::$txt['zero_for_no_limit'], 6], ['int', 'attachmentDirSizeLimit', 'subtext' => Lang::$txt['zero_for_no_limit'], 6, 'postinput' => Lang::$txt['kilobyte']], ['check', 'dont_show_attach_under_post', 'subtext' => Lang::$txt['dont_show_attach_under_post_sub']], @@ -2424,7 +2424,7 @@ public static function list_getAttachDirs(): array $is_base_dir = false; if (!empty(Config::$modSettings['attachment_basedirectories'])) { - $is_base_dir = in_array($dir, Config::$modSettings['attachment_basedirectories']); + $is_base_dir = \in_array($dir, Config::$modSettings['attachment_basedirectories']); // Count any sub-folders. foreach (Config::$modSettings['attachmentUploadDir'] as $sid => $sub) { @@ -2541,7 +2541,7 @@ public static function attachDirStatus(string $dir, int $expected_files): array while ($file = $dir_handle->read()) { // Now do we have a real file here? - if (in_array($file, ['.', '..', '.htaccess', 'index.php'])) { + if (\in_array($file, ['.', '..', '.htaccess', 'index.php'])) { continue; } diff --git a/Sources/Actions/Admin/Bans.php b/Sources/Actions/Admin/Bans.php index 794a2d675f..48014405c0 100644 --- a/Sources/Actions/Admin/Bans.php +++ b/Sources/Actions/Admin/Bans.php @@ -90,7 +90,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -105,7 +105,7 @@ public function execute(): void public function list(): void { // User pressed the 'remove selection button'. - if (!empty($_POST['removeBans']) && !empty($_POST['remove']) && is_array($_POST['remove'])) { + if (!empty($_POST['removeBans']) && !empty($_POST['remove']) && \is_array($_POST['remove'])) { User::$me->checkSession(); // Make sure every entry is a proper integer. @@ -364,7 +364,7 @@ public function edit(): void ], 'data' => [ 'function' => function ($ban_item) { - if (in_array($ban_item['type'], ['ip', 'hostname', 'email'])) { + if (\in_array($ban_item['type'], ['ip', 'hostname', 'email'])) { return '' . Lang::$txt[$ban_item['type']] . ': ' . $ban_item[$ban_item['type']]; } @@ -584,7 +584,7 @@ public function edit(): void */ public function browseTriggers(): void { - if (!empty($_POST['remove_triggers']) && !empty($_POST['remove']) && is_array($_POST['remove'])) { + if (!empty($_POST['remove_triggers']) && !empty($_POST['remove']) && \is_array($_POST['remove'])) { User::$me->checkSession(); self::removeBanTriggers($_POST['remove']); @@ -598,7 +598,7 @@ public function browseTriggers(): void Config::updateModSettings(['banLastUpdated' => time()]); } - Utils::$context['selected_entity'] = isset($_REQUEST['entity']) && in_array($_REQUEST['entity'], ['ip', 'hostname', 'email', 'member']) ? $_REQUEST['entity'] : 'ip'; + Utils::$context['selected_entity'] = isset($_REQUEST['entity']) && \in_array($_REQUEST['entity'], ['ip', 'hostname', 'email', 'member']) ? $_REQUEST['entity'] : 'ip'; $listOptions = [ 'id' => 'ban_trigger_list', @@ -1086,7 +1086,7 @@ public static function updateBanMembers(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (!in_array($row['id_member'], $allMembers)) { + if (!\in_array($row['id_member'], $allMembers)) { $allMembers[] = $row['id_member']; // Do they need an update? @@ -1129,7 +1129,7 @@ public static function updateBanMembers(): void while ($row = Db::$db->fetch_assoc($request)) { // Don't do this twice! - if (!in_array($row['id_member'], $allMembers)) { + if (!\in_array($row['id_member'], $allMembers)) { $updates[$row['new_value']][] = $row['id_member']; $allMembers[] = $row['id_member']; } @@ -1510,7 +1510,7 @@ protected function __construct() } // Mark the appropriate menu entry as selected - if (array_key_exists($this->subaction, Menu::$loaded['admin']->tab_data['tabs'])) { + if (\array_key_exists($this->subaction, Menu::$loaded['admin']->tab_data['tabs'])) { Menu::$loaded['admin']->tab_data['tabs'][$this->subaction]['is_selected'] = true; } @@ -1535,7 +1535,7 @@ protected function edit2(): void $ban_info['is_new'] = empty($ban_info['id']); $ban_info['expire_date'] = !empty($_POST['expire_date']) ? (int) $_POST['expire_date'] : 0; $ban_info['expiration'] = [ - 'status' => isset($_POST['expiration']) && in_array($_POST['expiration'], ['never', 'one_day', 'expired']) ? $_POST['expiration'] : 'never', + 'status' => isset($_POST['expiration']) && \in_array($_POST['expiration'], ['never', 'one_day', 'expired']) ? $_POST['expiration'] : 'never', 'days' => $ban_info['expire_date'], ]; $ban_info['db_expiration'] = $ban_info['expiration']['status'] == 'never' ? 'NULL' : ($ban_info['expiration']['status'] == 'one_day' ? time() + 24 * 60 * 60 * $ban_info['expire_date'] : 0); @@ -1636,8 +1636,8 @@ protected function banLoadAdditionalIPs(int $member_id): array $return = []; foreach ($search_list as $key => $callable) { - if (is_callable($callable)) { - $return[$key] = call_user_func($callable, $member_id); + if (\is_callable($callable)) { + $return[$key] = \call_user_func($callable, $member_id); } } @@ -1728,7 +1728,7 @@ protected function saveTriggers(array $suggestions, int $ban_group, int $member ]; foreach ($suggestions as $key => $value) { - if (is_array($value)) { + if (\is_array($value)) { $triggers[$key] = $value; } else { $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; @@ -1765,7 +1765,7 @@ protected function saveTriggers(array $suggestions, int $ban_group, int $member */ protected function removeBanGroups(array $group_ids): bool { - if (!is_array($group_ids)) { + if (!\is_array($group_ids)) { $group_ids = [$group_ids]; } @@ -1942,7 +1942,7 @@ protected function validateTriggers(array &$triggers): array } else { $ban_triggers['user']['id_member'] = $value; } - } elseif (in_array($key, ['ips_in_messages', 'ips_in_errors'])) { + } elseif (\in_array($key, ['ips_in_messages', 'ips_in_errors'])) { // Special case, those two are arrays themselves $values = array_unique($value); unset($value); @@ -1974,7 +1974,7 @@ protected function validateTriggers(array &$triggers): array Utils::$context['ban_errors'][] = 'no_bantype_selected'; } - if (isset($value) && !is_array($value)) { + if (isset($value) && !\is_array($value)) { $log_info[] = [ 'value' => $value, 'bantype' => $key, @@ -2069,7 +2069,7 @@ protected function addTriggers(int $group_id = 0, array $triggers = [], array $l foreach ($triggers as $key => $trigger) { // Exceptions, exceptions, exceptions...always exceptions... :P - if (in_array($key, ['ips_in_messages', 'ips_in_errors'])) { + if (\in_array($key, ['ips_in_messages', 'ips_in_errors'])) { foreach ($trigger as $real_trigger) { $insertTriggers[] = array_merge($values, $real_trigger); } @@ -2384,7 +2384,7 @@ protected static function removeBanTriggers(array|int $items_ids = [], ?int $gro return false; } - if (!is_array($items_ids)) { + if (!\is_array($items_ids)) { $items_ids = [$items_ids]; } diff --git a/Sources/Actions/Admin/Boards.php b/Sources/Actions/Admin/Boards.php index 40c71fffcf..b37a4fcc58 100644 --- a/Sources/Actions/Admin/Boards.php +++ b/Sources/Actions/Admin/Boards.php @@ -99,7 +99,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -115,7 +115,7 @@ public function main(): void { Theme::loadTemplate('ManageBoards'); - if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'move' && in_array($_REQUEST['move_to'], ['child', 'before', 'after', 'top'])) { + if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'move' && \in_array($_REQUEST['move_to'], ['child', 'before', 'after', 'top'])) { User::$me->checkSession('get'); SecurityToken::validate('admin-bm-' . (int) $_REQUEST['src_board'], 'request'); @@ -479,8 +479,8 @@ public function editBoard(): void // Load all membergroups except admin and moderator. foreach (Group::loadSimple(Group::LOAD_BOTH, [Group::ADMIN, Group::MOD]) as $group) { - $group->allow = in_array($group->id, $curBoard['member_groups']); - $group->deny = in_array($group->id, $curBoard['deny_groups']); + $group->allow = \in_array($group->id, $curBoard['member_groups']); + $group->deny = \in_array($group->id, $curBoard['deny_groups']); $group->name = $group->id === Group::GUEST ? Lang::$txt['parent_guests_only'] : ($group->id === Group::REGULAR ? Lang::$txt['parent_members_only'] : $group->name); @@ -557,7 +557,7 @@ public function editBoard(): void Utils::$context['board']->moderator_list = empty(Utils::$context['board']->moderators) ? '' : '"' . implode('", "', Utils::$context['board']->moderators) . '"'; if (!empty(Utils::$context['board']->moderators)) { - list(Utils::$context['board']->last_moderator_id) = array_slice(array_keys(Utils::$context['board']->moderators), -1); + list(Utils::$context['board']->last_moderator_id) = \array_slice(array_keys(Utils::$context['board']->moderators), -1); } // Get all the groups assigned as moderators. @@ -581,7 +581,7 @@ public function editBoard(): void Utils::$context['board']->moderator_groups_list = empty(Utils::$context['board']->moderator_groups) ? '' : '"' . implode('", &qout;', Utils::$context['board']->moderator_groups) . '"'; if (!empty(Utils::$context['board']->moderator_groups)) { - list(Utils::$context['board']->last_moderator_group_id) = array_slice(array_keys(Utils::$context['board']->moderator_groups), -1); + list(Utils::$context['board']->last_moderator_group_id) = \array_slice(array_keys(Utils::$context['board']->moderator_groups), -1); } // Get all the themes... @@ -646,7 +646,7 @@ public function editBoard2(): void } // Change the boardorder of this board? elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) { - if (!in_array($_POST['placement'], ['before', 'after', 'child'])) { + if (!\in_array($_POST['placement'], ['before', 'after', 'child'])) { ErrorHandler::fatalLang('mangled_post', false); } @@ -671,7 +671,7 @@ public function editBoard2(): void } } - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { + if (\strlen(implode(',', $boardOptions['access_groups'])) > 255 || \strlen(implode(',', $boardOptions['deny_groups'])) > 255) { ErrorHandler::fatalLang('too_many_groups', false); } @@ -681,7 +681,7 @@ public function editBoard2(): void $boardOptions['moderator_string'] = $_POST['moderators']; - if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) { + if (isset($_POST['moderator_list']) && \is_array($_POST['moderator_list'])) { $moderators = []; foreach ($_POST['moderator_list'] as $moderator) { @@ -693,7 +693,7 @@ public function editBoard2(): void $boardOptions['moderator_group_string'] = $_POST['moderator_groups']; - if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) { + if (isset($_POST['moderator_group_list']) && \is_array($_POST['moderator_group_list'])) { $moderator_groups = []; foreach ($_POST['moderator_group_list'] as $moderator_group) { diff --git a/Sources/Actions/Admin/Calendar.php b/Sources/Actions/Admin/Calendar.php index bca716bf96..593213acfb 100644 --- a/Sources/Actions/Admin/Calendar.php +++ b/Sources/Actions/Admin/Calendar.php @@ -91,7 +91,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -294,7 +294,7 @@ public function edit(): void Utils::$context['event']->selected_occurrence->fixTimezone(); Theme::loadTemplate('EventEditor'); - Theme::addJavaScriptVar('monthly_byday_items', count(Utils::$context['event']->byday_items) - 1); + Theme::addJavaScriptVar('monthly_byday_items', \count(Utils::$context['event']->byday_items) - 1); Theme::loadJavaScriptFile('event.js', ['defer' => true], 'smf_event'); } @@ -420,7 +420,7 @@ public function import(): void 'value' => Utils::$context['calendar_subscriptions'], ], 'get_count' => [ - 'value' => count(Utils::$context['calendar_subscriptions']), + 'value' => \count(Utils::$context['calendar_subscriptions']), ], 'no_items_label' => Lang::$txt['none'], 'columns' => [ diff --git a/Sources/Actions/Admin/ErrorLog.php b/Sources/Actions/Admin/ErrorLog.php index f8b8684095..8788d5a510 100644 --- a/Sources/Actions/Admin/ErrorLog.php +++ b/Sources/Actions/Admin/ErrorLog.php @@ -137,7 +137,7 @@ public function view(): void $this->filter = [ 'variable' => $_GET['filter'], 'value' => [ - 'sql' => in_array($_GET['filter'], ['message', 'url', 'file']) ? base64_decode(strtr($_GET['value'], [' ' => '+'])) : Db::$db->escape_wildcard_string($_GET['value']), + 'sql' => \in_array($_GET['filter'], ['message', 'url', 'file']) ? base64_decode(strtr($_GET['value'], [' ' => '+'])) : Db::$db->escape_wildcard_string($_GET['value']), ], 'href' => ';filter=' . $_GET['filter'] . ';value=' . urlencode($_GET['value']), 'entity' => $this->filters[$_GET['filter']]['txt'], @@ -277,7 +277,7 @@ public function view(): void LIMIT {int:members}', [ 'member_list' => $members, - 'members' => count($members), + 'members' => \count($members), ], ); @@ -435,7 +435,7 @@ public function viewFile(): void // We don't want to slice off too many so lets make sure we stop at the last one $max = min($max, max(array_keys($file_data))); - $file_data = array_slice($file_data, $min - 1, (int) ($max - $min)); + $file_data = \array_slice($file_data, $min - 1, (int) ($max - $min)); Utils::$context['file_data'] = [ 'contents' => $file_data, diff --git a/Sources/Actions/Admin/Features.php b/Sources/Actions/Admin/Features.php index 4c6329c0c0..91c0d038e5 100644 --- a/Sources/Actions/Admin/Features.php +++ b/Sources/Actions/Admin/Features.php @@ -96,7 +96,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -208,13 +208,13 @@ public function bbc(): void if (!isset($_POST['disabledBBC_enabledTags'])) { $_POST['disabledBBC_enabledTags'] = []; - } elseif (!is_array($_POST['disabledBBC_enabledTags'])) { + } elseif (!\is_array($_POST['disabledBBC_enabledTags'])) { $_POST['disabledBBC_enabledTags'] = [$_POST['disabledBBC_enabledTags']]; } if (!isset($_POST['legacyBBC_enabledTags'])) { $_POST['legacyBBC_enabledTags'] = []; - } elseif (!is_array($_POST['legacyBBC_enabledTags'])) { + } elseif (!\is_array($_POST['legacyBBC_enabledTags'])) { $_POST['legacyBBC_enabledTags'] = [$_POST['legacyBBC_enabledTags']]; } @@ -222,7 +222,7 @@ public function bbc(): void // Enable all children if parent is enabled foreach ($bbcTagsChildren as $tag => $children) { - if (in_array($tag, $_POST['disabledBBC_enabledTags'])) { + if (\in_array($tag, $_POST['disabledBBC_enabledTags'])) { $_POST['disabledBBC_enabledTags'] = array_merge($_POST['disabledBBC_enabledTags'], $children); } } @@ -350,7 +350,7 @@ public function signature(): void if (!empty($sig_limits[2])) { $count = 0; - for ($i = 0; $i < strlen($sig); $i++) { + for ($i = 0; $i < \strlen($sig); $i++) { if ($sig[$i] == "\n") { $count++; @@ -469,7 +469,7 @@ public function signature(): void if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) { $sizes = Image::getSizeExternal($matches[7][$key]); - if (is_array($sizes)) { + if (\is_array($sizes)) { // Too wide? if ($sizes[0] > $sig_limits[5] && $sig_limits[5]) { $width = $sig_limits[5]; @@ -587,7 +587,7 @@ public function signature(): void if (!isset($_POST['signature_bbc_enabledTags'])) { $_POST['signature_bbc_enabledTags'] = []; - } elseif (!is_array($_POST['signature_bbc_enabledTags'])) { + } elseif (!\is_array($_POST['signature_bbc_enabledTags'])) { $_POST['signature_bbc_enabledTags'] = [$_POST['signature_bbc_enabledTags']]; } @@ -673,7 +673,7 @@ public function profile(): void if (!empty($_POST['reg'])) { foreach ($_POST['reg'] as $value) { - if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) { + if (\in_array($value, $standard_fields) && !isset($disable_fields[$value])) { $reg_fields[] = $value; } } @@ -968,7 +968,7 @@ public function profileEdit(): void 'bbc' => $row['bbc'] ? true : false, 'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false, 'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '', - 'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : ['', '', ''], + 'options' => \strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : ['', '', ''], 'active' => $row['active'], 'private' => $row['private'], 'can_search' => $row['can_search'], @@ -1011,7 +1011,7 @@ public function profileEdit(): void } // Are we moving it? - if (Utils::$context['fid'] && isset($_GET['move']) && in_array(Utils::htmlspecialchars($_GET['move']), $move_to)) { + if (Utils::$context['fid'] && isset($_GET['move']) && \in_array(Utils::htmlspecialchars($_GET['move']), $move_to)) { $fields = []; $new_sort = []; @@ -1031,16 +1031,16 @@ public function profileEdit(): void $idx = array_search(Utils::$context['fid'], $fields); - if ($_GET['move'] == 'down' && count($fields) - 1 > $idx) { - $new_sort = array_slice($fields, 0, $idx, true); + if ($_GET['move'] == 'down' && \count($fields) - 1 > $idx) { + $new_sort = \array_slice($fields, 0, $idx, true); $new_sort[] = $fields[$idx + 1]; $new_sort[] = $fields[$idx]; - $new_sort += array_slice($fields, $idx + 2, count($fields), true); - } elseif (Utils::$context['fid'] > 0 and $idx < count($fields)) { - $new_sort = array_slice($fields, 0, ($idx - 1), true); + $new_sort += \array_slice($fields, $idx + 2, \count($fields), true); + } elseif (Utils::$context['fid'] > 0 and $idx < \count($fields)) { + $new_sort = \array_slice($fields, 0, ($idx - 1), true); $new_sort[] = $fields[$idx]; $new_sort[] = $fields[$idx - 1]; - $new_sort += array_slice($fields, ($idx + 1), count($fields), true); + $new_sort += \array_slice($fields, ($idx + 1), \count($fields), true); } else { // @todo implement an error handler Utils::redirectexit('action=admin;area=featuresettings;sa=profile'); @@ -1166,7 +1166,7 @@ public function profileEdit(): void $i = 0; - while (in_array($col_name, $current_fields)) { + while (\in_array($col_name, $current_fields)) { // First try appending an integer to the supplied name. if ($i <= 9) { $col_name = $initial_col_name . $i; @@ -1226,7 +1226,7 @@ public function profileEdit(): void } // Still exists? - if (in_array($option, $newOptions)) { + if (\in_array($option, $newOptions)) { $takenKeys[] = $k; } } @@ -1234,7 +1234,7 @@ public function profileEdit(): void // Finally - have we renamed it - or is it really gone? foreach ($optionChanges as $k => $option) { // Just been renamed? - if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) { + if (!\in_array($k, $takenKeys) && !empty($newOptions[$k])) { Db::$db->query( '', 'UPDATE {db_prefix}themes @@ -1510,7 +1510,7 @@ public static function basicConfigVars(): array // If admins have set it up as an on-registration thing, they can't set a default value (because it'll never be used) $disabled_fields = isset(Config::$modSettings['disabled_profile_fields']) ? explode(',', Config::$modSettings['disabled_profile_fields']) : []; $reg_fields = isset(Config::$modSettings['registration_fields']) ? explode(',', Config::$modSettings['registration_fields']) : []; - $can_personal_text = !in_array('personal_text', $disabled_fields) && !in_array('personal_text', $reg_fields); + $can_personal_text = !\in_array('personal_text', $disabled_fields) && !\in_array('personal_text', $reg_fields); $config_vars = [ // Big Options... polls, sticky, bbc.... @@ -1757,9 +1757,9 @@ public static function list_getProfileFields(int $start, int $items_per_page, st $list[] = [ 'id' => $field, 'label' => Lang::$txt['standard_profile_field_' . $field] ?? (Lang::$txt[$field] ?? $field), - 'disabled' => in_array($field, $disabled_fields), - 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration), - 'can_show_register' => !in_array($field, $fields_no_registration), + 'disabled' => \in_array($field, $disabled_fields), + 'on_register' => \in_array($field, $registration_fields) && !\in_array($field, $fields_no_registration), + 'can_show_register' => !\in_array($field, $fields_no_registration), ]; } } else { diff --git a/Sources/Actions/Admin/Find.php b/Sources/Actions/Admin/Find.php index 82dc01b803..e877e90cbb 100644 --- a/Sources/Actions/Admin/Find.php +++ b/Sources/Actions/Admin/Find.php @@ -175,7 +175,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } } @@ -229,11 +229,11 @@ public function internal(): void foreach ($this->settings_search as $setting_area) { // Get a list of their variables. - $config_vars = call_user_func($setting_area[0], true); + $config_vars = \call_user_func($setting_area[0], true); foreach ($config_vars as $var) { - if (!empty($var[1]) && !in_array($var[0], ['permissions', 'switch', 'desc'])) { - $search_data['settings'][] = [$var[(isset($var[2]) && in_array($var[2], ['file', 'db'])) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && in_array($var[2], ['file', 'db'])) || isset($var[3]) ? (in_array($var[2], ['file', 'db']) ? $var[1] : $var[3]) : '']; + if (!empty($var[1]) && !\in_array($var[0], ['permissions', 'switch', 'desc'])) { + $search_data['settings'][] = [$var[(isset($var[2]) && \in_array($var[2], ['file', 'db'])) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && \in_array($var[2], ['file', 'db'])) || isset($var[3]) ? (\in_array($var[2], ['file', 'db']) ? $var[1] : $var[3]) : '']; } } } @@ -248,7 +248,7 @@ public function internal(): void foreach ($data as $item) { $found = false; - if (!is_array($item[0])) { + if (!\is_array($item[0])) { $item[0] = [$item[0]]; } diff --git a/Sources/Actions/Admin/Languages.php b/Sources/Actions/Admin/Languages.php index 1a574f4d6c..e4e1599d92 100644 --- a/Sources/Actions/Admin/Languages.php +++ b/Sources/Actions/Admin/Languages.php @@ -84,7 +84,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -362,7 +362,7 @@ public function download(): void // Mark those which are now writable as such. foreach (Utils::$context['files'] as $type => $data) { foreach ($data as $k => $file) { - if (!$file['writable'] && !in_array($file['destination'], Utils::$context['still_not_writable'])) { + if (!$file['writable'] && !\in_array($file['destination'], Utils::$context['still_not_writable'])) { Utils::$context['files'][$type][$k]['writable'] = true; } } @@ -730,7 +730,7 @@ public function editEntries() // Check we have themes with a path and a name - just in case - and add the path. foreach ($themes as $id => $data) { - if (count($data) != 2) { + if (\count($data) != 2) { unset($themes[$id]); } elseif (is_dir($data['theme_dir'] . '/languages')) { $lang_dirs[$id] = $data['theme_dir'] . '/languages'; @@ -930,7 +930,7 @@ function ($val1, $val2) { if (!empty($_POST['edit'])) { foreach ($_POST['edit'] as $k => $v) { - if (is_string($v)) { + if (\is_string($v)) { // Only try to save if 'edit' was specified and if the string has changed if ( $v == 'edit' @@ -949,7 +949,7 @@ function ($val1, $val2) { 'string' => $this->cleanLangString($_POST['entry'][$k], false), ]; } - } elseif (is_array($v)) { + } elseif (\is_array($v)) { foreach ($v as $subk => $subv) { if ( $subv == 'edit' @@ -980,7 +980,7 @@ function ($val1, $val2) { // How many strings will PHP let us edit at once? // Each string needs 3 inputs, and there are 5 others in the form. - Utils::$context['max_inputs'] = floor(ini_get('max_input_vars') / 3) - 5; + Utils::$context['max_inputs'] = floor(\ini_get('max_input_vars') / 3) - 5; // Do we want to override the helptxt for certain types of text variables? $special_groups = [ @@ -995,7 +995,7 @@ function ($val1, $val2) { foreach ($allows_add_remove[$file_id]['add'] as $var_group) { $group = !empty($special_groups[$file_id][$var_group]) ? $special_groups[$file_id][$var_group] : $var_group; - if (in_array($var_group, $allows_add_remove[$file_id]['add'])) { + if (\in_array($var_group, $allows_add_remove[$file_id]['add'])) { Utils::$context['can_add_lang_entry'][$group] = true; } } @@ -1018,7 +1018,7 @@ function ($val1, $val2) { $entries[$matches[2] . (isset($matches[3]) ? '[' . $matches[3] . ']' : '')] = [ 'type' => $matches[1], 'group' => !empty($special_groups[$file_id][$matches[1]]) ? $special_groups[$file_id][$matches[1]] : $matches[1], - 'can_remove' => isset($allows_add_remove[$file_id]['remove']) && in_array($matches[1], $allows_add_remove[$file_id]['remove']), + 'can_remove' => isset($allows_add_remove[$file_id]['remove']) && \in_array($matches[1], $allows_add_remove[$file_id]['remove']), 'key' => $matches[2], 'subkey' => $matches[3], 'full' => $matches[0], @@ -1034,7 +1034,7 @@ function ($val1, $val2) { foreach ($entries as $entryKey => $entryValue) { // Ignore some things we set separately. - if (in_array($entryKey, array_keys($primary_settings))) { + if (\in_array($entryKey, array_keys($primary_settings))) { continue; } @@ -1136,7 +1136,7 @@ function ($val1, $val2) { $save_cache['enabled'] = true; } // Should we remove this one? - elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove']) { + elseif (isset($remove_strings[$entryKey]) && \in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove']) { $save_cache['enabled'] = true; } // Just keep this one as it is @@ -1216,7 +1216,7 @@ function ($val1, $val2) { } // Remove this entry only if it is allowed - if (isset($remove_strings[$entryValue['key']]) && in_array($entryValue['subkey'], $remove_strings[$entryValue['key']]) && $entryValue['can_remove']) { + if (isset($remove_strings[$entryValue['key']]) && \in_array($entryValue['subkey'], $remove_strings[$entryValue['key']]) && $entryValue['can_remove']) { $entryValue['entry'] = '\'\''; $final_saves[$entryKey] = [ @@ -1231,7 +1231,7 @@ function ($val1, $val2) { 'key' => $entryValue['key'], 'subkey' => $entryValue['subkey'], 'value' => $editing_string, - 'rows' => strlen($editing_string) / 38 + substr_count($editing_string, "\n") + 1, + 'rows' => \strlen($editing_string) / 38 + substr_count($editing_string, "\n") + 1, 'can_remove' => $entryValue['can_remove'], ]; } @@ -1254,7 +1254,7 @@ function ($val1, $val2) { } // Remove this entry only if it is allowed - if (in_array($entryValue['key'], $remove_strings) && $entryValue['can_remove']) { + if (\in_array($entryValue['key'], $remove_strings) && $entryValue['can_remove']) { $entryValue['entry'] = '\'\''; $final_saves[$entryKey] = [ @@ -1269,7 +1269,7 @@ function ($val1, $val2) { 'key' => $entryValue['key'], 'subkey' => null, 'value' => $editing_string, - 'rows' => (int) (strlen($editing_string) / 38) + substr_count($editing_string, "\n") + 1, + 'rows' => (int) (\strlen($editing_string) / 38) + substr_count($editing_string, "\n") + 1, 'can_remove' => $entryValue['can_remove'], ]; } @@ -1281,7 +1281,7 @@ function ($val1, $val2) { foreach ($add_strings as $string_key => $string_val) { // Adding a normal string - if (isset($string_val['string']) && is_string($string_val['string'])) { + if (isset($string_val['string']) && \is_string($string_val['string'])) { $type = $special_types[$string_val['group']] ?? $string_val['group']; if (empty(Utils::$context['can_add_lang_entry'][$type])) { @@ -1523,7 +1523,7 @@ public static function list_getLanguagesList(): array */ public static function list_getNumLanguages(): int { - return count(Lang::get()); + return \count(Lang::get()); } /** @@ -1659,7 +1659,7 @@ protected function cleanLangString(string $string, bool $to_display = true): str // We'll revert it back to an entity when saving. $string = str_replace(''', "\\'", $string); - for ($i = 0; $i < strlen($string); $i++) { + for ($i = 0; $i < \strlen($string); $i++) { // Handle escapes first. if ($string[$i] == '\\') { // Toggle the escape. @@ -1726,7 +1726,7 @@ protected function cleanLangString(string $string, bool $to_display = true): str $new_string .= '{%' . $matches[1] . '%}'; // We're not going to reparse this. - $i += strlen($matches[1]) - 1; + $i += \strlen($matches[1]) - 1; } continue; @@ -1754,7 +1754,7 @@ protected function cleanLangString(string $string, bool $to_display = true): str // This is for deciding whether to HTML a quote. $in_html = false; - for ($i = 0; $i < strlen($string); $i++) { + for ($i = 0; $i < \strlen($string); $i++) { // We don't do parsed strings apart from for breaks. if ($in_string == 2) { $in_string = 0; @@ -1780,7 +1780,7 @@ protected function cleanLangString(string $string, bool $to_display = true): str } $new_string .= $matches[1]; - $i += strlen($matches[1]) + 3; + $i += \strlen($matches[1]) + 3; $in_string = 0; } diff --git a/Sources/Actions/Admin/Logs.php b/Sources/Actions/Admin/Logs.php index 84af4fc125..308701fb90 100644 --- a/Sources/Actions/Admin/Logs.php +++ b/Sources/Actions/Admin/Logs.php @@ -163,7 +163,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][1]) ? [$this, self::$subactions[$this->subaction][1]] : Utils::getCallable(self::$subactions[$this->subaction][1]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -253,7 +253,7 @@ function togglePruned() $vals = []; foreach ($config_vars as $config_var) { - if (!is_array($config_var) || !in_array($config_var[1], self::$prune_toggle)) { + if (!\is_array($config_var) || !\in_array($config_var[1], self::$prune_toggle)) { continue; } @@ -285,7 +285,7 @@ function togglePruned() Config::$modSettings[self::$prune_toggle[$key]] = $value; } } else { - $defaults = array_pad([30, 180, 180, 180, 30, 0], count(self::$prune_toggle), 0); + $defaults = array_pad([30, 180, 180, 180, 30, 0], \count(self::$prune_toggle), 0); foreach (array_combine(self::$prune_toggle, $defaults) as $setting => $default) { Config::$modSettings[$setting] = $default; diff --git a/Sources/Actions/Admin/Mail.php b/Sources/Actions/Admin/Mail.php index 98d80447d3..3e98292ca3 100644 --- a/Sources/Actions/Admin/Mail.php +++ b/Sources/Actions/Admin/Mail.php @@ -90,7 +90,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -281,7 +281,7 @@ public function settings(): void $i = 0; foreach (self::$processedBirthdayEmails as $index => $email) { - $is_last = ++$i == count(self::$processedBirthdayEmails); + $is_last = ++$i == \count(self::$processedBirthdayEmails); Utils::$context['settings_insert_above'] .= ' ' . $index . ': { @@ -407,8 +407,8 @@ public static function getConfigVars(): array '', ['select', 'birthday_email', $emails, 'value' => ['subject' => $subject, 'body' => $body], 'javascript' => 'onchange="fetch_birthday_preview()"'], - 'birthday_subject' => ['var_message', 'birthday_subject', 'var_message' => self::$processedBirthdayEmails[empty(Config::$modSettings['birthday_email']) ? 'happy_birthday' : Config::$modSettings['birthday_email']]['subject'], 'disabled' => true, 'size' => strlen($subject) + 3], - 'birthday_body' => ['var_message', 'birthday_body', 'var_message' => nl2br($body), 'disabled' => true, 'size' => ceil(strlen($body) / 25)], + 'birthday_subject' => ['var_message', 'birthday_subject', 'var_message' => self::$processedBirthdayEmails[empty(Config::$modSettings['birthday_email']) ? 'happy_birthday' : Config::$modSettings['birthday_email']]['subject'], 'disabled' => true, 'size' => \strlen($subject) + 3], + 'birthday_body' => ['var_message', 'birthday_body', 'var_message' => nl2br($body), 'disabled' => true, 'size' => ceil(\strlen($body) / 25)], ]; IntegrationHook::call('integrate_modify_mail_settings', [&$config_vars]); diff --git a/Sources/Actions/Admin/Maintenance.php b/Sources/Actions/Admin/Maintenance.php index 563cc06752..a0429134c8 100644 --- a/Sources/Actions/Admin/Maintenance.php +++ b/Sources/Actions/Admin/Maintenance.php @@ -138,7 +138,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]['function']) ? [$this, self::$subactions[$this->subaction]['function']] : Utils::getCallable(self::$subactions[$this->subaction]['function']); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } // Any special activity? @@ -146,7 +146,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]['activities'][$this->activity]) ? [$this, self::$subactions[$this->subaction]['activities'][$this->activity]] : Utils::getCallable(self::$subactions[$this->subaction]['activities'][$this->activity]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -159,7 +159,7 @@ public function execute(): void */ public function routine(): void { - if (isset($_GET['done']) && in_array($_GET['done'], ['recount', 'rebuild_settings'])) { + if (isset($_GET['done']) && \in_array($_GET['done'], ['recount', 'rebuild_settings'])) { Utils::$context['maintenance_finished'] = Lang::$txt['maintain_' . $_GET['done']]; } } @@ -956,7 +956,7 @@ public function optimize(): void } // If there aren't any tables then I believe that would mean the world has exploded... - Utils::$context['num_tables'] = count($tables); + Utils::$context['num_tables'] = \count($tables); if (Utils::$context['num_tables'] == 0) { ErrorHandler::fatal('You appear to be running SMF in a flat file mode... fantastic!', false); @@ -1004,7 +1004,7 @@ public function optimize(): void // Number of tables, etc... Utils::$context['database_numb_tables'] = Lang::getTxt('database_numb_tables', [Utils::$context['num_tables']]); - Utils::$context['num_tables_optimized'] = count($_SESSION['optimized_tables']); + Utils::$context['num_tables_optimized'] = \count($_SESSION['optimized_tables']); Utils::$context['optimized_tables'] = $_SESSION['optimized_tables']; unset($_SESSION['optimized_tables']); } @@ -1080,7 +1080,7 @@ public function entitiesToUnicode(): void 'smileys', 'themes', ]; - Utils::$context['num_tables'] = count($tables); + Utils::$context['num_tables'] = \count($tables); // Loop through all tables that need converting. for (; Utils::$context['table'] < Utils::$context['num_tables']; Utils::$context['table']++) { @@ -1149,7 +1149,7 @@ public function entitiesToUnicode(): void while ($row = Db::$db->fetch_assoc($request)) { if ($row['Key_name'] === 'PRIMARY') { - if ((empty($primary_key) || $row['Seq_in_index'] == 1) && !in_array(strtolower($row['Column_name']), $columns)) { + if ((empty($primary_key) || $row['Seq_in_index'] == 1) && !\in_array(strtolower($row['Column_name']), $columns)) { $primary_key = $row['Column_name']; } @@ -1379,9 +1379,9 @@ public function changeMsgBodyLength(): void Utils::$context['sub_template'] = 'convert_msgbody'; if (!empty($id_msg_exceeding)) { - if (count($id_msg_exceeding) > 100) { - $query_msg = array_slice($id_msg_exceeding, 0, 100); - Utils::$context['exceeding_messages_morethan'] = Lang::getTxt('exceeding_messages_morethan', [count($id_msg_exceeding) - 100]); + if (\count($id_msg_exceeding) > 100) { + $query_msg = \array_slice($id_msg_exceeding, 0, 100); + Utils::$context['exceeding_messages_morethan'] = Lang::getTxt('exceeding_messages_morethan', [\count($id_msg_exceeding) - 100]); } else { $query_msg = $id_msg_exceeding; } @@ -1464,7 +1464,7 @@ public function purgeInactiveMembers(): void // Need to get all groups then work out which (if any) we avoid. foreach (Group::loadSimple(Group::LOAD_BOTH, [Group::GUEST, Group::MOD]) as $group) { // Avoid this one? - if (!in_array($group->id, $groups)) { + if (!\in_array($group->id, $groups)) { // Post group? if ($group->min_posts != -1) { $where .= ' AND mem.id_post_group != {int:id_post_group_' . $group->id . '}'; @@ -1477,7 +1477,7 @@ public function purgeInactiveMembers(): void } // If we have ungrouped unselected we need to avoid those guys. - if (!in_array(0, $groups)) { + if (!\in_array(0, $groups)) { $where .= ' AND (mem.id_group != 0 OR mem.additional_groups != {string:blank_add_groups})'; $where_vars['blank_add_groups'] = ''; } @@ -1494,7 +1494,7 @@ public function purgeInactiveMembers(): void $members = []; while ($row = Db::$db->fetch_assoc($request)) { - if (!$row['is_mod'] || !in_array(3, $groups)) { + if (!$row['is_mod'] || !\in_array(3, $groups)) { $members[] = $row['id_member']; } } @@ -1856,7 +1856,7 @@ public function pruneDrafts(): void Db::$db->free_result($request); // If we have old drafts, remove them - if (count($drafts) > 0) { + if (\count($drafts) > 0) { Draft::delete($drafts, false); } } @@ -1936,7 +1936,7 @@ function ($hook) use ($current_filter) { 'value' => array_reduce( $filtered_hooks, function ($accumulator, $functions) { - return $accumulator + count($functions); + return $accumulator + \count($functions); }, 0, ), @@ -2134,7 +2134,7 @@ public static function getIntegrationHooksData($start, $per_page, $sort, $filter array_multisort($sort_array, $sort_types[$sort][1], $temp_data); - return array_slice($temp_data, $start, $per_page, true); + return \array_slice($temp_data, $start, $per_page, true); } /** @@ -2356,7 +2356,7 @@ protected function getIntegrationHooks(): array */ protected static function getFileRecursive(string $dirname): array { - return \iterator_to_array( + return iterator_to_array( new \RecursiveIteratorIterator( new \RecursiveCallbackFilterIterator( new \RecursiveDirectoryIterator($dirname, \FilesystemIterator::UNIX_PATHS), diff --git a/Sources/Actions/Admin/Membergroups.php b/Sources/Actions/Admin/Membergroups.php index f344876f38..b78aac028c 100644 --- a/Sources/Actions/Admin/Membergroups.php +++ b/Sources/Actions/Admin/Membergroups.php @@ -89,7 +89,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -389,7 +389,7 @@ public function add(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (empty($illegal_permissions) || !in_array($row['permission'], $illegal_permissions)) { + if (empty($illegal_permissions) || !\in_array($row['permission'], $illegal_permissions)) { $inserts[] = [$id_group, $row['permission'], $row['add_deny']]; } } @@ -466,7 +466,7 @@ public function add(): void } // Make sure all boards selected are stored in a proper array. - $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? [] : $_POST['boardaccess']; + $accesses = empty($_POST['boardaccess']) || !\is_array($_POST['boardaccess']) ? [] : $_POST['boardaccess']; $changed_boards['allow'] = []; $changed_boards['deny'] = []; @@ -649,7 +649,7 @@ public function edit(): void // People who can manage boards are a bit special. $board_managers = User::groupsAllowedTo('manage_boards', null); - Utils::$context['can_manage_boards'] = in_array($group->id, $board_managers['allowed']); + Utils::$context['can_manage_boards'] = \in_array($group->id, $board_managers['allowed']); // Can this group moderate any boards? Utils::$context['is_moderator_group'] = $group->is_moderator_group; @@ -667,7 +667,7 @@ public function edit(): void $ext = pathinfo(Theme::$current->settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION); // If the extension is not empty, and it is valid. - if (!empty($ext) && in_array($ext, $imageExts)) { + if (!empty($ext) && \in_array($ext, $imageExts)) { Utils::$context['possible_icons'][] = $value; } } @@ -703,7 +703,7 @@ public function edit(): void $group->set([ 'max_messages' => isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0, 'min_posts' => isset($_POST['min_posts']) && isset($_POST['group_type']) && $_POST['group_type'] == -1 && $group->id > Group::MOD ? abs($_POST['min_posts']) : ($group->id == Group::NEWBIE ? 0 : -1), - 'icons' => (empty($_POST['icon_count']) || $_POST['icon_count'] < 0 || !in_array($_POST['icon_image'], Utils::$context['possible_icons'])) ? '' : min((int) $_POST['icon_count'], 99) . '#' . $_POST['icon_image'], + 'icons' => (empty($_POST['icon_count']) || $_POST['icon_count'] < 0 || !\in_array($_POST['icon_image'], Utils::$context['possible_icons'])) ? '' : min((int) $_POST['icon_count'], 99) . '#' . $_POST['icon_image'], 'name' => Utils::htmlspecialchars($_POST['group_name']), 'description' => isset($_POST['group_desc']) && ($group->id == Group::ADMIN || (isset($_POST['group_type']) && $_POST['group_type'] != -1)) ? Utils::htmlTrim(Utils::sanitizeChars(Utils::normalize($_POST['group_desc']))) : '', 'type' => !isset($_POST['group_type']) || $_POST['group_type'] < Group::TYPE_PRIVATE || $_POST['group_type'] > Group::TYPE_FREE || ($_POST['group_type'] == Group::TYPE_PROTECTED && !User::$me->allowedTo('admin_forum')) ? Group::TYPE_PRIVATE : (int) $_POST['group_type'], @@ -753,7 +753,7 @@ public function edit(): void $group->save(); // Time to update the boards this membergroup has access to. - $group->updateBoardAccess(empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? [] : $_POST['boardaccess']); + $group->updateBoardAccess(empty($_POST['boardaccess']) || !\is_array($_POST['boardaccess']) ? [] : $_POST['boardaccess']); // Let's check whether our "show group membership" setting is correct. $request = Db::$db->query( @@ -797,7 +797,7 @@ public function edit(): void $group->moderator_list = empty($group->moderators) ? '' : '"' . implode('", "', $group->moderators) . '"'; if (!empty($group->moderators)) { - list($group->last_moderator_id) = array_slice(array_keys($group->moderators), -1); + list($group->last_moderator_id) = \array_slice(array_keys($group->moderators), -1); } Utils::$context['group'] = $group; diff --git a/Sources/Actions/Admin/Members.php b/Sources/Actions/Admin/Members.php index da779fb8f0..51076a86f0 100644 --- a/Sources/Actions/Admin/Members.php +++ b/Sources/Actions/Admin/Members.php @@ -141,7 +141,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -282,14 +282,14 @@ public function view(): void } // Make sure numeric values are really numeric. - if (in_array($param_info['type'], ['int', 'age'])) { + if (\in_array($param_info['type'], ['int', 'age'])) { $search_params[$param_name] = (int) $search_params[$param_name]; } // Date values have to match a date format that PHP recognizes. elseif ($param_info['type'] == 'date') { $search_params[$param_name] = strtotime($search_params[$param_name] . ' ' . User::getTimezone()); - if (!is_int($search_params[$param_name])) { + if (!\is_int($search_params[$param_name])) { continue; } } elseif ($param_info['type'] == 'inet') { @@ -314,12 +314,12 @@ public function view(): void $upperlimit = sprintf('%04d-%02d-%02d', $datearray['year'] - $search_params[$param_name], $datearray['mon'], $datearray['mday']); $lowerlimit = sprintf('%04d-%02d-%02d', $datearray['year'] - $search_params[$param_name] - 1, $datearray['mon'], $datearray['mday']); - if (in_array($search_params['types'][$param_name], ['-', '--', '='])) { + if (\in_array($search_params['types'][$param_name], ['-', '--', '='])) { $query_parts[] = ($param_info['db_fields'][0]) . ' > {string:' . $param_name . '_minlimit}'; $where_params[$param_name . '_minlimit'] = ($search_params['types'][$param_name] == '--' ? $upperlimit : $lowerlimit); } - if (in_array($search_params['types'][$param_name], ['+', '++', '='])) { + if (\in_array($search_params['types'][$param_name], ['+', '++', '='])) { $query_parts[] = ($param_info['db_fields'][0]) . ' <= {string:' . $param_name . '_pluslimit}'; $where_params[$param_name . '_pluslimit'] = ($search_params['types'][$param_name] == '++' ? $lowerlimit : $upperlimit); @@ -351,9 +351,9 @@ public function view(): void elseif ($param_info['type'] == 'checkbox') { // Each checkbox or no checkbox at all is checked -> ignore. if ( - !is_array($search_params[$param_name]) - || count($search_params[$param_name]) == 0 - || count($search_params[$param_name]) == count($param_info['values']) + !\is_array($search_params[$param_name]) + || \count($search_params[$param_name]) == 0 + || \count($search_params[$param_name]) == \count($param_info['values']) ) { continue; } @@ -364,11 +364,11 @@ public function view(): void } // INET. elseif ($param_info['type'] == 'inet') { - if (count($search_params[$param_name]) === 1) { + if (\count($search_params[$param_name]) === 1) { $query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})'; $where_params[$param_name] = $search_params[$param_name][0]; - } elseif (count($search_params[$param_name]) === 2) { + } elseif (\count($search_params[$param_name]) === 2) { $query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})'; $where_params[$param_name . '_low'] = $search_params[$param_name]['low']; @@ -392,7 +392,7 @@ public function view(): void $mg_query_parts = []; // Primary membergroups, but only if at least was was not selected. - if (!empty($search_params['membergroups'][1]) && count($this->membergroups) != count($search_params['membergroups'][1])) { + if (!empty($search_params['membergroups'][1]) && \count($this->membergroups) != \count($search_params['membergroups'][1])) { $mg_query_parts[] = 'mem.id_group IN ({array_int:group_check})'; $where_params['group_check'] = $search_params['membergroups'][1]; } @@ -402,7 +402,7 @@ public function view(): void !empty($search_params['membergroups'][2]) && ( empty($search_params['membergroups'][1]) - || count($this->membergroups) != count($search_params['membergroups'][1]) + || \count($this->membergroups) != \count($search_params['membergroups'][1]) ) ) { foreach ($search_params['membergroups'][2] as $mg) { @@ -417,7 +417,7 @@ public function view(): void } // Get all selected post count related membergroups. - if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($this->postgroups)) { + if (!empty($search_params['postgroups']) && \count($search_params['postgroups']) != \count($this->postgroups)) { $query_parts[] = 'id_post_group IN ({array_int:post_groups})'; $where_params['post_groups'] = $search_params['postgroups']; } @@ -600,7 +600,7 @@ public function view(): void ], 'data' => [ 'function' => function ($rowData) { - return 'id || $rowData['id_group'] == 1 || in_array(1, explode(',', $rowData['additional_groups'])) ? ' disabled' : '') . '>'; + return 'id || $rowData['id_group'] == 1 || \in_array(1, explode(',', $rowData['additional_groups'])) ? ' disabled' : '') . '>'; }, 'class' => 'centercol', ], @@ -678,14 +678,14 @@ public function browse(): void // Allowed filters are those we can have, in theory. $allowed_filters = $browse_type == 'approve' ? [User::UNAPPROVED, User::REQUESTED_DELETE, User::NEED_COPPA] : [User::NOT_ACTIVATED, User::UNVALIDATED]; - $this->current_filter = isset($_REQUEST['filter']) && in_array($_REQUEST['filter'], $allowed_filters) && !empty($this->activation_numbers[$_REQUEST['filter']]) ? (int) $_REQUEST['filter'] : -1; + $this->current_filter = isset($_REQUEST['filter']) && \in_array($_REQUEST['filter'], $allowed_filters) && !empty($this->activation_numbers[$_REQUEST['filter']]) ? (int) $_REQUEST['filter'] : -1; // Sort out the different sub areas that we can actually filter by. $available_filters = []; foreach ($this->activation_numbers as $type => $amount) { // We have some of these... - if (in_array($type, $allowed_filters) && $amount > 0) { + if (\in_array($type, $allowed_filters) && $amount > 0) { $available_filters[] = [ 'type' => $type, 'amount' => $amount, @@ -980,7 +980,7 @@ function onSelectChange() } // Is there any need to show filters? - if (isset($available_filters) && count($available_filters) > 1) { + if (isset($available_filters) && \count($available_filters) > 1) { $filterOptions = ' ' . Lang::$txt['admin_browse_filter_by'] . ': '; @@ -1228,7 +1228,7 @@ public function approve(): void } // Log what we did? - if (!empty(Config::$modSettings['modlog_enabled']) && in_array($_POST['todo'], ['ok', 'okemail', 'require_activation', 'remind'])) { + if (!empty(Config::$modSettings['modlog_enabled']) && \in_array($_POST['todo'], ['ok', 'okemail', 'require_activation', 'remind'])) { $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member'; foreach ($member_info as $member) { @@ -1237,7 +1237,7 @@ public function approve(): void } // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers). - if (in_array($current_filter, [3, 4, 5])) { + if (\in_array($current_filter, [3, 4, 5])) { Config::updateModSettings(['unapprovedMembers' => (Config::$modSettings['unapprovedMembers'] > $member_count ? Config::$modSettings['unapprovedMembers'] - $member_count : 0)]); } @@ -1245,7 +1245,7 @@ public function approve(): void Logging::updateStats('member', false); // If they haven't been deleted, update the post group statistics on them... - if (!in_array($_POST['todo'], ['delete', 'deleteemail', 'reject', 'rejectemail', 'remind'])) { + if (!\in_array($_POST['todo'], ['delete', 'deleteemail', 'reject', 'rejectemail', 'remind'])) { Logging::updateStats('postgroups', $members); } @@ -1417,7 +1417,7 @@ protected function __construct() Utils::$context['tabs'][$this->subaction]['is_selected'] = true; } elseif (isset($this->subaction)) { foreach (Utils::$context['tabs'] as $id_tab => $tab_data) { - if (!empty($tab_data['selected_actions']) && in_array($this->subaction, $tab_data['selected_actions'])) { + if (!empty($tab_data['selected_actions']) && \in_array($this->subaction, $tab_data['selected_actions'])) { Utils::$context['tabs'][$id_tab]['is_selected'] = true; } } @@ -1523,11 +1523,11 @@ protected static function populateDuplicateMembers(array &$members): void 'ip2' => $row['member_ip2'], ]; - if (in_array($row['member_ip'], $ips)) { + if (\in_array($row['member_ip'], $ips)) { $duplicate_members[$row['member_ip']][] = $member_context; } - if ($row['member_ip'] != $row['member_ip2'] && in_array($row['member_ip2'], $ips)) { + if ($row['member_ip'] != $row['member_ip2'] && \in_array($row['member_ip2'], $ips)) { $duplicate_members[$row['member_ip2']][] = $member_context; } } @@ -1555,7 +1555,7 @@ protected static function populateDuplicateMembers(array &$members): void $row['poster_ip'] = new IP($row['poster_ip']); // Don't collect lots of the same. - if (isset($had_ips[$row['poster_ip']]) && in_array($row['id_member'], $had_ips[$row['poster_ip']])) { + if (isset($had_ips[$row['poster_ip']]) && \in_array($row['id_member'], $had_ips[$row['poster_ip']])) { continue; } @@ -1587,7 +1587,7 @@ protected static function populateDuplicateMembers(array &$members): void $member_track = [$member['id_member']]; foreach ($members[$key]['duplicate_members'] as $duplicate_id_member => $duplicate_member) { - if (in_array($duplicate_member['id'], $member_track)) { + if (\in_array($duplicate_member['id'], $member_track)) { unset($members[$key]['duplicate_members'][$duplicate_id_member]); continue; diff --git a/Sources/Actions/Admin/Mods.php b/Sources/Actions/Admin/Mods.php index e2359fa147..824665e0ba 100644 --- a/Sources/Actions/Admin/Mods.php +++ b/Sources/Actions/Admin/Mods.php @@ -77,7 +77,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } diff --git a/Sources/Actions/Admin/News.php b/Sources/Actions/Admin/News.php index 8d9f454534..2d518a3fb4 100644 --- a/Sources/Actions/Admin/News.php +++ b/Sources/Actions/Admin/News.php @@ -238,7 +238,7 @@ public function execute(): void // Have you got the proper permissions? User::$me->isAllowedTo(self::$subactions[$this->subaction][1]); - call_user_func([$this, self::$subactions[$this->subaction][0]]); + \call_user_func([$this, self::$subactions[$this->subaction][0]]); } /** @@ -262,7 +262,7 @@ public function edit(): void // Remove the items that were selected. foreach ($temp_news as $i => $news) { - if (in_array($i, $_POST['remove'])) { + if (\in_array($i, $_POST['remove'])) { unset($temp_news[$i]); } } @@ -433,7 +433,7 @@ public function compose(): void $_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type])))); foreach ($_POST[$type] as $index => $member) { - if (strlen(trim($member)) > 0) { + if (\strlen(trim($member)) > 0) { $_POST[$type][$index] = Utils::htmlspecialchars(Utils::strtolower(trim($member))); } else { unset($_POST[$type][$index]); @@ -445,7 +445,7 @@ public function compose(): void } } - if (isset($_POST['member_list']) && is_array($_POST['member_list'])) { + if (isset($_POST['member_list']) && \is_array($_POST['member_list'])) { $members = []; foreach ($_POST['member_list'] as $member_id) { @@ -455,7 +455,7 @@ public function compose(): void $_POST['members'] = implode(',', $members); } - if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list'])) { + if (isset($_POST['exclude_member_list']) && \is_array($_POST['exclude_member_list'])) { $members = []; foreach ($_POST['exclude_member_list'] as $member_id) { @@ -537,11 +537,11 @@ public function compose(): void if ( ( !empty(Utils::$context['recipients']['groups']) - && in_array(3, Utils::$context['recipients']['groups']) + && \in_array(3, Utils::$context['recipients']['groups']) ) || ( !empty(Utils::$context['recipients']['exclude_groups']) - && in_array(3, Utils::$context['recipients']['exclude_groups']) + && \in_array(3, Utils::$context['recipients']['exclude_groups']) ) ) { $request = Db::$db->query( @@ -556,7 +556,7 @@ public function compose(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (in_array(3, Utils::$context['recipients'])) { + if (\in_array(3, Utils::$context['recipients'])) { Utils::$context['recipients']['exclude_members'][] = $row['identifier']; } else { Utils::$context['recipients']['members'][] = $row['identifier']; @@ -566,7 +566,7 @@ public function compose(): void } // For progress bar! - Utils::$context['total_emails'] = count(Utils::$context['recipients']['emails']); + Utils::$context['total_emails'] = \count(Utils::$context['recipients']['emails']); $request = Db::$db->query( '', @@ -671,7 +671,7 @@ public function send(bool $clean_only = false): void // Cleaning groups is simple - although deal with both checkbox and commas. if (isset($_POST['groups'])) { - if (is_array($_POST['groups'])) { + if (\is_array($_POST['groups'])) { foreach ($_POST['groups'] as $group => $dummy) { Utils::$context['recipients']['groups'][] = (int) $group; } @@ -686,7 +686,7 @@ public function send(bool $clean_only = false): void // Same for excluded groups if (isset($_POST['exclude_groups'])) { - if (is_array($_POST['exclude_groups'])) { + if (\is_array($_POST['exclude_groups'])) { foreach ($_POST['exclude_groups'] as $group => $dummy) { Utils::$context['recipients']['exclude_groups'][] = (int) $group; } @@ -890,7 +890,7 @@ public function send(bool $clean_only = false): void } // Anything to exclude? - if (!empty(Utils::$context['recipients']['exclude_groups']) && in_array(0, Utils::$context['recipients']['exclude_groups'])) { + if (!empty(Utils::$context['recipients']['exclude_groups']) && \in_array(0, Utils::$context['recipients']['exclude_groups'])) { $sendQuery .= ' AND mem.id_group != {int:regular_group}'; } @@ -1014,7 +1014,7 @@ public function send(bool $clean_only = false): void } // Working out progress is a black art of sorts. - $percentEmails = Utils::$context['total_emails'] == 0 ? 0 : ((count(Utils::$context['recipients']['emails']) / Utils::$context['total_emails']) * (Utils::$context['total_emails'] / (Utils::$context['total_emails'] + Utils::$context['total_members']))); + $percentEmails = Utils::$context['total_emails'] == 0 ? 0 : ((\count(Utils::$context['recipients']['emails']) / Utils::$context['total_emails']) * (Utils::$context['total_emails'] / (Utils::$context['total_emails'] + Utils::$context['total_members']))); $percentMembers = (Utils::$context['start'] / Utils::$context['total_members']) * (Utils::$context['total_members'] / (Utils::$context['total_emails'] + Utils::$context['total_members'])); diff --git a/Sources/Actions/Admin/Permissions.php b/Sources/Actions/Admin/Permissions.php index 7a7be76d17..4b169d6d8b 100644 --- a/Sources/Actions/Admin/Permissions.php +++ b/Sources/Actions/Admin/Permissions.php @@ -942,7 +942,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -972,7 +972,7 @@ public function index(): void $this->setGroupsContext(); // We can modify any permission set, except for the ones we can't. - Utils::$context['can_modify'] = empty($_REQUEST['pid']) || !in_array((int) $_REQUEST['pid'], self::PROFILE_UNMODIFIABLE); + Utils::$context['can_modify'] = empty($_REQUEST['pid']) || !\in_array((int) $_REQUEST['pid'], self::PROFILE_UNMODIFIABLE); // Load the proper template. Utils::$context['sub_template'] = 'permission_index'; @@ -1082,7 +1082,7 @@ public function quick(): void $_REQUEST['pid'] = (int) ($_REQUEST['pid'] ?? 0); // Sorry, but that one can't be modified. - if (in_array($_REQUEST['pid'], self::PROFILE_UNMODIFIABLE)) { + if (\in_array($_REQUEST['pid'], self::PROFILE_UNMODIFIABLE)) { ErrorHandler::fatalLang('no_access', false); } @@ -1154,7 +1154,7 @@ public function modify2(): void } // No, you can't modify this permission profile. - if (in_array($_GET['pid'], self::PROFILE_UNMODIFIABLE)) { + if (\in_array($_GET['pid'], self::PROFILE_UNMODIFIABLE)) { ErrorHandler::fatalLang('no_access', false); } @@ -1174,9 +1174,9 @@ public function modify2(): void ]; // Prepare all permissions that were set or denied for addition to the DB. - if (isset($_POST['perm']) && is_array($_POST['perm'])) { + if (isset($_POST['perm']) && \is_array($_POST['perm'])) { foreach ($_POST['perm'] as $scope => $perm_array) { - if (!is_array($perm_array)) { + if (!\is_array($perm_array)) { continue; } @@ -1186,7 +1186,7 @@ public function modify2(): void } // Don't allow people to escalate themselves! - if (in_array($permission, $illegal_permissions)) { + if (\in_array($permission, $illegal_permissions)) { continue; } @@ -1214,7 +1214,7 @@ public function modify2(): void self::removeIllegalBBCHtmlPermission(); // Ensure Config::$modSettings['board_manager_groups'] is up to date. - if (!in_array('manage_boards', $illegal_permissions)) { + if (!\in_array('manage_boards', $illegal_permissions)) { self::updateBoardManagers(); } @@ -1375,14 +1375,14 @@ public function profiles(): void foreach (Utils::$context['profiles'] as $id => $profile) { // Can't rename the special ones. - Utils::$context['profiles'][$id]['can_rename'] = !in_array($id, self::PROFILE_PREDEFINED); + Utils::$context['profiles'][$id]['can_rename'] = !\in_array($id, self::PROFILE_PREDEFINED); if (Utils::$context['profiles'][$id]['can_rename']) { Utils::$context['can_rename_something'] = true; } // You can only delete it if you can rename it AND it's not in use. - Utils::$context['profiles'][$id]['can_delete'] = !in_array($id, self::PROFILE_PREDEFINED) && empty($profile['in_use']); + Utils::$context['profiles'][$id]['can_delete'] = !\in_array($id, self::PROFILE_PREDEFINED) && empty($profile['in_use']); } SecurityToken::create('admin-mpp'); @@ -1462,7 +1462,7 @@ public function postmod(): void } // If we're saving the changes then do just that - save them. - if (!empty($_POST['save_changes']) && !in_array(Utils::$context['current_profile'], self::PROFILE_UNMODIFIABLE)) { + if (!empty($_POST['save_changes']) && !\in_array(Utils::$context['current_profile'], self::PROFILE_UNMODIFIABLE)) { SecurityToken::validate('admin-mppm'); // First, are we saving a new value for enabled post moderation? @@ -1613,7 +1613,7 @@ public static function getPermissions(): array IntegrationHook::call('integrate_permissions_list', [&self::$permissions]); // In case a mod screwed things up... - if (!in_array('html', Utils::$context['restricted_bbc'])) { + if (!\in_array('html', Utils::$context['restricted_bbc'])) { Utils::$context['restricted_bbc'][] = 'html'; } @@ -1777,11 +1777,11 @@ public static function setPermissionLevel(string $level, int $group, string|int // Make sure we're not granting someone too many permissions! foreach (['global', 'board'] as $scope) { foreach ($group_levels[$scope][$level] as $k => $permission) { - if (in_array($permission, self::$illegal ?? [])) { + if (\in_array($permission, self::$illegal ?? [])) { unset($group_levels[$scope][$level][$k]); } - if (in_array($group, self::$excluded[$permission] ?? [])) { + if (\in_array($group, self::$excluded[$permission] ?? [])) { unset($group_levels[$scope][$level][$k]); } } @@ -1850,7 +1850,7 @@ public static function setPermissionLevel(string $level, int $group, string|int self::removeIllegalBBCHtmlPermission(); } // Setting profile permissions for a specific group. - elseif ($profile !== 'null' && $group !== 'null' && !in_array($profile, self::PROFILE_UNMODIFIABLE)) { + elseif ($profile !== 'null' && $group !== 'null' && !\in_array($profile, self::PROFILE_UNMODIFIABLE)) { $group = (int) $group; $profile = (int) $profile; @@ -1884,7 +1884,7 @@ public static function setPermissionLevel(string $level, int $group, string|int } } // Setting profile permissions for all groups. - elseif ($profile !== 'null' && $group === 'null' && !in_array($profile, self::PROFILE_UNMODIFIABLE)) { + elseif ($profile !== 'null' && $group === 'null' && !\in_array($profile, self::PROFILE_UNMODIFIABLE)) { $profile = (int) $profile; Db::$db->query( @@ -1953,7 +1953,7 @@ public static function setPermissionLevel(string $level, int $group, string|int } // Make sure Config::$modSettings['board_manager_groups'] is up to date. - if (!in_array('manage_boards', self::$illegal)) { + if (!\in_array('manage_boards', self::$illegal)) { self::updateBoardManagers(); } } @@ -2027,7 +2027,7 @@ public static function init_inline_permissions(array $permissions, array $exclud self::loadIllegalGuestPermissions(); // Only special people can have this permission - if (in_array('bbc_html', $permissions)) { + if (\in_array('bbc_html', $permissions)) { self::loadIllegalBBCHtmlGroups(); } @@ -2035,7 +2035,7 @@ public static function init_inline_permissions(array $permissions, array $exclud $non_guest_perms = array_intersect(str_replace(['_any', '_own'], '', $permissions), self::$never_guests); foreach ($non_guest_perms as $permission) { - if (!isset(self::$excluded[$permission]) || !in_array(-1, self::$excluded[$permission])) { + if (!isset(self::$excluded[$permission]) || !\in_array(-1, self::$excluded[$permission])) { self::$excluded[$permission][] = -1; } } @@ -2046,7 +2046,7 @@ public static function init_inline_permissions(array $permissions, array $exclud $excluded_groups = array_filter( (array) $excluded_groups, function ($v) { - return is_int($v) || is_string($v) && (string) intval($v) === $v; + return \is_int($v) || \is_string($v) && (string) \intval($v) === $v; }, ); @@ -2111,7 +2111,7 @@ public static function save_inline_permissions(array $permissions): void // Check they can't do certain things. self::loadIllegalPermissions(); - if (in_array('bbc_html', $permissions)) { + if (\in_array('bbc_html', $permissions)) { self::loadIllegalBBCHtmlGroups(); } @@ -2123,11 +2123,11 @@ public static function save_inline_permissions(array $permissions): void } foreach ($_POST[$permission] as $id_group => $value) { - if ($value == 'on' && !empty(Utils::$context['excluded_permissions'][$permission]) && in_array($id_group, Utils::$context['excluded_permissions'][$permission])) { + if ($value == 'on' && !empty(Utils::$context['excluded_permissions'][$permission]) && \in_array($id_group, Utils::$context['excluded_permissions'][$permission])) { continue; } - if (in_array($value, ['on', 'deny']) && (empty(self::$illegal) || !in_array($permission, self::$illegal))) { + if (\in_array($value, ['on', 'deny']) && (empty(self::$illegal) || !\in_array($permission, self::$illegal))) { $insert_rows[] = [(int) $id_group, $permission, $value == 'on' ? 1 : 0]; } } @@ -2160,7 +2160,7 @@ public static function save_inline_permissions(array $permissions): void self::updateChildPermissions([], -1); // Make sure Config::$modSettings['board_manager_groups'] is up to date. - if (!in_array('manage_boards', self::$illegal)) { + if (!\in_array('manage_boards', self::$illegal)) { self::updateBoardManagers(); } @@ -2189,7 +2189,7 @@ public static function loadPermissionProfiles(): void Utils::$context['profiles'][$row['id_profile']] = [ 'id' => $row['id_profile'], 'name' => Lang::$txt['permissions_profile_' . $row['profile_name']] ?? $row['profile_name'], - 'can_modify' => !in_array($row['id_profile'], self::PROFILE_UNMODIFIABLE), + 'can_modify' => !\in_array($row['id_profile'], self::PROFILE_UNMODIFIABLE), 'unformatted_name' => $row['profile_name'], ]; } @@ -2465,7 +2465,7 @@ protected function setGroupsContext(): void protected function quickSetPredefined(): void { // Make sure it's a predefined permission set we expect. - if (!in_array($_POST['predefined'], ['restrict', 'standard', 'moderator', 'maintenance'])) { + if (!\in_array($_POST['predefined'], ['restrict', 'standard', 'moderator', 'maintenance'])) { Utils::redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); } @@ -2523,11 +2523,11 @@ protected function quickCopyFrom(): void foreach ($_POST['group'] as $group_id) { foreach ($target_perm as $perm => $add_deny) { // No dodgy permissions please! - if (in_array($perm, self::$illegal)) { + if (\in_array($perm, self::$illegal)) { continue; } - if (in_array($group_id, self::$excluded[$perm] ?? [])) { + if (\in_array($group_id, self::$excluded[$perm] ?? [])) { continue; } @@ -2587,7 +2587,7 @@ protected function quickCopyFrom(): void foreach ($_POST['group'] as $group_id) { foreach ($target_perm as $perm => $add_deny) { // Are these for guests? - if ($group_id == -1 && in_array($perm, self::$never_guests)) { + if ($group_id == -1 && \in_array($perm, self::$never_guests)) { continue; } @@ -2636,7 +2636,7 @@ protected function quickSetPermission(): void list($scope, $permission) = explode('/', $_POST['permissions']); // Check whether our input is within expected range. - if (!in_array($_POST['add_remove'], ['add', 'clear', 'deny']) || !in_array($scope, ['global', 'board'])) { + if (!\in_array($_POST['add_remove'], ['add', 'clear', 'deny']) || !\in_array($scope, ['global', 'board'])) { Utils::redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); } @@ -2682,11 +2682,11 @@ protected function quickSetPermission(): void $perm_change = []; foreach ($_POST['group'] as $groupID) { - if (isset(self::$excluded[$permission]) && in_array($groupID, self::$excluded[$permission])) { + if (isset(self::$excluded[$permission]) && \in_array($groupID, self::$excluded[$permission])) { continue; } - if ($scope == 'global' && $groupID != 1 && $groupID != 3 && !in_array($permission, self::$illegal)) { + if ($scope == 'global' && $groupID != 1 && $groupID != 3 && !\in_array($permission, self::$illegal)) { $perm_change[] = [$permission, $groupID, $add_deny]; } elseif ($scope != 'global') { $perm_change[] = [$permission, $groupID, $pid, $add_deny]; @@ -2880,11 +2880,11 @@ protected function setOnOff(): void $cur_perm = &Utils::$context['permissions'][$scope]['columns'][$position][$group_name]['permissions'][$perm['id']]; if ($perm['has_own_any']) { - $cur_perm['any']['select'] = in_array($perm['id'] . '_any', $this->allowed_denied[$scope]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $this->allowed_denied[$scope]['denied']) ? 'deny' : 'off'); + $cur_perm['any']['select'] = \in_array($perm['id'] . '_any', $this->allowed_denied[$scope]['allowed']) ? 'on' : (\in_array($perm['id'] . '_any', $this->allowed_denied[$scope]['denied']) ? 'deny' : 'off'); - $cur_perm['own']['select'] = in_array($perm['id'] . '_own', $this->allowed_denied[$scope]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $this->allowed_denied[$scope]['denied']) ? 'deny' : 'off'); + $cur_perm['own']['select'] = \in_array($perm['id'] . '_own', $this->allowed_denied[$scope]['allowed']) ? 'on' : (\in_array($perm['id'] . '_own', $this->allowed_denied[$scope]['denied']) ? 'deny' : 'off'); } else { - $cur_perm['select'] = in_array($perm['id'], $this->allowed_denied[$scope]['denied']) ? 'deny' : (in_array($perm['id'], $this->allowed_denied[$scope]['allowed']) ? 'on' : 'off'); + $cur_perm['select'] = \in_array($perm['id'], $this->allowed_denied[$scope]['denied']) ? 'deny' : (\in_array($perm['id'], $this->allowed_denied[$scope]['allowed']) ? 'on' : 'off'); } // Keep the last value if it's hidden. @@ -2975,7 +2975,7 @@ protected function updateGlobalPermissions(int $group, array $give_perms, array // This should already have been done, but just in case... foreach ($give_perms['global'] as $k => $v) { - if (in_array($v[1], $illegal_permissions)) { + if (\in_array($v[1], $illegal_permissions)) { unset($give_perms['global'][$k]); } } @@ -3019,7 +3019,7 @@ protected function updateBoardPermissions(int $group, array $give_perms, array $ // This should already have been done, but just in case... foreach ($give_perms['board'] as $k => $v) { - if (in_array($v[1], $illegal_permissions)) { + if (\in_array($v[1], $illegal_permissions)) { unset($give_perms['board'][$k]); } } @@ -3125,7 +3125,7 @@ protected function renameProfile(): void $value = Utils::htmlspecialchars($value); - if (trim($value) != '' && !in_array($id, self::PROFILE_PREDEFINED)) { + if (trim($value) != '' && !\in_array($id, self::PROFILE_PREDEFINED)) { Db::$db->query( '', 'UPDATE {db_prefix}permission_profiles @@ -3158,7 +3158,7 @@ protected function deleteProfile(): void $profiles = []; foreach (array_map('intval', $_POST['delete_profile']) as $profile) { - if ($profile > 0 && !in_array($profile, self::PROFILE_PREDEFINED)) { + if ($profile > 0 && !\in_array($profile, self::PROFILE_PREDEFINED)) { $profiles[] = $profile; } } @@ -3226,7 +3226,7 @@ protected static function loadAllPermissions(): void } foreach ($groups as $group) { - $position = (int) (!in_array($group, self::$left_permission_groups)); + $position = (int) (!\in_array($group, self::$left_permission_groups)); Utils::$context['permissions'][$scope]['columns'][$position][$group] = [ 'type' => $scope, @@ -3243,13 +3243,13 @@ protected static function loadAllPermissions(): void foreach (self::getPermissions() as $permission => $perm_info) { // If this permission shouldn't be given to certain groups (e.g. guests), don't. foreach ([$permission, $perm_info['generic_name']] as $perm) { - if (isset(Utils::$context['group']['id']) && in_array(Utils::$context['group']['id'], self::$excluded[$perm] ?? [])) { + if (isset(Utils::$context['group']['id']) && \in_array(Utils::$context['group']['id'], self::$excluded[$perm] ?? [])) { continue 2; } } // What column should this be located in? - $position = (int) (!in_array($perm_info['view_group'], self::$left_permission_groups)); + $position = (int) (!\in_array($perm_info['view_group'], self::$left_permission_groups)); // For legibility reasons... $view_group_perms = &Utils::$context['permissions'][$perm_info['scope']]['columns'][$position][$perm_info['view_group']]['permissions']; @@ -3326,7 +3326,7 @@ protected static function loadIllegalGuestPermissions(): array // Also add this info to self::$excluded to make life easier for everyone foreach (self::$never_guests as $permission) { - if (empty(self::$excluded[$permission]) || !in_array($permission, self::$excluded[$permission])) { + if (empty(self::$excluded[$permission]) || !\in_array($permission, self::$excluded[$permission])) { self::$excluded[$permission][] = -1; } } @@ -3468,9 +3468,9 @@ protected static function integrateLoadPermissions(): void 'own_any' => $perm_info[0] ? substr($id, -3) : null, 'view_group' => $perm_info[1], 'scope' => $scope === 'board' ? 'board' : 'global', - 'hidden' => in_array($permission, $hidden_permissions), + 'hidden' => \in_array($permission, $hidden_permissions), 'label' => 'permissionname_' . $permission, - 'never_guests' => in_array($permission, self::$never_guests), + 'never_guests' => \in_array($permission, self::$never_guests), ]; } } @@ -3570,7 +3570,7 @@ protected static function integrateLoadIllegalGuestPermissions(): void // Did the hook remove a permission from self::$never_guests? foreach (self::$permissions as $permission => $perm_info) { - if (!in_array($perm_info['generic_name'], self::$never_guests)) { + if (!\in_array($perm_info['generic_name'], self::$never_guests)) { self::$permissions[$permission]['never_guests'] = false; } } diff --git a/Sources/Actions/Admin/Posts.php b/Sources/Actions/Admin/Posts.php index 09b1089ec6..7120d9e21d 100644 --- a/Sources/Actions/Admin/Posts.php +++ b/Sources/Actions/Admin/Posts.php @@ -76,7 +76,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -107,7 +107,7 @@ public function censor(): void list($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, ''); } } elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper'])) { - if (is_array($_POST['censor_vulgar'])) { + if (\is_array($_POST['censor_vulgar'])) { foreach ($_POST['censor_vulgar'] as $i => $value) { if (trim(strtr($value, '*', ' ')) == '') { unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]); @@ -150,7 +150,7 @@ public function censor(): void Utils::$context['censored_words'] = []; - for ($i = 0, $n = count($censor_vulgar); $i < $n; $i++) { + for ($i = 0, $n = \count($censor_vulgar); $i < $n; $i++) { if (empty($censor_vulgar[$i])) { continue; } diff --git a/Sources/Actions/Admin/Registration.php b/Sources/Actions/Admin/Registration.php index d57ded3e64..2f8389a39c 100644 --- a/Sources/Actions/Admin/Registration.php +++ b/Sources/Actions/Admin/Registration.php @@ -88,7 +88,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -110,7 +110,7 @@ public function register(): void SecurityToken::validate('admin-regc'); foreach ($_POST as $key => $value) { - if (!is_array($_POST[$key])) { + if (!\is_array($_POST[$key])) { $_POST[$key] = Utils::htmlTrimRecursive(str_replace(["\n", "\r"], '', Utils::normalize($_POST[$key]))); } } @@ -239,7 +239,7 @@ public function agreement(): void User::$me->checkSession(); SecurityToken::validate('admin-rega'); - $backup_file = dirname($agreement_file) . '/' . (date_create('@' . filemtime($agreement_file))->format('Y-m-d\\TH_i_sp')) . '_' . basename($agreement_file); + $backup_file = \dirname($agreement_file) . '/' . (date_create('@' . filemtime($agreement_file))->format('Y-m-d\\TH_i_sp')) . '_' . basename($agreement_file); // Off it goes to the agreement file. if (Config::safeFileWrite($agreement_file, $_POST['agreement'], $backup_file)) { @@ -272,7 +272,7 @@ public function agreement(): void Utils::$context['agreement'] = Utils::htmlspecialchars(Utils::$context['agreement']); - Utils::$context['warning'] = is_writable($agreement_file) && is_writable(dirname($agreement_file)) ? '' : Lang::$txt['agreement_not_writable']; + Utils::$context['warning'] = is_writable($agreement_file) && is_writable(\dirname($agreement_file)) ? '' : Lang::$txt['agreement_not_writable']; Utils::$context['sub_template'] = 'edit_agreement'; Utils::$context['page_title'] = Lang::$txt['registration_agreement']; diff --git a/Sources/Actions/Admin/RepairBoards.php b/Sources/Actions/Admin/RepairBoards.php index 725defe2b3..96b378b25c 100644 --- a/Sources/Actions/Admin/RepairBoards.php +++ b/Sources/Actions/Admin/RepairBoards.php @@ -901,7 +901,7 @@ protected function findForumErrors(bool $do_fix = false): array Utils::$context['db_cache'] = Db::$cache; Db::$cache = []; - Utils::$context['total_steps'] = count($this->errorTests); + Utils::$context['total_steps'] = \count($this->errorTests); // For all the defined error types do the necessary tests. $current_step = -1; @@ -916,7 +916,7 @@ protected function findForumErrors(bool $do_fix = false): array } // If we're fixing it but it ain't broke why try? - if ($do_fix && !in_array($error_type, $to_fix)) { + if ($do_fix && !\in_array($error_type, $to_fix)) { $_GET['step']++; continue; @@ -1001,7 +1001,7 @@ protected function findForumErrors(bool $do_fix = false): array $func = method_exists($this, $test['message_function']) ? [$this, $test['message_function']] : Utils::getCallable($test['message_function']); while ($row = Db::$db->fetch_assoc($request)) { - $found_errors |= call_user_func($func, $row); + $found_errors |= \call_user_func($func, $row); } } @@ -1024,7 +1024,7 @@ protected function findForumErrors(bool $do_fix = false): array $func = method_exists($this, $test['fix_collect']['process']) ? [$this, $test['fix_collect']['process']] : Utils::getCallable($test['fix_collect']['process']); // Fix it! - call_user_func($func, $ids); + \call_user_func($func, $ids); } } // Simply executing a fix it query? @@ -1041,20 +1041,20 @@ protected function findForumErrors(bool $do_fix = false): array $func = method_exists($this, $test['fix_processing']) ? [$this, $test['fix_processing']] : Utils::getCallable($test['fix_processing']); while ($row = Db::$db->fetch_assoc($request)) { - call_user_func($func, $row); + \call_user_func($func, $row); } } // What about the full set of processing? elseif (isset($test['fix_full_processing'])) { $func = method_exists($this, $test['fix_full_processing']) ? [$this, $test['fix_full_processing']] : Utils::getCallable($test['fix_full_processing']); - call_user_func($func, $request); + \call_user_func($func, $request); } // Do we have other things we need to fix as a result? if (!empty($test['force_fix'])) { foreach ($test['force_fix'] as $item) { - if (!in_array($item, $to_fix)) { + if (!\in_array($item, $to_fix)) { $to_fix[] = $item; } } @@ -1139,7 +1139,7 @@ protected function pauseRepairProcess(array $to_fix, string $current_step_descri $return = false; } // Try to stay under our memory limit. - elseif ((memory_get_usage() + 65536) > Sapi::memoryReturnBytes(ini_get('memory_limit'))) { + elseif ((memory_get_usage() + 65536) > Sapi::memoryReturnBytes(\ini_get('memory_limit'))) { $return = false; } // Errr, wait. How much time has this taken already? @@ -1147,7 +1147,7 @@ protected function pauseRepairProcess(array $to_fix, string $current_step_descri $return = false; } // If we have a lot of errors, lets do smaller batches, to save on memory needs. - elseif (count(Utils::$context['repair_errors']) > 100000 && $this->loops > 50) { + elseif (\count(Utils::$context['repair_errors']) > 100000 && $this->loops > 50) { $return = false; } @@ -2061,7 +2061,7 @@ protected function fixMissingCachedSubject(mixed $result): void $inserts[] = [$word, $row['id_topic']]; } - if (count($inserts) > 500) { + if (\count($inserts) > 500) { Db::$db->insert( 'ignore', '{db_prefix}log_search_subjects', @@ -2093,7 +2093,7 @@ protected function fixMissingCachedSubject(mixed $result): void */ protected function missingCachedSubjectMessage(array $row): bool { - if (count(Utils::extractWords($row['subject'], 2)) != 0) { + if (\count(Utils::extractWords($row['subject'], 2)) != 0) { Utils::$context['repair_errors'][] = Lang::getTxt('repair_missing_cached_subject', [$row['id_topic']]); return true; diff --git a/Sources/Actions/Admin/Reports.php b/Sources/Actions/Admin/Reports.php index 17280aef11..76791956d3 100644 --- a/Sources/Actions/Admin/Reports.php +++ b/Sources/Actions/Admin/Reports.php @@ -181,7 +181,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } // Finish the tables before exiting - this is to help the templates a little more. @@ -320,7 +320,7 @@ public function boardAccess(): void $inc = []; if (isset($_REQUEST['groups'])) { - if (!is_array($_REQUEST['groups'])) { + if (!\is_array($_REQUEST['groups'])) { $inc = explode(',', $_REQUEST['groups']); } @@ -341,15 +341,15 @@ public function boardAccess(): void Board::getModeratorGroups($loaded_ids); foreach ($group_data as $group) { - if ($group->parent === Group::NONE && ($inc == [] || in_array($group->id, $inc))) { + if ($group->parent === Group::NONE && ($inc == [] || \in_array($group->id, $inc))) { $groups[$group->id] = $group->name; foreach (Board::$loaded as $board) { if (!isset($data[$board->id])) { $data[$board->id] = ['col' => $board->name]; - } elseif (in_array($group->id, $board->member_groups)) { + } elseif (\in_array($group->id, $board->member_groups)) { $data[$board->id][$group->id] = '✅'; - } elseif (in_array($group->id, $board->deny_groups)) { + } elseif (\in_array($group->id, $board->deny_groups)) { $data[$board->id][$group->id] = '🚫'; } } @@ -377,7 +377,7 @@ public function boardPerms(): void $inc = []; if (isset($_REQUEST['groups'])) { - if (!is_array($_REQUEST['groups'])) { + if (!\is_array($_REQUEST['groups'])) { $inc = explode(',', $_REQUEST['groups']); } @@ -409,12 +409,12 @@ public function boardPerms(): void $data = []; foreach ($group_data as $group) { - if ($group->parent === Group::NONE && ($inc == [] || in_array($group->id, $inc))) { + if ($group->parent === Group::NONE && ($inc == [] || \in_array($group->id, $inc))) { $groups[$group->id] = $group->name; foreach ($group->permissions['board_profiles'] as $id_profile => $board_profile) { foreach ($board_profile as $permission => $add_deny) { - if (in_array($permission, $disabled_permissions)) { + if (\in_array($permission, $disabled_permissions)) { continue; } @@ -479,7 +479,7 @@ public function groupPerms(): void $inc = []; if (isset($_REQUEST['groups'])) { - if (!is_array($_REQUEST['groups'])) { + if (!\is_array($_REQUEST['groups'])) { $inc = explode(',', $_REQUEST['groups']); } @@ -513,11 +513,11 @@ public function groupPerms(): void IntegrationHook::call('integrate_reports_groupperm', [&$disabled_permissions]); foreach ($group_data as $group) { - if ($group->parent === Group::NONE && ($inc == [] || in_array($group->id, $inc))) { + if ($group->parent === Group::NONE && ($inc == [] || \in_array($group->id, $inc))) { $groups[$group->id] = $group->name; foreach ($group->permissions['general'] as $permission => $add_deny) { - if (in_array($permission, $disabled_permissions)) { + if (\in_array($permission, $disabled_permissions)) { continue; } @@ -559,7 +559,7 @@ public function staff(): void $allStaff = array_unique($allStaff); // This is a bit of a cop out - but we're protecting their forum, really! - if (count($allStaff) > 300) { + if (\count($allStaff) > 300) { ErrorHandler::fatalLang('report_error_too_many_staff'); } @@ -666,7 +666,7 @@ protected function __construct() $is_first = 0; foreach (self::$subactions as $k => $func) { - if (!is_string($func)) { + if (!\is_string($func)) { continue; } @@ -858,7 +858,7 @@ protected function finishTables(): void // Loop through each table counting up some basic values, to help with the templating. foreach ($this->tables as $id => $table) { $this->tables[$id]['id'] = $id; - $this->tables[$id]['row_count'] = count($table['data']); + $this->tables[$id]['row_count'] = \count($table['data']); $this->tables[$id]['column_count'] = array_reduce( $table['data'], diff --git a/Sources/Actions/Admin/Search.php b/Sources/Actions/Admin/Search.php index 4776cbfece..822f65212d 100644 --- a/Sources/Actions/Admin/Search.php +++ b/Sources/Actions/Admin/Search.php @@ -77,7 +77,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -340,8 +340,8 @@ public static function getConfigVars(): array // Perhaps the search method wants to add some settings? $searchAPI = SearchApi::load(); - if (is_callable([$searchAPI, 'searchSettings'])) { - call_user_func_array([$searchAPI, 'searchSettings'], [&$config_vars]); + if (\is_callable([$searchAPI, 'searchSettings'])) { + \call_user_func_array([$searchAPI, 'searchSettings'], [&$config_vars]); } // Let the admin set custom stopwords. diff --git a/Sources/Actions/Admin/SearchEngines.php b/Sources/Actions/Admin/SearchEngines.php index bfc9d00da5..daa7135c0c 100644 --- a/Sources/Actions/Admin/SearchEngines.php +++ b/Sources/Actions/Admin/SearchEngines.php @@ -94,7 +94,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -398,7 +398,7 @@ public function logs(): void $urls = Who::determineActions($urls, 'whospider_'); foreach ($urls as $k => $new_url) { - if (is_array($new_url)) { + if (\is_array($new_url)) { Utils::$context['spider_logs']['rows'][$k]['data']['viewing']['value'] = Lang::$txt[$new_url['label']]; Utils::$context['spider_logs']['rows'][$k]['data']['viewing']['class'] = $new_url['class']; @@ -432,7 +432,7 @@ public function view(): void } // User pressed the 'remove selection button'. - if (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove'])) { + if (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && \is_array($_POST['remove'])) { User::$me->checkSession(); SecurityToken::validate('admin-ser'); diff --git a/Sources/Actions/Admin/Server.php b/Sources/Actions/Admin/Server.php index 4fffa581c7..1087e9147e 100644 --- a/Sources/Actions/Admin/Server.php +++ b/Sources/Actions/Admin/Server.php @@ -209,7 +209,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -241,7 +241,7 @@ public function general(): void IntegrationHook::call('integrate_save_general_settings'); foreach ($config_vars as $config_var) { - if (is_array($config_var) && isset($config_var[3]) && $config_var[3] == 'text' && !empty($_POST[$config_var[0]])) { + if (\is_array($config_var) && isset($config_var[3]) && $config_var[3] == 'text' && !empty($_POST[$config_var[0]])) { $_POST[$config_var[0]] = Utils::normalize($_POST[$config_var[0]]); } } @@ -491,7 +491,7 @@ public function cache(): void IntegrationHook::call('integrate_save_cache_settings'); - if (is_callable([CacheApi::$loadedApi, 'cleanCache']) && ((int) $_POST['cache_enable'] < CacheApi::$enable || $_POST['cache_accelerator'] != CacheApi::$accelerator)) { + if (\is_callable([CacheApi::$loadedApi, 'cleanCache']) && ((int) $_POST['cache_enable'] < CacheApi::$enable || $_POST['cache_accelerator'] != CacheApi::$accelerator)) { CacheApi::clean(); } @@ -559,7 +559,7 @@ public function export(): void $export_files = glob($prev_export_dir . DIRECTORY_SEPARATOR . '*'); foreach ($export_files as $export_file) { - if (!in_array(basename($export_file), ['index.php', '.htaccess'])) { + if (!\in_array(basename($export_file), ['index.php', '.htaccess'])) { rename($export_file, Config::$modSettings['export_dir'] . DIRECTORY_SEPARATOR . basename($export_file)); } } @@ -966,7 +966,7 @@ public static function cacheConfigVars(): array // Maybe we have some additional settings from the selected accelerator. if (!empty($detectedCacheApis)) { foreach ($detectedCacheApis as $class_name_txt_key => $cache_api) { - if (is_callable([$cache_api, 'cacheSettings'])) { + if (\is_callable([$cache_api, 'cacheSettings'])) { $cache_api->cacheSettings($config_vars); } } @@ -997,7 +997,7 @@ public static function exportConfigVars(): array they report obviously insane values, it's not possible to track disk usage correctly. */ - self::$diskspace_disabled = (!function_exists('disk_free_space') || !function_exists('disk_total_space') || intval(@disk_total_space(file_exists(Config::$modSettings['export_dir']) ? Config::$modSettings['export_dir'] : Config::$boarddir)) < 1440); + self::$diskspace_disabled = (!\function_exists('disk_free_space') || !\function_exists('disk_total_space') || \intval(@disk_total_space(file_exists(Config::$modSettings['export_dir']) ? Config::$modSettings['export_dir'] : Config::$boarddir)) < 1440); $config_vars = [ ['text', 'export_dir', 40], @@ -1123,7 +1123,7 @@ public static function prepareServerSettingsContext(array &$config_vars): void Utils::$context['config_vars'] = []; foreach ($config_vars as $identifier => $config_var) { - if (!is_array($config_var) || !isset($config_var[1])) { + if (!\is_array($config_var) || !isset($config_var[1])) { Utils::$context['config_vars'][] = $config_var; } else { // Set the subtext in case it's part of the label. @@ -1140,8 +1140,8 @@ public static function prepareServerSettingsContext(array &$config_vars): void 'label' => $config_var[1], 'help' => $config_var[5] ?? '', 'type' => $config_var[3], - 'size' => !empty($config_var[4]) && !is_array($config_var[4]) ? $config_var[4] : 0, - 'data' => isset($config_var[4]) && is_array($config_var[4]) && $config_var[3] != 'select' ? $config_var[4] : [], + 'size' => !empty($config_var[4]) && !\is_array($config_var[4]) ? $config_var[4] : 0, + 'data' => isset($config_var[4]) && \is_array($config_var[4]) && $config_var[3] != 'select' ? $config_var[4] : [], 'name' => $config_var[0], 'value' => $config_var[2] == 'file' ? Utils::htmlspecialchars((string) Config::${$config_var[0]}) : (isset(Config::$modSettings[$config_var[0]]) ? Utils::htmlspecialchars(Config::$modSettings[$config_var[0]]) : (in_array($config_var[3], ['int', 'float']) ? 0 : '')), 'disabled' => !empty(Utils::$context['settings_not_writable']) || !empty($config_var['disabled']), @@ -1171,11 +1171,11 @@ public static function prepareServerSettingsContext(array &$config_vars): void } // If this is a select box handle any data. - if (!empty($config_var[4]) && is_array($config_var[4])) { + if (!empty($config_var[4]) && \is_array($config_var[4])) { // If it's associative $config_values = array_values($config_var[4]); - if (isset($config_values[0]) && is_array($config_values[0])) { + if (isset($config_values[0]) && \is_array($config_values[0])) { Utils::$context['config_vars'][$config_var[0]]['data'] = $config_var[4]; } else { foreach ($config_var[4] as $key => $item) { diff --git a/Sources/Actions/Admin/Smileys.php b/Sources/Actions/Admin/Smileys.php index fb75deacfb..8ffa9fbd0b 100644 --- a/Sources/Actions/Admin/Smileys.php +++ b/Sources/Actions/Admin/Smileys.php @@ -169,7 +169,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -195,7 +195,7 @@ public function editSets(): void } // Can't the default set or the only one remaining. - if (self::$smiley_sets[$id]['is_default'] || count(self::$smiley_sets) < 2) { + if (self::$smiley_sets[$id]['is_default'] || \count(self::$smiley_sets) < 2) { continue; } @@ -348,7 +348,7 @@ public function editSets(): void continue; } - if (in_array($pathinfo['extension'], self::$allowed_extenions) && $pathinfo['filename'] != 'blank') { + if (\in_array($pathinfo['extension'], self::$allowed_extenions) && $pathinfo['filename'] != 'blank') { $smileys[Utils::convertCase($entry, 'fold')] = $entry; } } @@ -379,7 +379,7 @@ public function editSets(): void } Db::$db->free_result($request); - Utils::$context['current_set']['can_import'] = count($smileys); + Utils::$context['current_set']['can_import'] = \count($smileys); Utils::$context['current_set']['import_url'] = Config::$scripturl . '?action=admin;area=smileys;sa=import;set=' . Utils::$context['current_set']['path'] . ';' . Utils::$context['session_var'] . '=' . Utils::$context['session_id']; } @@ -392,11 +392,11 @@ public function editSets(): void $dir = dir(self::$smileys_dir); while ($entry = $dir->read()) { - if (!in_array($entry, ['.', '..']) && is_dir(self::$smileys_dir . '/' . $entry)) { + if (!\in_array($entry, ['.', '..']) && is_dir(self::$smileys_dir . '/' . $entry)) { Utils::$context['smiley_set_dirs'][] = [ 'id' => $entry, 'path' => self::$smileys_dir . '/' . $entry, - 'selectable' => $entry == Utils::$context['current_set']['path'] || !in_array($entry, explode(',', Config::$modSettings['smiley_sets_known'])), + 'selectable' => $entry == Utils::$context['current_set']['path'] || !\in_array($entry, explode(',', Config::$modSettings['smiley_sets_known'])), 'current' => $entry == Utils::$context['current_set']['path'], ]; } @@ -619,7 +619,7 @@ public function add(): void // And make sure it is legitimate $pathinfo = pathinfo($_POST['smiley_filename']); - if (!in_array($pathinfo['extension'], self::$allowed_extenions)) { + if (!\in_array($pathinfo['extension'], self::$allowed_extenions)) { ErrorHandler::fatalLang('smileys_upload_error_types', false, [implode(', ', self::$allowed_extenions)]); } @@ -755,7 +755,7 @@ public function add(): void continue; } - if (empty(Utils::$context['filenames'][$smiley_set['path']][self::sanitizeFileName($entry_info['filename'])]) && in_array(strtolower($entry_info['extension']), self::$allowed_extenions)) { + if (empty(Utils::$context['filenames'][$smiley_set['path']][self::sanitizeFileName($entry_info['filename'])]) && \in_array(strtolower($entry_info['extension']), self::$allowed_extenions)) { Utils::$context['filenames'][$smiley_set['path']][self::sanitizeFileName($entry_info['filename'])] = [ 'id' => Utils::htmlspecialchars($entry), 'selected' => $entry_info['filename'] == 'smiley' && $smiley_set['path'] == Utils::$context['selected_set'], @@ -1295,7 +1295,7 @@ function changeSet(newSet) while ($entry = $dir->read()) { if ( empty(Utils::$context['filenames'][$smiley_set['path']][$entry]) - && in_array(pathinfo($entry, PATHINFO_EXTENSION), self::$allowed_extenions) + && \in_array(pathinfo($entry, PATHINFO_EXTENSION), self::$allowed_extenions) ) { Utils::$context['filenames'][$smiley_set['path']][$entry] = [ 'id' => Utils::htmlspecialchars($entry), @@ -1434,7 +1434,7 @@ public function setOrder(): void 'id' => $location, 'title' => $location == 'postform' ? Lang::$txt['smileys_location_form'] : Lang::$txt['smileys_location_popup'], 'description' => $location == 'postform' ? Lang::$txt['smileys_location_form_description'] : Lang::$txt['smileys_location_popup_description'], - 'last_row' => count(Utils::$context['smileys'][$location]['rows']), + 'last_row' => \count(Utils::$context['smileys'][$location]['rows']), 'rows' => array_values(Utils::$context['smileys'][$location]['rows']), ]; } @@ -1563,7 +1563,7 @@ public function install(): void if ($extracted && !file_exists(Config::$packagesdir . '/temp/package-info.xml')) { foreach ($extracted as $file) { if (basename($file['filename']) == 'package-info.xml') { - $base_path = dirname($file['filename']) . '/'; + $base_path = \dirname($file['filename']) . '/'; break; } } @@ -1579,7 +1579,7 @@ public function install(): void $smileyInfo = SubsPackage::getPackageInfo(Utils::$context['filename']); - if (!is_array($smileyInfo)) { + if (!\is_array($smileyInfo)) { ErrorHandler::fatalLang($smileyInfo, false); } @@ -1639,7 +1639,7 @@ public function install(): void $file = Config::$packagesdir . '/temp/' . $base_path . $action['filename']; - if (isset($action['filename']) && (!file_exists($file) || !is_writable(dirname($action['destination'])))) { + if (isset($action['filename']) && (!file_exists($file) || !is_writable(\dirname($action['destination'])))) { Utils::$context['has_failure'] = true; $thisAction += [ @@ -1681,7 +1681,7 @@ public function install(): void foreach (Utils::$context['actions'] as $action) { Config::updateModSettings([ 'smiley_sets_known' => Config::$modSettings['smiley_sets_known'] . ',' . basename($action['action']), - 'smiley_sets_names' => Config::$modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count(Utils::$context['actions']) > 1 ? ' ' . (!empty($action['description']) ? Utils::htmlspecialchars($action['description']) : basename($action['action'])) : ''), + 'smiley_sets_names' => Config::$modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (\count(Utils::$context['actions']) > 1 ? ' ' . (!empty($action['description']) ? Utils::htmlspecialchars($action['description']) : basename($action['action'])) : ''), ]); } @@ -1800,7 +1800,7 @@ public function editIcon(): void } // There is a 16 character limit on message icons... - if (strlen($_POST['icon_filename']) > 16) { + if (\strlen($_POST['icon_filename']) > 16) { ErrorHandler::fatalLang('icon_name_too_long', false); } @@ -2138,7 +2138,7 @@ public static function list_getSmileySets(int $start, int $items_per_page, strin */ public static function list_getNumSmileySets(): int { - return count(explode(',', Config::$modSettings['smiley_sets_known'])); + return \count(explode(',', Config::$modSettings['smiley_sets_known'])); } /** @@ -2340,7 +2340,7 @@ protected function import(string $smileyPath, bool $create = false): void continue; } - if (in_array($pathinfo['extension'], self::$allowed_extenions) && $pathinfo['filename'] != 'blank' && strlen($pathinfo['basename']) <= 48) { + if (\in_array($pathinfo['extension'], self::$allowed_extenions) && $pathinfo['filename'] != 'blank' && \strlen($pathinfo['basename']) <= 48) { $smiley_files[strtolower($pathinfo['basename'])] = $pathinfo['basename']; } } @@ -2574,7 +2574,7 @@ protected function createDir(string $dir, string $name): void $path = realpath(self::$smileys_dir . DIRECTORY_SEPARATOR . $dir); // Must be an immediate child directory of the base smileys directory. - if (dirname($path) !== realpath(self::$smileys_dir)) { + if (\dirname($path) !== realpath(self::$smileys_dir)) { ErrorHandler::fatalLang('smiley_set_dir_not_found', false, [Utils::htmlspecialchars($name)]); } @@ -2600,7 +2600,7 @@ protected function createDir(string $dir, string $name): void */ protected function validateImage(string $name, string $tmp_name): bool { - return in_array(pathinfo($name, PATHINFO_EXTENSION), self::$allowed_extenions) && Utils::checkMimeType($tmp_name, Utils::buildRegex(self::$allowed_mime_types, '~'), true); + return \in_array(pathinfo($name, PATHINFO_EXTENSION), self::$allowed_extenions) && Utils::checkMimeType($tmp_name, Utils::buildRegex(self::$allowed_mime_types, '~'), true); } /** @@ -2617,7 +2617,7 @@ protected function moveImageIntoPlace(string $name, string $tmp_name, array $des ErrorHandler::fatalLang('smileys_upload_error_blank', false); } - if (!is_uploaded_file($tmp_name) || (ini_get('open_basedir') == '' && !file_exists($tmp_name))) { + if (!is_uploaded_file($tmp_name) || (\ini_get('open_basedir') == '' && !file_exists($tmp_name))) { ErrorHandler::fatalLang('smileys_upload_error', false); } @@ -2633,7 +2633,7 @@ protected function moveImageIntoPlace(string $name, string $tmp_name, array $des $destination_name = basename($name); // Make sure they aren't trying to upload a nasty file - for their own good here! - if (in_array(strtolower($destination_name), self::$illegal_files)) { + if (\in_array(strtolower($destination_name), self::$illegal_files)) { ErrorHandler::fatalLang('smileys_upload_error_illegal', false); } diff --git a/Sources/Actions/Admin/Subscriptions.php b/Sources/Actions/Admin/Subscriptions.php index 6805965ea4..8b798fe237 100644 --- a/Sources/Actions/Admin/Subscriptions.php +++ b/Sources/Actions/Admin/Subscriptions.php @@ -101,7 +101,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -150,7 +150,7 @@ public function view(): void ], 'get_count' => [ 'function' => function () { - return count(self::$all); + return \count(self::$all); }, ], 'no_items_label' => Lang::$txt['paid_none_yet'], @@ -583,7 +583,7 @@ public function modify(): void $isRepeatable = isset($_POST['repeatable']) ? 1 : 0; $allowpartial = isset($_POST['allow_partial']) ? 1 : 0; $reminder = isset($_POST['reminder']) ? (int) $_POST['reminder'] : 0; - $emailComplete = strlen($_POST['emailcomplete']) > 10 ? trim($_POST['emailcomplete']) : ''; + $emailComplete = \strlen($_POST['emailcomplete']) > 10 ? trim($_POST['emailcomplete']) : ''; $_POST['prim_group'] = !empty($_POST['prim_group']) ? (int) $_POST['prim_group'] : 0; // Cleanup text fields @@ -1326,7 +1326,7 @@ public static function getConfigVars(): array // If the currency is set to something different then we need to set it to other for this to work and set it back shortly. Config::$modSettings['paid_currency'] = !empty(Config::$modSettings['paid_currency_code']) ? Config::$modSettings['paid_currency_code'] : ''; - if (!empty(Config::$modSettings['paid_currency_code']) && !in_array(Config::$modSettings['paid_currency_code'], ['usd', 'eur', 'gbp', 'cad', 'aud'])) { + if (!empty(Config::$modSettings['paid_currency_code']) && !\in_array(Config::$modSettings['paid_currency_code'], ['usd', 'eur', 'gbp', 'cad', 'aud'])) { Config::$modSettings['paid_currency'] = 'other'; } @@ -1866,15 +1866,15 @@ public static function remove(int $id_subscribe, int $id_member, bool $delete = $existingGroups = explode(',', $additional_groups); foreach ($existingGroups as $key => $group) { - if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed))) { + if (empty($group) || (\in_array($group, $removals) && !\in_array($group, $allowed))) { unset($existingGroups[$key]); } } // Finally, do something with the current primary group. - if (in_array($id_group, $removals)) { + if (\in_array($id_group, $removals)) { // If this primary group is actually allowed keep it. - if (in_array($id_group, $allowed)) { + if (\in_array($id_group, $allowed)) { $existingGroups[] = $id_group; } @@ -1951,7 +1951,7 @@ public static function remove(int $id_subscribe, int $id_member, bool $delete = public static function reapply(array $users): void { // Make it an array. - if (!is_array($users)) { + if (!\is_array($users)) { $users = [$users]; } diff --git a/Sources/Actions/Admin/Tasks.php b/Sources/Actions/Admin/Tasks.php index 4f7af6b292..a7d9b0a0fe 100644 --- a/Sources/Actions/Admin/Tasks.php +++ b/Sources/Actions/Admin/Tasks.php @@ -81,7 +81,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -306,7 +306,7 @@ public function edit(): void // The other time bits are simple! $interval = max((int) $_POST['regularity'], 1); - $unit = in_array(substr($_POST['unit'], 0, 1), ['m', 'h', 'd', 'w']) ? substr($_POST['unit'], 0, 1) : 'd'; + $unit = \in_array(substr($_POST['unit'], 0, 1), ['m', 'h', 'd', 'w']) ? substr($_POST['unit'], 0, 1) : 'd'; // Don't allow one minute intervals. if ($interval == 1 && $unit == 'm') { diff --git a/Sources/Actions/Admin/Themes.php b/Sources/Actions/Admin/Themes.php index 28cd05691b..a789f403d9 100644 --- a/Sources/Actions/Admin/Themes.php +++ b/Sources/Actions/Admin/Themes.php @@ -110,7 +110,7 @@ public function execute(): void } if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -139,7 +139,7 @@ public function admin(): void ErrorHandler::fatalLang('themes_none_selectable', false); } - if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) { + if (!\in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) { ErrorHandler::fatalLang('themes_default_selectable', false); } @@ -150,7 +150,7 @@ public function admin(): void 'knownThemes' => implode(',', $_POST['options']['known_themes']), ]); - if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) { + if ((int) $_POST['theme_reset'] == 0 || \in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) { User::updateMemberData(null, ['id_theme' => (int) $_POST['theme_reset']]); } @@ -366,7 +366,7 @@ public function setOptions(): void $setValues = []; foreach ($_POST['options'] as $opt => $val) { - $setValues[] = [-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val]; + $setValues[] = [-1, $_GET['th'], $opt, \is_array($val) ? implode(',', $val) : $val]; } $old_settings = []; @@ -374,7 +374,7 @@ public function setOptions(): void foreach ($_POST['default_options'] as $opt => $val) { $old_settings[] = $opt; - $setValues[] = [-1, 1, $opt, is_array($val) ? implode(',', $val) : $val]; + $setValues[] = [-1, 1, $opt, \is_array($val) ? implode(',', $val) : $val]; } // If we're actually inserting something.. @@ -447,7 +447,7 @@ public function setOptions(): void FROM {db_prefix}members', [ 'option' => $opt, - 'value' => (is_array($val) ? implode(',', $val) : $val), + 'value' => (\is_array($val) ? implode(',', $val) : $val), ], ); @@ -511,7 +511,7 @@ public function setOptions(): void [ 'current_theme' => $_GET['th'], 'option' => $opt, - 'value' => (is_array($val) ? implode(',', $val) : $val), + 'value' => (\is_array($val) ? implode(',', $val) : $val), ], ); } elseif ($_POST['options_master'][$opt] == 2) { @@ -622,7 +622,7 @@ public function setOptions(): void foreach (Utils::$context['options'] as $i => $setting) { // Just skip separators - if (!is_array($setting)) { + if (!\is_array($setting)) { continue; } @@ -738,7 +738,7 @@ public function setSettings(): void // Make sure items are cast correctly. foreach (Utils::$context['theme_settings'] as $item) { // Disregard this item if this is just a separator. - if (!is_array($item)) { + if (!\is_array($item)) { continue; } @@ -762,11 +762,11 @@ public function setSettings(): void $inserts = []; foreach ($_POST['options'] as $opt => $val) { - $inserts[] = [0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val]; + $inserts[] = [0, $_GET['th'], $opt, \is_array($val) ? implode(',', $val) : $val]; } foreach ($_POST['default_options'] as $opt => $val) { - $inserts[] = [0, 1, $opt, is_array($val) ? implode(',', $val) : $val]; + $inserts[] = [0, 1, $opt, \is_array($val) ? implode(',', $val) : $val]; } // If we're actually inserting something.. @@ -793,7 +793,7 @@ public function setSettings(): void Utils::$context['page_title'] = Lang::$txt['theme_settings']; foreach (Theme::$current->settings as $setting => $dummy) { - if (!in_array($setting, ['theme_url', 'theme_dir', 'images_url', 'template_dirs'])) { + if (!\in_array($setting, ['theme_url', 'theme_dir', 'images_url', 'template_dirs'])) { Theme::$current->settings[$setting] = Utils::htmlspecialcharsRecursive(Theme::$current->settings[$setting]); } } @@ -803,7 +803,7 @@ public function setSettings(): void foreach (Utils::$context['settings'] as $i => $setting) { // Separators are dummies, so leave them alone. - if (!is_array($setting)) { + if (!\is_array($setting)) { continue; } @@ -955,7 +955,7 @@ public function install(): void } // Call the function and handle the result. - $result = call_user_func([$this, $do_actions[$do_action]]); + $result = \call_user_func([$this, $do_actions[$do_action]]); // Everything went better than expected! if (!empty($result)) { @@ -1035,7 +1035,7 @@ public function edit(): ?string if (isset($_GET['directory']) && $_GET['directory'] != '') { Utils::$context['theme_files'] = $this->getFileList($currentTheme['theme_dir'] . '/' . $_GET['directory'], $_GET['directory'] . '/'); - $temp = dirname($_GET['directory']); + $temp = \dirname($_GET['directory']); array_unshift(Utils::$context['theme_files'], [ 'filename' => $temp == '.' || $temp == '' ? '/ (..)' : $temp . ' (..)', @@ -1081,7 +1081,7 @@ public function edit(): ?string if (isset($_POST['save'])) { if (User::$me->checkSession('post', '', false) == '' && SecurityToken::validate('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true) { - if (is_array($_POST['entire_file'])) { + if (\is_array($_POST['entire_file'])) { $_POST['entire_file'] = implode("\n", $_POST['entire_file']); } @@ -1106,7 +1106,7 @@ public function edit(): ?string // Nuke any minified files and update Config::$modSettings['browser_cache'] Theme::deleteAllMinified(); - Utils::redirectexit('action=admin;area=theme;th=' . $_GET['th'] . ';' . Utils::$context['session_var'] . '=' . Utils::$context['session_id'] . ';sa=edit;directory=' . dirname($_REQUEST['filename'])); + Utils::redirectexit('action=admin;area=theme;th=' . $_GET['th'] . ';' . Utils::$context['session_var'] . '=' . Utils::$context['session_id'] . ';sa=edit;directory=' . \dirname($_REQUEST['filename'])); } } // Session timed out. @@ -1117,7 +1117,7 @@ public function edit(): ?string Utils::$context['sub_template'] = 'edit_file'; // Recycle the submitted data. - if (is_array($_POST['entire_file'])) { + if (\is_array($_POST['entire_file'])) { Utils::$context['entire_file'] = Utils::htmlspecialchars(implode("\n", $_POST['entire_file'])); } else { Utils::$context['entire_file'] = Utils::htmlspecialchars($_POST['entire_file']); @@ -1670,8 +1670,8 @@ protected function getSingleTheme(int $id, array $variables = []): bool|array } // Is this theme installed and enabled? - $single['known'] = in_array($single['id'], $knownThemes); - $single['enable'] = in_array($single['id'], $enableThemes); + $single['known'] = \in_array($single['id'], $knownThemes); + $single['enable'] = \in_array($single['id'], $enableThemes); // It should at least return if the theme is a known one or if its enable. return $single; @@ -1732,8 +1732,8 @@ protected function getAllThemes(bool $enable_only = false): void if (!isset(Utils::$context['themes'][$row['id_theme']])) { Utils::$context['themes'][$row['id_theme']] = [ 'id' => (int) $row['id_theme'], - 'known' => in_array($row['id_theme'], $knownThemes), - 'enable' => in_array($row['id_theme'], $enableThemes), + 'known' => \in_array($row['id_theme'], $knownThemes), + 'enable' => \in_array($row['id_theme'], $enableThemes), ]; } @@ -1796,8 +1796,8 @@ protected function getInstalledThemes(): void if (!isset(Utils::$context['themes'][$row['id_theme']])) { Utils::$context['themes'][$row['id_theme']] = [ 'id' => (int) $row['id_theme'], - 'known' => in_array($row['id_theme'], $knownThemes), - 'enable' => in_array($row['id_theme'], $enableThemes), + 'known' => \in_array($row['id_theme'], $knownThemes), + 'enable' => \in_array($row['id_theme'], $enableThemes), ]; } diff --git a/Sources/Actions/Announce.php b/Sources/Actions/Announce.php index bc8dfb3056..7520733712 100644 --- a/Sources/Actions/Announce.php +++ b/Sources/Actions/Announce.php @@ -79,7 +79,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -147,7 +147,7 @@ public function send(): void // Make sure all membergroups are integers and can access the board of the announcement. foreach ($_POST['who'] as $id => $mg) { - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; + $_POST['who'][$id] = \in_array((int) $mg, $groups) ? (int) $mg : 0; } // Get the topic subject and censor it. diff --git a/Sources/Actions/AttachmentApprove.php b/Sources/Actions/AttachmentApprove.php index 7fb4cce16f..e1f577e68f 100644 --- a/Sources/Actions/AttachmentApprove.php +++ b/Sources/Actions/AttachmentApprove.php @@ -99,7 +99,7 @@ public function execute(): void while ($row = Db::$db->fetch_assoc($request)) { // We can only add it if we can approve in this board! - if ($allowed_boards = [0] || in_array($row['id_board'], $allowed_boards)) { + if ($allowed_boards = [0] || \in_array($row['id_board'], $allowed_boards)) { $attachments[] = $row['id_attach']; // Also come up with the redirection URL. diff --git a/Sources/Actions/AttachmentDownload.php b/Sources/Actions/AttachmentDownload.php index dc57c37ac1..aaac060d9b 100644 --- a/Sources/Actions/AttachmentDownload.php +++ b/Sources/Actions/AttachmentDownload.php @@ -107,7 +107,7 @@ public function execute(): void $request = null; IntegrationHook::call('integrate_download_request', [&$request]); - if (!is_null($request) && Db::$db->is_resource($request)) { + if (!\is_null($request) && Db::$db->is_resource($request)) { // No attachment has been found. if (Db::$db->num_rows($request) == 0) { Utils::sendHttpStatus(404, 'File Not Found'); @@ -181,7 +181,7 @@ public function execute(): void !empty($file->msg) && ( empty($file->board) - || ($boards_allowed !== [0] && !in_array($file->board, $boards_allowed)) + || ($boards_allowed !== [0] && !\in_array($file->board, $boards_allowed)) ) ) ) @@ -261,8 +261,8 @@ public function execute(): void list($a, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); list($range) = explode(',', $range, 2); list($range, $range_end) = explode('-', $range); - $range = intval($range); - $range_end = !$range_end ? $file->size - 1 : intval($range_end); + $range = \intval($range); + $range_end = !$range_end ? $file->size - 1 : \intval($range_end); $length = $range_end - $range + 1; } diff --git a/Sources/Actions/AttachmentUpload.php b/Sources/Actions/AttachmentUpload.php index e72ecd66ab..b00f9fde24 100644 --- a/Sources/Actions/AttachmentUpload.php +++ b/Sources/Actions/AttachmentUpload.php @@ -138,7 +138,7 @@ public function execute(): void $this->_sa = !empty($_REQUEST['sa']) ? Utils::htmlspecialchars(Utils::htmlTrim($_REQUEST['sa'])) : false; - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { + if ($this->_canPostAttachment && $this->_sa && \in_array($this->_sa, $this->_subActions)) { $this->{$this->_sa}(); } // Just send a generic message. @@ -229,7 +229,7 @@ protected function processAttachments(): void // If this isn't a new post, check the current attachments. if (isset($_REQUEST['msg'])) { - Utils::$context['attachments']['quantity'] = count(Utils::$context['current_attachments']); + Utils::$context['attachments']['quantity'] = \count(Utils::$context['current_attachments']); foreach (Utils::$context['current_attachments'] as $attachment) { Utils::$context['attachments']['total_size'] += $attachment['size']; @@ -237,7 +237,7 @@ protected function processAttachments(): void } // A bit of house keeping first. - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { + if (!empty($_SESSION['temp_attachments']) && \count($_SESSION['temp_attachments']) == 1) { unset($_SESSION['temp_attachments']); } @@ -444,10 +444,10 @@ protected function createAttach(): void foreach ($attachment['errors'] as $error) { $attachmentOptions['errors'][] = Lang::getTxt('attach_warning', $attachment); - if (!is_array($error)) { + if (!\is_array($error)) { $attachmentOptions['errors'][] = Lang::$txt[$error]; - if (in_array($error, $log_these)) { + if (\in_array($error, $log_these)) { ErrorHandler::log($attachment['name'] . ': ' . Lang::$txt[$error], 'critical'); } } else { @@ -503,7 +503,7 @@ protected function setResponse(array $data = []): void // Is there any generic errors? made some sense out of them! if ($this->_generalErrors) { foreach ($this->_generalErrors as $k => $v) { - $this->_generalErrors[$k] = (is_array($v) ? Lang::getTxt($v[0], (array) $v[1]) : Lang::$txt[$v]); + $this->_generalErrors[$k] = (\is_array($v) ? Lang::getTxt($v[0], (array) $v[1]) : Lang::$txt[$v]); } } diff --git a/Sources/Actions/AutoSuggest.php b/Sources/Actions/AutoSuggest.php index f083a6e0d7..e0e4834470 100644 --- a/Sources/Actions/AutoSuggest.php +++ b/Sources/Actions/AutoSuggest.php @@ -92,11 +92,11 @@ public function execute(): void Utils::$context['sub_template'] = 'generic_xml'; if (method_exists($this, self::$suggest_types[$this->suggest_type])) { - Utils::$context['xml_data'] = call_user_func([$this, self::$suggest_types[$this->suggest_type]]); - } elseif (function_exists('AutoSuggest_Search_' . self::$suggest_types[$this->suggest_type])) { - Utils::$context['xml_data'] = call_user_func('AutoSuggest_Search_' . self::$suggest_types[$this->suggest_type]); - } elseif (function_exists('AutoSuggest_Search_' . $this->suggest_type)) { - Utils::$context['xml_data'] = call_user_func('AutoSuggest_Search_' . $this->suggest_type); + Utils::$context['xml_data'] = \call_user_func([$this, self::$suggest_types[$this->suggest_type]]); + } elseif (\function_exists('AutoSuggest_Search_' . self::$suggest_types[$this->suggest_type])) { + Utils::$context['xml_data'] = \call_user_func('AutoSuggest_Search_' . self::$suggest_types[$this->suggest_type]); + } elseif (\function_exists('AutoSuggest_Search_' . $this->suggest_type)) { + Utils::$context['xml_data'] = \call_user_func('AutoSuggest_Search_' . $this->suggest_type); } } @@ -281,7 +281,7 @@ public static function checkRegistered(string $suggest_type): bool { IntegrationHook::call('integrate_autosuggest', [&self::$suggest_types]); - return isset(self::$suggest_types[$suggest_type]) && (method_exists(__CLASS__, $suggest_type) || function_exists('AutoSuggest_Search_' . self::$suggest_types[$suggest_type]) || function_exists('AutoSuggest_Search_' . $suggest_type)); + return isset(self::$suggest_types[$suggest_type]) && (method_exists(__CLASS__, $suggest_type) || \function_exists('AutoSuggest_Search_' . self::$suggest_types[$suggest_type]) || \function_exists('AutoSuggest_Search_' . $suggest_type)); } /** diff --git a/Sources/Actions/BackwardCompatibility.php b/Sources/Actions/BackwardCompatibility.php index f405118b2b..6ea1337823 100644 --- a/Sources/Actions/BackwardCompatibility.php +++ b/Sources/Actions/BackwardCompatibility.php @@ -37,14 +37,14 @@ public static function subActionProvider(?string $sa = null, bool $return_config self::load(); - if (is_string($sa)) { + if (\is_string($sa)) { // make sure it's a supported subaction - if (array_key_exists($sa, self::$subactions)) { + if (\array_key_exists($sa, self::$subactions)) { self::$obj->subaction = $sa; } } - if (is_string($activity)) { + if (\is_string($activity)) { self::$obj->activity = $activity; } diff --git a/Sources/Actions/BoardIndex.php b/Sources/Actions/BoardIndex.php index 36eb34de25..119c3fb5ca 100644 --- a/Sources/Actions/BoardIndex.php +++ b/Sources/Actions/BoardIndex.php @@ -359,12 +359,12 @@ public static function get(array $board_index_options): array // Find all boards and categories, as well as related information. foreach (Board::queryData($selects, $params, $joins, $where, $order) as $row_board) { - $row_board = array_filter($row_board, fn ($prop) => !is_null($prop)); + $row_board = array_filter($row_board, fn ($prop) => !\is_null($prop)); $parent = Board::$loaded[$row_board['id_parent']] ?? null; // Perhaps we are ignoring this board? - $ignoreThisBoard = in_array($row_board['id_board'], User::$me->ignoreboards); + $ignoreThisBoard = \in_array($row_board['id_board'], User::$me->ignoreboards); $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; if ($board_index_options['include_categories']) { @@ -421,7 +421,7 @@ public static function get(array $board_index_options): array 'is_redirect' => (bool) $row_board['is_redirect'], 'unapproved_topics' => $row_board['unapproved_topics'], 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], - 'can_approve_posts' => !empty(User::$me->mod_cache['ap']) && (User::$me->mod_cache['ap'] == [0] || in_array($row_board['id_board'], User::$me->mod_cache['ap'])), + 'can_approve_posts' => !empty(User::$me->mod_cache['ap']) && (User::$me->mod_cache['ap'] == [0] || \in_array($row_board['id_board'], User::$me->mod_cache['ap'])), 'href' => Config::$scripturl . '?board=' . $row_board['id_board'] . '.0', 'link' => '' . $row_board['board_name'] . '', 'board_class' => 'off', diff --git a/Sources/Actions/BuddyListToggle.php b/Sources/Actions/BuddyListToggle.php index 16ac4ceaca..5a92bf0f1d 100644 --- a/Sources/Actions/BuddyListToggle.php +++ b/Sources/Actions/BuddyListToggle.php @@ -63,7 +63,7 @@ public function execute(): void } // Remove if it's already there... - if (in_array($this->userReceiver, User::$me->buddies)) { + if (\in_array($this->userReceiver, User::$me->buddies)) { User::$me->buddies = array_diff(User::$me->buddies, [$this->userReceiver]); } // ...or add if it's not and if it's not you. diff --git a/Sources/Actions/Calendar.php b/Sources/Actions/Calendar.php index befd8dabed..d3d2ccd276 100644 --- a/Sources/Actions/Calendar.php +++ b/Sources/Actions/Calendar.php @@ -87,7 +87,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -244,9 +244,9 @@ public function show(): void // Load all the context information needed to show the calendar grid. $calendarOptions = [ 'start_day' => !empty(Theme::$current->options['calendar_start_day']) ? Theme::$current->options['calendar_start_day'] : 0, - 'show_birthdays' => in_array(Config::$modSettings['cal_showbdays'], [1, 2]), - 'show_events' => in_array(Config::$modSettings['cal_showevents'], [1, 2]), - 'show_holidays' => in_array(Config::$modSettings['cal_showholidays'], [1, 2]), + 'show_birthdays' => \in_array(Config::$modSettings['cal_showbdays'], [1, 2]), + 'show_events' => \in_array(Config::$modSettings['cal_showevents'], [1, 2]), + 'show_holidays' => \in_array(Config::$modSettings['cal_showholidays'], [1, 2]), 'show_week_num' => true, 'short_day_titles' => !empty(Config::$modSettings['cal_short_days']), 'short_month_titles' => !empty(Config::$modSettings['cal_short_months']), @@ -408,7 +408,7 @@ public function post(): void User::$me->checkSession(); // Validate the post... - if (!in_array($_POST['link_to'] ?? '', ['board', 'topic'])) { + if (!\in_array($_POST['link_to'] ?? '', ['board', 'topic'])) { self::validateEventPost(); } @@ -418,7 +418,7 @@ public function post(): void } // New - and directing? - if (in_array($_POST['link_to'] ?? '', ['board', 'topic']) || empty(Config::$modSettings['cal_allow_unlinked'])) { + if (\in_array($_POST['link_to'] ?? '', ['board', 'topic']) || empty(Config::$modSettings['cal_allow_unlinked'])) { $_REQUEST['calendar'] = 1; if (empty($_POST['topic'])) { @@ -560,7 +560,7 @@ public function post(): void } else { // Load the list of boards and categories in the context. $boardListOptions = [ - 'included_boards' => in_array(0, $boards) ? null : $boards, + 'included_boards' => \in_array(0, $boards) ? null : $boards, 'not_redirection' => true, 'use_permissions' => true, 'selected_board' => Config::$modSettings['cal_defaultboard'], @@ -578,7 +578,7 @@ public function post(): void ]; Theme::loadTemplate('EventEditor'); - Theme::addJavaScriptVar('monthly_byday_items', (string) (count(Utils::$context['event']->byday_items) - 1)); + Theme::addJavaScriptVar('monthly_byday_items', (string) (\count(Utils::$context['event']->byday_items) - 1)); Theme::loadJavaScriptFile('event.js', ['defer' => true], 'smf_event'); } @@ -661,7 +661,7 @@ public function export(): void $event = $occurrence->getParentEvent(); // Skip if we already exported the full event. - if (in_array($event->uid, $full_event_uids)) { + if (\in_array($event->uid, $full_event_uids)) { continue; } @@ -693,7 +693,7 @@ public function export(): void // RFC 5545 requires "\r\n", not just "\n". $file['content'] = implode("\r\n", $file['content']); - $file['size'] = strlen($file['content']); + $file['size'] = \strlen($file['content']); // Send it. Utils::emitFile($file); @@ -827,7 +827,7 @@ public static function getEventRange(string $low_date, string $high_date, bool $ } foreach ($occurrences as $mday => $array) { - $occurrences[$mday][count($array) - 1]['is_last'] = true; + $occurrences[$mday][\count($array) - 1]['is_last'] = true; } ksort($occurrences); @@ -1259,7 +1259,7 @@ public static function getCalendarList(string $start_date, string $end_date, arr foreach ($calendarGrid['events'] as $date => $date_events) { foreach ($date_events as $event_key => $event_val) { - if (in_array($event_val['id'] . ' ' . $event_val['start']->format('c'), $temp)) { + if (\in_array($event_val['id'] . ' ' . $event_val['start']->format('c'), $temp)) { unset($calendarGrid['events'][$date][$event_key]); if (empty($calendarGrid['events'][$date])) { @@ -1403,11 +1403,11 @@ public static function cache_getRecentEvents(array $eventOptions): array } // Mark the last item so that a list separator can be used in the template. - for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) { + for ($i = 0, $n = \count($return_data['calendar_birthdays']); $i < $n; $i++) { $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); } - for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) { + for ($i = 0, $n = \count($return_data['calendar_events']); $i < $n; $i++) { $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); } diff --git a/Sources/Actions/CoppaForm.php b/Sources/Actions/CoppaForm.php index e25c9ef47d..c46c17648f 100644 --- a/Sources/Actions/CoppaForm.php +++ b/Sources/Actions/CoppaForm.php @@ -105,7 +105,7 @@ public function execute(): void header('connection: close'); header('content-disposition: attachment; filename="approval.txt"'); header('content-type: ' . (BrowserDetector::isBrowser('ie') || BrowserDetector::isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); - header('content-length: ' . strlen($data)); + header('content-length: ' . \strlen($data)); echo $data; Utils::obExit(false); diff --git a/Sources/Actions/Credits.php b/Sources/Actions/Credits.php index 09f8b62231..a8d5697b6c 100644 --- a/Sources/Actions/Credits.php +++ b/Sources/Actions/Credits.php @@ -241,7 +241,7 @@ public function execute(): void ]; // Give the translators some credit for their hard work. - if (!is_array(Lang::$txt['translation_credits'])) { + if (!\is_array(Lang::$txt['translation_credits'])) { Lang::$txt['translation_credits'] = array_filter(array_map('trim', explode(',', Lang::$txt['translation_credits']))); } diff --git a/Sources/Actions/Display.php b/Sources/Actions/Display.php index a916a4947a..dc3cd2a357 100644 --- a/Sources/Actions/Display.php +++ b/Sources/Actions/Display.php @@ -322,7 +322,7 @@ protected function __construct() protected function checkPrevNextRedirect(): void { // Find the previous or next topic. But don't bother if there's only one. - if (isset($_REQUEST['prev_next']) && in_array($_REQUEST['prev_next'], ['prev', 'next']) && Board::$info->num_topics > 1) { + if (isset($_REQUEST['prev_next']) && \in_array($_REQUEST['prev_next'], ['prev', 'next']) && Board::$info->num_topics > 1) { $prev = $_REQUEST['prev_next'] === 'prev'; // Just prepare some variables that are used in the query. @@ -425,9 +425,9 @@ protected function preventPrefetch(): void protected function setRobotNoIndex(): void { // Let's do some work on what to search index. - if (count($_GET) > 2) { + if (\count($_GET) > 2) { foreach ($_GET as $k => $v) { - if (!in_array($k, ['topic', 'board', 'start', session_name()])) { + if (!\in_array($k, ['topic', 'board', 'start', session_name()])) { Utils::$context['robot_no_index'] = true; } } @@ -763,7 +763,7 @@ protected function getWhoViewing(): void $link = '' . $row['real_name'] . ''; } - $is_buddy = in_array($row['id_member'], User::$me->buddies); + $is_buddy = \in_array($row['id_member'], User::$me->buddies); if ($is_buddy) { $link = '' . $link . ''; @@ -791,7 +791,7 @@ protected function getWhoViewing(): void } // The number of guests is equal to the rows minus the ones we actually used ;). - Utils::$context['view_num_guests'] = Db::$db->num_rows($request) - count(Utils::$context['view_members']); + Utils::$context['view_num_guests'] = Db::$db->num_rows($request) - \count(Utils::$context['view_members']); Db::$db->free_result($request); @@ -891,7 +891,7 @@ protected function setModerators(): void if (!empty(Utils::$context['link_moderators'])) { // And show it after the board's name. - Utils::$context['linktree'][count(Utils::$context['linktree']) - 1]['extra_after'] = '(' . (count(Utils::$context['link_moderators']) == 1 ? Lang::$txt['moderator'] : Lang::$txt['moderators']) . ': ' . implode(', ', Utils::$context['link_moderators']) . ')'; + Utils::$context['linktree'][\count(Utils::$context['linktree']) - 1]['extra_after'] = '(' . (\count(Utils::$context['link_moderators']) == 1 ? Lang::$txt['moderator'] : Lang::$txt['moderators']) . ': ' . implode(', ', Utils::$context['link_moderators']) . ')'; } } @@ -1044,7 +1044,7 @@ protected function loadEvents(): void if (!empty(Utils::$context['linked_calendar_events'])) { Theme::loadTemplate('EventEditor'); - Utils::$context['linked_calendar_events'][count(Utils::$context['linked_calendar_events']) - 1]['is_last'] = true; + Utils::$context['linked_calendar_events'][\count(Utils::$context['linked_calendar_events']) - 1]['is_last'] = true; } } } @@ -1242,7 +1242,7 @@ protected function loadEditor(): void Utils::$context['icons'] = Editor::getMessageIcons(Board::$info->id); if (!empty(Utils::$context['icons'])) { - Utils::$context['icons'][count(Utils::$context['icons']) - 1]['is_last'] = true; + Utils::$context['icons'][\count(Utils::$context['icons']) - 1]['is_last'] = true; } } diff --git a/Sources/Actions/DisplayAdminFile.php b/Sources/Actions/DisplayAdminFile.php index bbc9a2cbea..a95ee0585d 100644 --- a/Sources/Actions/DisplayAdminFile.php +++ b/Sources/Actions/DisplayAdminFile.php @@ -41,7 +41,7 @@ public function execute(): void { Sapi::setMemoryLimit('32M'); - if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) { + if (empty($_REQUEST['filename']) || !\is_string($_REQUEST['filename'])) { ErrorHandler::fatalLang('no_access', false); } diff --git a/Sources/Actions/Feed.php b/Sources/Actions/Feed.php index 61fe7c2980..85fb40d90c 100644 --- a/Sources/Actions/Feed.php +++ b/Sources/Actions/Feed.php @@ -305,7 +305,7 @@ public function __construct(?string $subaction = null, ?int $member = null) $_GET['c'][$i] = (int) $c; } - if (count($_GET['c']) == 1) { + if (\count($_GET['c']) == 1) { $request = Db::$db->query( '', 'SELECT name @@ -368,7 +368,7 @@ public function __construct(?string $subaction = null, ?int $member = null) LIMIT {int:limit}', [ 'board_list' => $_GET['boards'], - 'limit' => count($_GET['boards']), + 'limit' => \count($_GET['boards']), ], ); @@ -480,13 +480,13 @@ public function getData(): array if (empty($this->data)) { // Should we call one of this class's own methods, or something added by a mod? - if (is_callable([$this, self::$subactions[$this->subaction]])) { + if (\is_callable([$this, self::$subactions[$this->subaction]])) { $call = [$this, self::$subactions[$this->subaction]]; } else { $call = Utils::getCallable(self::$subactions[$this->subaction]); } - $this->data = !empty($call) ? call_user_func($call, $this->format) : []; + $this->data = !empty($call) ? \call_user_func($call, $this->format) : []; if ( !empty(CacheApi::$enable) @@ -511,12 +511,12 @@ public function emit(): void $filename[] = $this->metadata['title']; $filename[] = $this->subaction; - if (in_array($this->subaction, ['profile', 'posts', 'personal_messages'])) { + if (\in_array($this->subaction, ['profile', 'posts', 'personal_messages'])) { $filename[] = 'u=' . $this->member; } if (!empty($this->boards)) { - if (count($this->boards) > 1) { + if (\count($this->boards) > 1) { $filename[] = 'boards=' . implode(',', $this->boards); } else { $filename[] = 'board=' . reset($this->boards); @@ -1905,7 +1905,7 @@ public function getXmlPosts(): array $data = []; - $show_all = !empty(User::$me->is_admin) || defined('EXPORTING'); + $show_all = !empty(User::$me->is_admin) || \defined('EXPORTING'); $query_this_message_board = str_replace(['{query_see_board}', 'b.'], ['{query_see_message_board}', 'm.'], $this->query_this_board); @@ -2681,7 +2681,7 @@ public static function build(string $format, array $data, array $metadata, strin $namespaces['smf']['smf'] = sprintf($namespaces['smf']['smf'], $subaction); // These sub-actions need the SMF namespace in other feed formats. - if (in_array($subaction, ['profile', 'posts', 'personal_messages'])) { + if (\in_array($subaction, ['profile', 'posts', 'personal_messages'])) { $namespaces['rss']['smf'] = $namespaces['smf']['smf']; $namespaces['rss2']['smf'] = $namespaces['smf']['smf']; $namespaces['atom']['smf'] = $namespaces['smf']['smf']; @@ -2728,7 +2728,7 @@ public static function build(string $format, array $data, array $metadata, strin } } - $i = in_array($format, ['atom', 'smf']) ? 1 : 2; + $i = \in_array($format, ['atom', 'smf']) ? 1 : 2; $extraFeedTags_string = ''; @@ -2901,7 +2901,7 @@ public static function cdataParse(string $data, string $ns = '', bool $force = f } // Looks like we need to do it the hard way. else { - for ($pos = 0, $n = strlen($data); $pos < $n; null) { + for ($pos = 0, $n = \strlen($data); $pos < $n; null) { $positions = [ strpos($data, ']]>', $pos), strpos($data, '<', $pos), @@ -3031,7 +3031,7 @@ protected function setlimit(): void protected function checkEnabled(): void { // Users can always export their own profile data. - if (in_array($this->subaction, ['profile', 'posts', 'personal_messages']) && $this->member == User::$me->id && !User::$me->is_guest) { + if (\in_array($this->subaction, ['profile', 'posts', 'personal_messages']) && $this->member == User::$me->id && !User::$me->is_guest) { return; } @@ -3075,7 +3075,7 @@ protected static function dumpTags(array $data, int $i, string $format = '', arr continue; } - $forceCdata = in_array($key, $forceCdataKeys); + $forceCdata = \in_array($key, $forceCdataKeys); $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; // First let's indent! @@ -3097,7 +3097,7 @@ protected static function dumpTags(array $data, int $i, string $format = '', arr Utils::$context['feed']['items'] .= '>'; // The element's value. - if (is_array($val)) { + if (\is_array($val)) { // An array. Dump it, and then indent the tag. self::dumpTags($val, $i + 1, $format, $forceCdataKeys, $nsKeys); Utils::$context['feed']['items'] .= "\n" . str_repeat("\t", $i); @@ -3136,7 +3136,7 @@ protected static function fixPossibleUrl(string $val): string empty(Config::$modSettings['queryless_urls']) || ( Sapi::isCGI() - && ini_get('cgi.fix_pathinfo') == 0 + && \ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0 ) || ( diff --git a/Sources/Actions/FindMember.php b/Sources/Actions/FindMember.php index 52bae552ee..f4ec420f53 100644 --- a/Sources/Actions/FindMember.php +++ b/Sources/Actions/FindMember.php @@ -78,7 +78,7 @@ public function execute(): void $_REQUEST['search'] = Utils::htmlspecialchars($_REQUEST['search'], ENT_QUOTES); Utils::$context['results'] = User::find([$_REQUEST['search']], true, Utils::$context['buddy_search']); - $total_results = count(Utils::$context['results']); + $total_results = \count(Utils::$context['results']); Utils::$context['page_index'] = new PageIndex(Config::$scripturl . '?action=findmember;search=' . Utils::$context['last_search'] . ';' . Utils::$context['session_var'] . '=' . Utils::$context['session_id'] . ';input=' . Utils::$context['input_box_name'] . (Utils::$context['quote_results'] ? ';quote=1' : '') . (Utils::$context['buddy_search'] ? ';buddies' : ''), $_REQUEST['start'], $total_results, 7); @@ -96,7 +96,7 @@ public function execute(): void 'num_pages' => floor(($total_results - 1) / 7) + 1, ]; - Utils::$context['results'] = array_slice(Utils::$context['results'], $_REQUEST['start'], 7); + Utils::$context['results'] = \array_slice(Utils::$context['results'], $_REQUEST['start'], 7); } else { Utils::$context['links']['up'] = Config::$scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); } diff --git a/Sources/Actions/Groups.php b/Sources/Actions/Groups.php index 6f0b9ddb32..27da02c0e5 100644 --- a/Sources/Actions/Groups.php +++ b/Sources/Actions/Groups.php @@ -124,7 +124,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -244,7 +244,7 @@ public function members(): void $_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0; // No browsing of guests, membergroup 0 or moderators. - if (in_array($_REQUEST['group'], [-1, 0, 3])) { + if (\in_array($_REQUEST['group'], [-1, 0, 3])) { ErrorHandler::fatalLang('membergroup_does_not_exist', false); } @@ -280,7 +280,7 @@ public function members(): void } // Removing member from group? - if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $group->assignable) { + if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && \is_array($_REQUEST['rem']) && $group->assignable) { User::$me->checkSession(); SecurityToken::validate('mod-mgm'); @@ -304,7 +304,7 @@ public function members(): void foreach ($member_names as $index => $member_name) { $member_names[$index] = trim(Utils::strtolower($member_names[$index])); - if (strlen($member_names[$index]) == 0) { + if (\strlen($member_names[$index]) == 0) { unset($member_names[$index]); } } @@ -802,7 +802,7 @@ public static function listMembergroupMembers_Href(&$members, $membergroup, $lim Db::$db->free_result($request); // If there are more than $limit members, add a 'more' link. - if ($limit !== null && count($members) > $limit) { + if ($limit !== null && \count($members) > $limit) { array_pop($members); return true; diff --git a/Sources/Actions/Help.php b/Sources/Actions/Help.php index f8a590119b..a9e229a327 100644 --- a/Sources/Actions/Help.php +++ b/Sources/Actions/Help.php @@ -69,7 +69,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } diff --git a/Sources/Actions/HelpAdmin.php b/Sources/Actions/HelpAdmin.php index ef9af93316..febb35507c 100644 --- a/Sources/Actions/HelpAdmin.php +++ b/Sources/Actions/HelpAdmin.php @@ -49,7 +49,7 @@ class HelpAdmin implements ActionInterface */ public function execute(): void { - if (!isset($_GET['help']) || !is_string($_GET['help'])) { + if (!isset($_GET['help']) || !\is_string($_GET['help'])) { ErrorHandler::fatalLang('no_access', false); } diff --git a/Sources/Actions/JavaScriptModify.php b/Sources/Actions/JavaScriptModify.php index ea3a78021b..7dfa69afc8 100644 --- a/Sources/Actions/JavaScriptModify.php +++ b/Sources/Actions/JavaScriptModify.php @@ -315,8 +315,8 @@ public function execute(): void Utils::$context['message'] = [ 'id' => $row['id_msg'], 'errors' => [], - 'error_in_subject' => in_array('no_subject', $post_errors), - 'error_in_body' => in_array('no_message', $post_errors) || in_array('long_message', $post_errors) || in_array('links_malformed', $post_errors), + 'error_in_subject' => \in_array('no_subject', $post_errors), + 'error_in_body' => \in_array('no_message', $post_errors) || \in_array('long_message', $post_errors) || \in_array('links_malformed', $post_errors), ]; Lang::load('Errors'); diff --git a/Sources/Actions/Like.php b/Sources/Actions/Like.php index cba745aa8d..3fd310606c 100644 --- a/Sources/Actions/Like.php +++ b/Sources/Actions/Like.php @@ -203,7 +203,7 @@ public function execute(): void // Make sure the user can see and like your content. $this->check(); - if (is_string($this->error)) { + if (\is_string($this->error)) { $this->respond(); return; @@ -222,9 +222,9 @@ public function execute(): void // Call the appropriate method. if (method_exists($this, self::$subactions[$this->subaction])) { - call_user_func([$this, self::$subactions[$this->subaction]]); + \call_user_func([$this, self::$subactions[$this->subaction]]); } else { - call_user_func(self::$subactions[$this->subaction]); + \call_user_func(self::$subactions[$this->subaction]); } } @@ -394,7 +394,7 @@ protected function check(): void // Is the user able to like this? // Viewing a list of likes doesn't require this permission. - if ($this->subaction != 'view' && isset($this->valid_likes['can_like']) && is_string($this->valid_likes['can_like'])) { + if ($this->subaction != 'view' && isset($this->valid_likes['can_like']) && \is_string($this->valid_likes['can_like'])) { $this->error = $this->valid_likes['can_like']; return; @@ -601,7 +601,7 @@ protected function like(): void $call = Utils::getCallable($this->valid_likes['callback']); if (!empty($call)) { - call_user_func_array($call, [$this]); + \call_user_func_array($call, [$this]); } } @@ -663,7 +663,7 @@ protected function view(): void $members = array_keys(Utils::$context['likers']); $loaded = User::load($members); - if (count($loaded) != count($members)) { + if (\count($loaded) != \count($members)) { $members = array_diff($members, array_map(fn ($member) => $member->id, $loaded)); foreach ($members as $not_loaded) { @@ -682,7 +682,7 @@ protected function view(): void Utils::$context['likers'][$liker]['time'] = !empty($dummy['timestamp']) ? Time::create('@' . $dummy['timestamp'])->format() : ''; } - Utils::$context['page_title'] = strip_tags(Lang::getTxt('likes_count', ['num' => count(Utils::$context['likers'])])); + Utils::$context['page_title'] = strip_tags(Lang::getTxt('likes_count', ['num' => \count(Utils::$context['likers'])])); // Lastly, setting up for display. Theme::loadTemplate('Likes'); @@ -748,7 +748,7 @@ protected function respond(): void // These fine gentlemen all share the same template. $generic = ['delete', 'insert', 'count']; - if (in_array($this->subaction, $generic)) { + if (\in_array($this->subaction, $generic)) { Utils::$context['sub_template'] = 'generic'; Utils::$context['data'] = Lang::$txt['like_' . $this->data] ?? $this->data; } diff --git a/Sources/Actions/Login2.php b/Sources/Actions/Login2.php index 9d372f8cdd..8984a33d05 100644 --- a/Sources/Actions/Login2.php +++ b/Sources/Actions/Login2.php @@ -93,7 +93,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -256,7 +256,7 @@ public function main(): void } // Are we using any sort of integration to validate the login? - if (in_array('retry', IntegrationHook::call('integrate_validate_login', [$_POST['user'], $_POST['passwrd'] ?? null, Config::$modSettings['cookieTime']]), true)) { + if (\in_array('retry', IntegrationHook::call('integrate_validate_login', [$_POST['user'], $_POST['passwrd'] ?? null, Config::$modSettings['cookieTime']]), true)) { Utils::$context['login_errors'] = [Lang::$txt['incorrect_password']]; return; @@ -297,7 +297,7 @@ public function main(): void } // Correct password, but they've got no salt. Fix it! - if (strlen(User::$profiles[User::$my_id]['password_salt']) < 32) { + if (\strlen(User::$profiles[User::$my_id]['password_salt']) < 32) { User::$profiles[User::$my_id]['password_salt'] = bin2hex(random_bytes(16)); User::updateMemberData(User::$profiles[User::$my_id]['id_member'], ['password_salt' => User::$profiles[User::$my_id]['password_salt']]); @@ -493,7 +493,7 @@ protected function checkPasswordFallbacks(): bool $other_passwords = []; // SMF 1.1 and 2.0 password styles. - if (strlen(User::$profiles[User::$my_id]['passwd']) == 40) { + if (\strlen(User::$profiles[User::$my_id]['passwd']) == 40) { // Maybe they are using a hash from before the password fix. // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 $other_passwords[] = sha1(strtolower(User::$profiles[User::$my_id]['member_name']) . Utils::htmlspecialcharsDecode($_POST['passwrd'])); @@ -501,12 +501,12 @@ protected function checkPasswordFallbacks(): bool // Perhaps we converted to UTF-8 and have a valid password being hashed differently. if (Utils::$context['character_set'] == 'UTF-8' && !empty(Config::$modSettings['previousCharacterSet']) && Config::$modSettings['previousCharacterSet'] != 'utf8') { // Try iconv first, for no particular reason. - if (function_exists('iconv')) { + if (\function_exists('iconv')) { $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', Config::$modSettings['previousCharacterSet'], User::$profiles[User::$my_id]['member_name'])) . Utils::htmlspecialcharsDecode(iconv('UTF-8', Config::$modSettings['previousCharacterSet'], $_POST['passwrd']))); } // Say it aint so, iconv failed! - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { + if (empty($other_passwords['iconv']) && \function_exists('mb_convert_encoding')) { $other_passwords[] = sha1(strtolower(mb_convert_encoding(User::$profiles[User::$my_id]['member_name'], 'UTF-8', Config::$modSettings['previousCharacterSet'])) . Utils::htmlspecialcharsDecode(mb_convert_encoding($_POST['passwrd'], 'UTF-8', Config::$modSettings['previousCharacterSet']))); } } @@ -515,7 +515,7 @@ protected function checkPasswordFallbacks(): bool // None of the below cases will be used most of the time (because the salt is normally set.) if (!empty(Config::$modSettings['enable_password_conversion']) && User::$profiles[User::$my_id]['password_salt'] == '') { // YaBB SE, Discus, MD5 (used a lot), SHA-1 (used some), SMF 1.0.x, IkonBoard, and none at all. - switch (strlen(User::$profiles[User::$my_id]['passwd'])) { + switch (\strlen(User::$profiles[User::$my_id]['passwd'])) { case 13: $other_passwords[] = crypt($_POST['passwrd'], substr($_POST['passwrd'], 0, 2)); $other_passwords[] = crypt($_POST['passwrd'], substr(User::$profiles[User::$my_id]['passwd'], 0, 2)); @@ -554,7 +554,7 @@ protected function checkPasswordFallbacks(): bool } // If the salt is set let's try some other options elseif (!empty(Config::$modSettings['enable_password_conversion']) && User::$profiles[User::$my_id]['password_salt'] != '') { - switch (strlen(User::$profiles[User::$my_id]['passwd'])) { + switch (\strlen(User::$profiles[User::$my_id]['passwd'])) { case 32: // MyBB $other_passwords[] = md5(md5(User::$profiles[User::$my_id]['password_salt']) . md5($_POST['passwrd'])); @@ -588,7 +588,7 @@ protected function checkPasswordFallbacks(): bool IntegrationHook::call('integrate_other_passwords', [&$other_passwords]); // Whichever encryption it was using, let's make it use SMF's now ;). - if (in_array(User::$profiles[User::$my_id]['passwd'], $other_passwords)) { + if (\in_array(User::$profiles[User::$my_id]['passwd'], $other_passwords)) { User::$profiles[User::$my_id]['passwd'] = Security::hashPassword(User::$profiles[User::$my_id]['member_name'], Utils::htmlspecialcharsDecode($_POST['passwrd'])); User::$profiles[User::$my_id]['password_salt'] = bin2hex(random_bytes(16)); @@ -626,7 +626,7 @@ protected function checkPasswordFallbacks(): bool protected function phpBB3_password_check(string $passwd, string $passwd_hash): ?string { // Too long or too short? - if (strlen($passwd_hash) != 34) { + if (\strlen($passwd_hash) != 34) { return null; } @@ -648,11 +648,11 @@ protected function phpBB3_password_check(string $passwd, string $passwd_hash): ? $i = 0; while ($i < 16) { - $value = ord($hash[$i++]); + $value = \ord($hash[$i++]); $output .= $range[$value & 0x3f]; if ($i < 16) { - $value |= ord($hash[$i]) << 8; + $value |= \ord($hash[$i]) << 8; } $output .= $range[($value >> 6) & 0x3f]; @@ -662,7 +662,7 @@ protected function phpBB3_password_check(string $passwd, string $passwd_hash): ? } if ($i < 16) { - $value |= ord($hash[$i]) << 16; + $value |= \ord($hash[$i]) << 16; } $output .= $range[($value >> 12) & 0x3f]; diff --git a/Sources/Actions/LoginTFA.php b/Sources/Actions/LoginTFA.php index 3f8d2de0b3..c84def9487 100644 --- a/Sources/Actions/LoginTFA.php +++ b/Sources/Actions/LoginTFA.php @@ -66,7 +66,7 @@ public function execute(): void $code = $_POST['tfa_code']; - if (strlen($code) == $totp->getCodeLength() && $totp->validateCode($code)) { + if (\strlen($code) == $totp->getCodeLength() && $totp->validateCode($code)) { User::updateMemberData($member['id_member'], ['last_login' => time()]); Cookie::setTFACookie(3153600, $member['id_member'], Cookie::encrypt($member['tfa_backup'], $member['password_salt'])); diff --git a/Sources/Actions/Memberlist.php b/Sources/Actions/Memberlist.php index eedfc03377..8ab67de6db 100644 --- a/Sources/Actions/Memberlist.php +++ b/Sources/Actions/Memberlist.php @@ -215,7 +215,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -320,7 +320,7 @@ public function all(): void Utils::$context['letter_links'] = ''; for ($i = 97; $i < 123; $i++) { - Utils::$context['letter_links'] .= '' . strtoupper(chr($i)) . ' '; + Utils::$context['letter_links'] .= '' . strtoupper(\chr($i)) . ' '; } // Sort out the column information. @@ -526,7 +526,7 @@ public function search(): void ]; // Search for a name - if (in_array('name', $_POST['fields'])) { + if (\in_array('name', $_POST['fields'])) { $fields = User::$me->allowedTo('moderate_forum') ? ['member_name', 'real_name'] : ['real_name']; $search_fields[] = 'name'; } else { @@ -535,19 +535,19 @@ public function search(): void } // Search for websites. - if (in_array('website', $_POST['fields'])) { + if (\in_array('website', $_POST['fields'])) { $fields += [7 => 'website_title', 'website_url']; $search_fields[] = 'website'; } // Search for groups. - if (in_array('group', $_POST['fields'])) { + if (\in_array('group', $_POST['fields'])) { $fields += [9 => 'COALESCE(group_name, {string:blank_string})']; $search_fields[] = 'group'; } // Search for an email address? - if (in_array('email', $_POST['fields']) && User::$me->allowedTo('moderate_forum')) { + if (\in_array('email', $_POST['fields']) && User::$me->allowedTo('moderate_forum')) { $fields += [2 => 'email_address']; $search_fields[] = 'email'; } diff --git a/Sources/Actions/MessageIndex.php b/Sources/Actions/MessageIndex.php index 3736ea9f92..44b661f5b9 100644 --- a/Sources/Actions/MessageIndex.php +++ b/Sources/Actions/MessageIndex.php @@ -816,7 +816,7 @@ protected function getWhoViewing(): void $link = '' . $row['real_name'] . ''; } - $is_buddy = in_array($row['id_member'], User::$me->buddies); + $is_buddy = \in_array($row['id_member'], User::$me->buddies); if ($is_buddy) { $link = '' . $link . ''; @@ -842,7 +842,7 @@ protected function getWhoViewing(): void Utils::$context['view_num_hidden']++; } } - Utils::$context['view_num_guests'] = Db::$db->num_rows($request) - count(Utils::$context['view_members']); + Utils::$context['view_num_guests'] = Db::$db->num_rows($request) - \count(Utils::$context['view_members']); Db::$db->free_result($request); // Put them in "last clicked" order. @@ -876,7 +876,7 @@ protected function setModerators(): void // Now we tack the info onto the end of the linktree if (!empty(Utils::$context['link_moderators'])) { - Utils::$context['linktree'][count(Utils::$context['linktree']) - 1]['extra_after'] = '(' . (count(Utils::$context['link_moderators']) == 1 ? Lang::$txt['moderator'] : Lang::$txt['moderators']) . ': ' . implode(', ', Utils::$context['link_moderators']) . ')'; + Utils::$context['linktree'][\count(Utils::$context['linktree']) - 1]['extra_after'] = '(' . (\count(Utils::$context['link_moderators']) == 1 ? Lang::$txt['moderator'] : Lang::$txt['moderators']) . ': ' . implode(', ', Utils::$context['link_moderators']) . ')'; } } @@ -950,11 +950,11 @@ protected function setupTemplate(): void protected function setRobotNoIndex(): void { // Right, let's only index normal stuff! - if (count($_GET) > 1) { + if (\count($_GET) > 1) { $session_name = session_name(); foreach ($_GET as $k => $v) { - if (!in_array($k, ['board', 'start', $session_name])) { + if (!\in_array($k, ['board', 'start', $session_name])) { Utils::$context['robot_no_index'] = true; } } @@ -990,7 +990,7 @@ protected function buildQuickMod(): void $boards_allowed = User::$me->boardsAllowedTo('post_new'); // How many boards can you do this on besides this one? - Utils::$context['can_move_any'] = count($boards_allowed) > 1; + Utils::$context['can_move_any'] = \count($boards_allowed) > 1; } // Set permissions for all the topics. diff --git a/Sources/Actions/Moderation/Home.php b/Sources/Actions/Moderation/Home.php index 1a89bff88f..2646afe7a7 100644 --- a/Sources/Actions/Moderation/Home.php +++ b/Sources/Actions/Moderation/Home.php @@ -110,12 +110,12 @@ public function execute(): void } if (method_exists($this, $block['func'])) { - call_user_func([$this, $block['func']]); + \call_user_func([$this, $block['func']]); } else { $call = Utils::getCallable($block['func']); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -539,7 +539,7 @@ protected static function integrateModBlocks(): void foreach ($valid_blocks as $k => $func) { $func = 'ModBlock' . $func; - if (is_callable($func)) { + if (\is_callable($func)) { Utils::$context['mod_blocks'][] = $func(); } } diff --git a/Sources/Actions/Moderation/Logs.php b/Sources/Actions/Moderation/Logs.php index 5905edbcdf..f87958f94a 100644 --- a/Sources/Actions/Moderation/Logs.php +++ b/Sources/Actions/Moderation/Logs.php @@ -224,7 +224,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -360,7 +360,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st $row['extra'] = Utils::jsonDecode($row['extra'], true); // Corrupt? - $row['extra'] = is_array($row['extra']) ? $row['extra'] : []; + $row['extra'] = \is_array($row['extra']) ? $row['extra'] : []; // Add on some of the column stuff info if (!empty($row['id_board'])) { @@ -469,7 +469,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st LIMIT {int:limit}', [ 'board_list' => array_keys($boards), - 'limit' => count(array_keys($boards)), + 'limit' => \count(array_keys($boards)), ], ); @@ -498,7 +498,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st LIMIT {int:limit}', [ 'topic_list' => array_keys($topics), - 'limit' => count(array_keys($topics)), + 'limit' => \count(array_keys($topics)), ], ); @@ -534,7 +534,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st LIMIT {int:limit}', [ 'message_list' => array_keys($messages), - 'limit' => count(array_keys($messages)), + 'limit' => \count(array_keys($messages)), ], ); @@ -568,7 +568,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st LIMIT {int:limit}', [ 'member_list' => array_keys($members), - 'limit' => count(array_keys($members)), + 'limit' => \count(array_keys($members)), ], ); @@ -597,7 +597,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st // Mark up any deleted members, topics and boards. foreach (['board', 'board_from', 'board_to', 'member', 'topic', 'new_topic'] as $type) { - if (in_array($type, ['topic', 'new_topic']) && !empty($entry['extra']['subject'])) { + if (\in_array($type, ['topic', 'new_topic']) && !empty($entry['extra']['subject'])) { $entries[$k]['extra'][$type] = $entry['extra']['subject']; } elseif (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) { $entries[$k]['extra'][$type] = Lang::getTxt('modlog_id', [$entry['extra'][$type]]); @@ -635,7 +635,7 @@ public static function list_getModLogEntries(int $start, int $items_per_page, st */ protected function __construct() { - if (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], self::$actions)) { + if (!empty($_REQUEST['action']) && \in_array($_REQUEST['action'], self::$actions)) { $this->action = $_REQUEST['action']; } diff --git a/Sources/Actions/Moderation/Main.php b/Sources/Actions/Moderation/Main.php index 1cdb9df7fb..7e7d89b82b 100644 --- a/Sources/Actions/Moderation/Main.php +++ b/Sources/Actions/Moderation/Main.php @@ -230,7 +230,7 @@ public function execute(): void $call = method_exists($this, Menu::$loaded['moderate']->include_data['function']) ? [$this, Menu::$loaded['moderate']->include_data['function']] : Utils::getCallable(Menu::$loaded['moderate']->include_data['function']); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -381,11 +381,11 @@ protected function setModerationAreas(): void array_walk_recursive( $this->moderation_areas, function (&$value, $key) { - if (in_array($key, ['title', 'label'])) { + if (\in_array($key, ['title', 'label'])) { $value = Lang::$txt[$value] ?? $value; } - if (is_string($value)) { + if (\is_string($value)) { $value = strtr($value, [ '{scripturl}' => Config::$scripturl, '{boardurl}' => Config::$boardurl, diff --git a/Sources/Actions/Moderation/Posts.php b/Sources/Actions/Moderation/Posts.php index d953a98a41..0216df6135 100644 --- a/Sources/Actions/Moderation/Posts.php +++ b/Sources/Actions/Moderation/Posts.php @@ -86,7 +86,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -198,7 +198,7 @@ public function posts(): void $can_add = false; // If we're approving this is simple. - if ($curAction == 'approve' && ($any_array == [0] || in_array($row['id_board'], $any_array))) { + if ($curAction == 'approve' && ($any_array == [0] || \in_array($row['id_board'], $any_array))) { $can_add = true; } // Delete requires more permission checks... @@ -208,7 +208,7 @@ public function posts(): void $row['id_member'] == User::$me->id && ( $delete_own_boards == [0] - || in_array($row['id_board'], $delete_own_boards) + || \in_array($row['id_board'], $delete_own_boards) ) ) { $can_add = true; @@ -219,7 +219,7 @@ public function posts(): void && $row['id_msg'] != $row['id_first_msg'] && ( $delete_own_replies == [0] - || in_array($row['id_board'], $delete_own_replies) + || \in_array($row['id_board'], $delete_own_replies) ) ) { $can_add = true; @@ -229,7 +229,7 @@ public function posts(): void $row['id_member'] != User::$me->id && ( $delete_any_boards == [0] - || in_array($row['id_board'], $delete_any_boards) + || \in_array($row['id_board'], $delete_any_boards) ) ) { $can_add = true; @@ -350,7 +350,7 @@ public function posts(): void $row['id_member'] == User::$me->id && ( $delete_own_boards == [0] - || in_array($row['id_board'], $delete_own_boards) + || \in_array($row['id_board'], $delete_own_boards) ) ) { $can_delete = true; @@ -361,7 +361,7 @@ public function posts(): void && $row['id_msg'] != $row['id_first_msg'] && ( $delete_own_replies == [0] - || in_array($row['id_board'], $delete_own_replies) + || \in_array($row['id_board'], $delete_own_replies) ) ) { $can_delete = true; @@ -371,7 +371,7 @@ public function posts(): void $row['id_member'] != User::$me->id && ( $delete_any_boards == [0] - || in_array($row['id_board'], $delete_any_boards) + || \in_array($row['id_board'], $delete_any_boards) ) ) { $can_delete = true; diff --git a/Sources/Actions/Moderation/ReportedContent.php b/Sources/Actions/Moderation/ReportedContent.php index 4fd1b89af0..480b3319bf 100644 --- a/Sources/Actions/Moderation/ReportedContent.php +++ b/Sources/Actions/Moderation/ReportedContent.php @@ -122,7 +122,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -281,7 +281,7 @@ public function details(): void // Parameters are slightly different depending on what we're doing here... if ($this->type == 'members') { // Find their ID in the serialized action string... - $user_id_length = strlen((string) Utils::$context['report']['user']['id']); + $user_id_length = \strlen((string) Utils::$context['report']['user']['id']); $member = 's:6:"member";s:' . $user_id_length . ':"' . Utils::$context['report']['user']['id'] . '";}'; $params = [ @@ -625,7 +625,7 @@ protected function __construct() // area=reported{type} $this->type = substr($_GET['area'], 8); - if (!in_array($this->type, self::$types)) { + if (!\in_array($this->type, self::$types)) { ErrorHandler::fatalLang('no_access', false); } @@ -694,7 +694,7 @@ protected function updateReport(string $action, int $value, int|array $report_id '', 'UPDATE {db_prefix}log_reported SET {raw:action} = {string:value} - ' . (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') . ' + ' . (\is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') . ' ' . $board_query, [ 'action' => $action, @@ -762,7 +762,7 @@ protected function updateReport(string $action, int $value, int|array $report_id } // See if any report alerts need to be cleaned up upon close/ignore - if (in_array($log_report, ['close', 'ignore', 'close_user', 'ignore_user'])) { + if (\in_array($log_report, ['close', 'ignore', 'close_user', 'ignore_user'])) { $this->clearReportAlerts($log_report, $extra); } @@ -1342,7 +1342,7 @@ protected function buildQuickButtons(): void 'javascript' => 'data-confirm="' . Lang::$txt['mc_reportedp_delete_confirm'] . '"', 'class' => 'you_sure', 'icon' => 'delete', - 'show' => !$report['closed'] && (is_array($this->remove_any_boards) && in_array($report['topic']['id_board'], $this->remove_any_boards)), + 'show' => !$report['closed'] && (\is_array($this->remove_any_boards) && \in_array($report['topic']['id_board'], $this->remove_any_boards)), ]; } diff --git a/Sources/Actions/Moderation/Warnings.php b/Sources/Actions/Moderation/Warnings.php index 8d443e0786..8dfc044af2 100644 --- a/Sources/Actions/Moderation/Warnings.php +++ b/Sources/Actions/Moderation/Warnings.php @@ -88,7 +88,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } diff --git a/Sources/Actions/Moderation/WatchedUsers.php b/Sources/Actions/Moderation/WatchedUsers.php index 434e870b21..9cfb182fb8 100644 --- a/Sources/Actions/Moderation/WatchedUsers.php +++ b/Sources/Actions/Moderation/WatchedUsers.php @@ -47,11 +47,11 @@ public function execute(): void { // First off - are we deleting? if (!empty($_REQUEST['delete'])) { - User::$me->checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post'); + User::$me->checkSession(!\is_array($_REQUEST['delete']) ? 'get' : 'post'); $toDelete = []; - if (!is_array($_REQUEST['delete'])) { + if (!\is_array($_REQUEST['delete'])) { $toDelete[] = (int) $_REQUEST['delete']; } else { foreach ($_REQUEST['delete'] as $did) { @@ -435,7 +435,7 @@ public static function list_getWatchedUserPosts(int $start, int $items_per_page, 'body' => BBCodeParser::load()->parse($row['body'], (bool) $row['smileys_enabled'], (int) $row['id_msg']), 'poster_time' => Time::create('@' . $row['poster_time'])->format(), 'approved' => $row['approved'], - 'can_delete' => $delete_boards == [0] || in_array($row['id_board'], $delete_boards), + 'can_delete' => $delete_boards == [0] || \in_array($row['id_board'], $delete_boards), ]; } Db::$db->free_result($request); diff --git a/Sources/Actions/Notify.php b/Sources/Actions/Notify.php index 527b8eb10a..6d127aa17c 100644 --- a/Sources/Actions/Notify.php +++ b/Sources/Actions/Notify.php @@ -164,7 +164,7 @@ public static function getNotifyPrefs(int|array $members, string|array $prefs = $members = array_map('intval', (array) $members); if (!empty($prefs)) { - $prefs = is_array($prefs) ? $prefs : (array) $prefs; + $prefs = \is_array($prefs) ? $prefs : (array) $prefs; } $result = []; @@ -212,7 +212,7 @@ public static function getNotifyPrefs(int|array $members, string|array $prefs = */ public static function setNotifyPrefs(int $memID, array $prefs = []): void { - if (empty($prefs) || !is_int($memID)) { + if (empty($prefs) || !\is_int($memID)) { return; } @@ -290,7 +290,7 @@ public static function getMemberWithToken(string $type): array Db::$db->free_result($request); // What token are we expecting? - $expected_token = Notify::createUnsubscribeToken((int) self::$member_info['id'], self::$member_info['email'], $type, in_array($type, ['board', 'topic']) && !empty($$type) ? $$type : 0); + $expected_token = Notify::createUnsubscribeToken((int) self::$member_info['id'], self::$member_info['email'], $type, \in_array($type, ['board', 'topic']) && !empty($$type) ? $$type : 0); // Don't do anything if the token they gave is wrong if ($_REQUEST['token'] !== $expected_token) { diff --git a/Sources/Actions/PersonalMessage.php b/Sources/Actions/PersonalMessage.php index de631c0036..39b1418bec 100644 --- a/Sources/Actions/PersonalMessage.php +++ b/Sources/Actions/PersonalMessage.php @@ -292,7 +292,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -370,7 +370,7 @@ public function applyActions(): void $_REQUEST['pm_action'] = 'delete'; } - if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms'])) { + if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && \is_array($_REQUEST['pms'])) { foreach ($_REQUEST['pms'] as $pm) { $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; } @@ -424,7 +424,7 @@ public function applyActions(): void $action = substr($action, 4); } - if (isset($type) && in_array($type, ['add', 'rem']) && ($action == '-1' || (int) $action > 0)) { + if (isset($type) && \in_array($type, ['add', 'rem']) && ($action == '-1' || (int) $action > 0)) { $to_label[(int) $pm] = (int) $action; $label_type[(int) $pm] = $type; } @@ -449,7 +449,7 @@ public function applyActions(): void // Back to the folder. $_SESSION['pm_selected'] = array_keys($to_label); - Utils::redirectexit($this->current_label_redirect . (count($to_label) == 1 ? '#msg' . $_SESSION['pm_selected'][0] : ''), count($to_label) == 1 && BrowserDetector::isBrowser('ie')); + Utils::redirectexit($this->current_label_redirect . (\count($to_label) == 1 ? '#msg' . $_SESSION['pm_selected'][0] : ''), \count($to_label) == 1 && BrowserDetector::isBrowser('ie')); } /** @@ -543,7 +543,7 @@ public function report(): void Db::$db->free_result($request); // How many admins in total? - Utils::$context['admin_count'] = count(Utils::$context['admins']); + Utils::$context['admin_count'] = \count(Utils::$context['admins']); } // Otherwise, let's get down to the sending stuff. else { @@ -785,11 +785,11 @@ protected function createMenu(string $area): void array_walk_recursive( $this->pm_areas, function (&$value, $key) { - if (in_array($key, ['title', 'label'])) { + if (\in_array($key, ['title', 'label'])) { $value = Lang::$txt[$value] ?? $value; } - if (is_string($value)) { + if (\is_string($value)) { $value = strtr($value, [ '{scripturl}' => Config::$scripturl, '{boardurl}' => Config::$boardurl, diff --git a/Sources/Actions/Post.php b/Sources/Actions/Post.php index bac705621f..30fb288b61 100644 --- a/Sources/Actions/Post.php +++ b/Sources/Actions/Post.php @@ -208,7 +208,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -277,7 +277,7 @@ public function show(): void Utils::$context['move'] = !empty($_REQUEST['move']); Utils::$context['announce'] = !empty($_REQUEST['announce']); Utils::$context['locked'] = !empty($this->locked) || !empty($_REQUEST['lock']); - Utils::$context['can_quote'] = empty(Config::$modSettings['disabledBBC']) || !in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); + Utils::$context['can_quote'] = empty(Config::$modSettings['disabledBBC']) || !\in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); // An array to hold all the attachments for this topic. Utils::$context['current_attachments'] = []; @@ -466,7 +466,7 @@ protected function getTopicSummary(): void 'timestamp' => $row['poster_time'], 'id' => $row['id_msg'], 'is_new' => !empty(Utils::$context['new_replies']), - 'is_ignored' => !empty(Config::$modSettings['enable_buddylist']) && !empty(Theme::$current->options['posts_apply_ignore_list']) && in_array($row['id_member'], User::$me->ignoreusers), + 'is_ignored' => !empty(Config::$modSettings['enable_buddylist']) && !empty(Theme::$current->options['posts_apply_ignore_list']) && \in_array($row['id_member'], User::$me->ignoreusers), ]; if (!empty(Utils::$context['new_replies'])) { @@ -517,7 +517,7 @@ protected function setBoards(): void // Get a list of boards for the select menu $boardListOptions = [ - 'included_boards' => in_array(0, $this->boards) ? null : $this->boards, + 'included_boards' => \in_array(0, $this->boards) ? null : $this->boards, 'not_redirection' => true, 'use_permissions' => true, 'selected_board' => !empty(Board::$info->id) ? Board::$info->id : (Utils::$context['make_event'] && !empty(Config::$modSettings['cal_defaultboard']) ? Config::$modSettings['cal_defaultboard'] : $this->boards[0]), @@ -776,7 +776,7 @@ protected function initiateEvent(): void Utils::$context['event']->selected_occurrence->fixTimezone(); Theme::loadTemplate('EventEditor'); - Theme::addJavaScriptVar('monthly_byday_items', (string) (count(Utils::$context['event']->byday_items) - 1)); + Theme::addJavaScriptVar('monthly_byday_items', (string) (\count(Utils::$context['event']->byday_items) - 1)); Theme::loadJavaScriptFile('event.js', ['defer' => true], 'smf_event'); Utils::$context['event']->board = !empty(Utils::$context['event']->board) ? Utils::$context['event']->board : (Board::$info->id ?? (int) Config::$modSettings['cal_defaultboard']); @@ -920,7 +920,7 @@ protected function showPreview(): void 'is_last' => false, ]; - if (count(Utils::$context['choices']) < 2) { + if (\count(Utils::$context['choices']) < 2) { Utils::$context['choices'][] = [ 'id' => $choice_id++, 'number' => $choice_id, @@ -929,7 +929,7 @@ protected function showPreview(): void ]; } Utils::$context['last_choice_id'] = $choice_id; - Utils::$context['choices'][count(Utils::$context['choices']) - 1]['is_last'] = true; + Utils::$context['choices'][\count(Utils::$context['choices']) - 1]['is_last'] = true; } // Are you... a guest? @@ -1218,7 +1218,7 @@ protected function showNew(): void if (str_contains($this->form_message, '[html]')) { $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $this->form_message, -1, PREG_SPLIT_DELIM_CAPTURE); - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. if ($i % 4 == 0) { $parts[$i] = preg_replace_callback( @@ -1287,7 +1287,7 @@ protected function showAttachments(): void // If this isn't a new post, check the current attachments. if (isset($_REQUEST['msg'])) { - Utils::$context['attachments']['quantity'] = count(Utils::$context['current_attachments']); + Utils::$context['attachments']['quantity'] = \count(Utils::$context['current_attachments']); foreach (Utils::$context['current_attachments'] as $attachment) { Utils::$context['attachments']['total_size'] += $attachment['size']; @@ -1295,7 +1295,7 @@ protected function showAttachments(): void } // A bit of house keeping first. - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { + if (!empty($_SESSION['temp_attachments']) && \count($_SESSION['temp_attachments']) == 1) { unset($_SESSION['temp_attachments']); } @@ -1379,7 +1379,7 @@ protected function showAttachments(): void } if ($attachID == 'initial_error') { - Lang::$txt['error_attach_initial_error'] = Lang::$txt['attach_no_upload'] . '' . (is_array($attachment) ? Lang::getTxt($attachment[0], (array) $attachment[1]) : Lang::$txt[$attachment]) . ''; + Lang::$txt['error_attach_initial_error'] = Lang::$txt['attach_no_upload'] . '' . (\is_array($attachment) ? Lang::getTxt($attachment[0], (array) $attachment[1]) : Lang::$txt[$attachment]) . ''; $this->errors[] = 'attach_initial_error'; @@ -1395,7 +1395,7 @@ protected function showAttachments(): void Lang::$txt['error_attach_errors'] .= Lang::getTxt('attach_warning', $attachment) . ''; foreach ($attachment['errors'] as $error) { - Lang::$txt['error_attach_errors'] .= (is_array($error) ? Lang::getTxt($error[0], (array) $error[1]) : Lang::$txt[$error]) . ''; + Lang::$txt['error_attach_errors'] .= (\is_array($error) ? Lang::getTxt($error[0], (array) $error[1]) : Lang::$txt[$error]) . ''; } Lang::$txt['error_attach_errors'] .= ''; @@ -1589,20 +1589,20 @@ protected function checkForErrors(): void Utils::$context['error_type'] = 'minor'; foreach ($this->errors as $post_error) { - if (is_array($post_error)) { + if (\is_array($post_error)) { $post_error_id = $post_error[0]; Utils::$context['post_error'][$post_error_id] = Lang::getTxt('error_' . $post_error_id, (array) $post_error[1]); // If it's not a minor error flag it as such. - if (!in_array($post_error_id, $this->minor_errors)) { + if (!\in_array($post_error_id, $this->minor_errors)) { Utils::$context['error_type'] = 'serious'; } } else { Utils::$context['post_error'][$post_error] = Lang::$txt['error_' . $post_error]; // If it's not a minor error flag it as such. - if (!in_array($post_error, $this->minor_errors)) { + if (!\in_array($post_error, $this->minor_errors)) { Utils::$context['error_type'] = 'serious'; } } @@ -1700,7 +1700,7 @@ protected function setMessageIcons(): void Utils::$context['icons'] = Editor::getMessageIcons(!empty(Board::$info->id) ? Board::$info->id : 0); if (!empty(Utils::$context['icons'])) { - Utils::$context['icons'][count(Utils::$context['icons']) - 1]['is_last'] = true; + Utils::$context['icons'][\count(Utils::$context['icons']) - 1]['is_last'] = true; } // Are we starting a poll? if set the poll icon as selected if its available @@ -1716,7 +1716,7 @@ protected function setMessageIcons(): void Utils::$context['icon_url'] = ''; - for ($i = 0, $n = count(Utils::$context['icons']); $i < $n; $i++) { + for ($i = 0, $n = \count(Utils::$context['icons']); $i < $n; $i++) { Utils::$context['icons'][$i]['selected'] = Utils::$context['icon'] == Utils::$context['icons'][$i]['value']; if (Utils::$context['icons'][$i]['selected']) { diff --git a/Sources/Actions/Post2.php b/Sources/Actions/Post2.php index e38416c312..a21ff46b29 100644 --- a/Sources/Actions/Post2.php +++ b/Sources/Actions/Post2.php @@ -121,7 +121,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -369,7 +369,7 @@ public function submit(): void // If there was an initial error just show that message. if ($attachID == 'initial_error') { $attach_errors[] = '' . Lang::$txt['attach_no_upload'] . ''; - $attach_errors[] = '' . (is_array($attachment) ? Lang::getTxt($attachment[0], (array) $attachment[1]) : Lang::$txt[$attachment]) . ''; + $attach_errors[] = '' . (\is_array($attachment) ? Lang::getTxt($attachment[0], (array) $attachment[1]) : Lang::$txt[$attachment]) . ''; unset($_SESSION['temp_attachments']); @@ -407,10 +407,10 @@ public function submit(): void $log_these = ['attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file']; foreach ($attachmentOptions['errors'] as $error) { - if (!is_array($error)) { + if (!\is_array($error)) { $attach_errors[] = '' . Lang::$txt[$error] . ''; - if (in_array($error, $log_these)) { + if (\in_array($error, $log_these)) { ErrorHandler::log($attachment['name'] . ': ' . Lang::$txt[$error], 'critical'); } } else { @@ -747,9 +747,9 @@ protected function submitAttachments(): void if ( ( isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) - && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files']) + && \in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files']) ) - || in_array($attachID, $keep_temp) + || \in_array($attachID, $keep_temp) || !str_contains($attachID, 'post_tmp_' . User::$me->id) ) { continue; diff --git a/Sources/Actions/Profile/BuddyIgnoreLists.php b/Sources/Actions/Profile/BuddyIgnoreLists.php index 8c8d263ad1..e320979c02 100644 --- a/Sources/Actions/Profile/BuddyIgnoreLists.php +++ b/Sources/Actions/Profile/BuddyIgnoreLists.php @@ -110,7 +110,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -166,7 +166,7 @@ public function buddies(): void foreach ($new_buddies as $k => $dummy) { $new_buddies[$k] = strtr(trim($new_buddies[$k]), ['\'' => ''']); - if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], [Profile::$member->data['member_name'], Profile::$member->data['real_name']])) { + if (\strlen($new_buddies[$k]) == 0 || \in_array($new_buddies[$k], [Profile::$member->data['member_name'], Profile::$member->data['real_name']])) { unset($new_buddies[$k]); } } @@ -185,7 +185,7 @@ public function buddies(): void LIMIT {int:count_new_buddies}', [ 'new_buddies' => $new_buddies, - 'count_new_buddies' => count($new_buddies), + 'count_new_buddies' => \count($new_buddies), ], ); @@ -193,7 +193,7 @@ public function buddies(): void while ($row = Db::$db->fetch_assoc($request)) { $_SESSION['prf-save'] = true; - if (in_array($row['id_member'], $buddiesArray)) { + if (\in_array($row['id_member'], $buddiesArray)) { continue; } @@ -253,7 +253,7 @@ public function buddies(): void LIMIT {int:buddy_list_count}', [ 'buddy_list' => $buddiesArray, - 'buddy_list_count' => count(explode(',', Profile::$member->data['buddy_list'])), + 'buddy_list_count' => \count(explode(',', Profile::$member->data['buddy_list'])), ], ); @@ -263,7 +263,7 @@ public function buddies(): void Db::$db->free_result($result); } - Utils::$context['buddy_count'] = count($buddies); + Utils::$context['buddy_count'] = \count($buddies); // Load all the members up. User::load($buddies, User::LOAD_BY_ID, 'profile'); @@ -377,7 +377,7 @@ public function ignore(): void foreach ($new_entries as $k => $dummy) { $new_entries[$k] = strtr(trim($new_entries[$k]), ['\'' => ''']); - if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], [Profile::$member->data['member_name'], Profile::$member->data['real_name']])) { + if (\strlen($new_entries[$k]) == 0 || \in_array($new_entries[$k], [Profile::$member->data['member_name'], Profile::$member->data['real_name']])) { unset($new_entries[$k]); } } @@ -394,7 +394,7 @@ public function ignore(): void LIMIT {int:count_new_entries}', [ 'new_entries' => $new_entries, - 'count_new_entries' => count($new_entries), + 'count_new_entries' => \count($new_entries), ], ); @@ -402,7 +402,7 @@ public function ignore(): void while ($row = Db::$db->fetch_assoc($request)) { $_SESSION['prf-save'] = true; - if (in_array($row['id_member'], $ignoreArray)) { + if (\in_array($row['id_member'], $ignoreArray)) { continue; } @@ -432,7 +432,7 @@ public function ignore(): void LIMIT {int:ignore_list_count}', [ 'ignore_list' => $ignoreArray, - 'ignore_list_count' => count(explode(',', Profile::$member->data['pm_ignore_list'])), + 'ignore_list_count' => \count(explode(',', Profile::$member->data['pm_ignore_list'])), ], ); @@ -442,7 +442,7 @@ public function ignore(): void Db::$db->free_result($result); } - Utils::$context['ignore_count'] = count($ignored); + Utils::$context['ignore_count'] = \count($ignored); // Load all the members up. User::load($ignored, User::LOAD_BY_ID, 'profile'); diff --git a/Sources/Actions/Profile/Delete.php b/Sources/Actions/Profile/Delete.php index 6768736437..593ca04c2d 100644 --- a/Sources/Actions/Profile/Delete.php +++ b/Sources/Actions/Profile/Delete.php @@ -92,7 +92,7 @@ public function delete(): void User::$me->checkSession(); // Too often, people remove/delete their own only account. - if (in_array(1, Profile::$member->groups)) { + if (\in_array(1, Profile::$member->groups)) { // Are you allowed to administrate the forum, as they are? User::$me->isAllowedTo('admin_forum'); @@ -161,7 +161,7 @@ public function delete(): void } // Next, delete the posts, if requested. - if (in_array($_POST['remove_type'], ['posts', 'topics'])) { + if (\in_array($_POST['remove_type'], ['posts', 'topics'])) { $extra = empty($_POST['perma_delete']) ? ' AND t.id_board != {int:recycle_board}' : ''; $recycle_board = empty(Config::$modSettings['recycle_board']) ? 0 : Config::$modSettings['recycle_board']; diff --git a/Sources/Actions/Profile/Export.php b/Sources/Actions/Profile/Export.php index 2d4fe3d9a2..efd98fbbdc 100644 --- a/Sources/Actions/Profile/Export.php +++ b/Sources/Actions/Profile/Export.php @@ -204,7 +204,7 @@ public function execute(): void } if (!isset($latest[$datatype])) { - $latest[$datatype] = is_callable($datatype_settings['latest']) ? $datatype_settings['latest'](Utils::$context['id_member']) : $datatype_settings['latest']; + $latest[$datatype] = \is_callable($datatype_settings['latest']) ? $datatype_settings['latest'](Utils::$context['id_member']) : $datatype_settings['latest']; } if ($latest[$datatype] > $progress[$datatype]) { @@ -220,7 +220,7 @@ public function execute(): void $exportbasename = basename($exportfilepath); $part = substr($exportbasename, 0, strcspn($exportbasename, '_')); - $suffix = count($exportfilepaths) == 1 ? '' : '_' . $part; + $suffix = \count($exportfilepaths) == 1 ? '' : '_' . $part; $size = filesize($exportfilepath) / 1024; $units = ['KB', 'MB', 'GB', 'TB']; @@ -278,11 +278,11 @@ public function execute(): void $start[$datatype] = !empty($start[$datatype]) ? $start[$datatype] : 0; if (!isset($latest[$datatype])) { - $latest[$datatype] = is_callable($datatype_settings['latest']) ? $datatype_settings['latest'](Utils::$context['id_member']) : $datatype_settings['latest']; + $latest[$datatype] = \is_callable($datatype_settings['latest']) ? $datatype_settings['latest'](Utils::$context['id_member']) : $datatype_settings['latest']; } if (!isset($total[$datatype])) { - $total[$datatype] = is_callable($datatype_settings['total']) ? $datatype_settings['total'](Utils::$context['id_member']) : $datatype_settings['total']; + $total[$datatype] = \is_callable($datatype_settings['total']) ? $datatype_settings['total'](Utils::$context['id_member']) : $datatype_settings['total']; } } } diff --git a/Sources/Actions/Profile/GroupMembership.php b/Sources/Actions/Profile/GroupMembership.php index 7a5402711b..ca5075a8f9 100644 --- a/Sources/Actions/Profile/GroupMembership.php +++ b/Sources/Actions/Profile/GroupMembership.php @@ -111,7 +111,7 @@ public function show(): void } // Are they in this group? - $member_or_available = in_array($group->id, Profile::$member->groups) ? 'member' : 'available'; + $member_or_available = \in_array($group->id, Profile::$member->groups) ? 'member' : 'available'; // Can't join private or protected groups. if ($group->type < Group::TYPE_REQUESTABLE && $member_or_available == 'available') { @@ -121,7 +121,7 @@ public function show(): void Utils::$context['groups'][$member_or_available][$group->id] = $group; // Do they have a pending request to join this group? - Utils::$context['groups'][$member_or_available][$group->id]->pending = in_array($group->id, $open_requests); + Utils::$context['groups'][$member_or_available][$group->id]->pending = \in_array($group->id, $open_requests); } // If needed, add "Regular Members" on the end. @@ -131,7 +131,7 @@ public function show(): void } // No changing primary group unless you have enough groups! - if (count(Utils::$context['groups']['member']) < 2) { + if (\count(Utils::$context['groups']['member']) < 2) { Utils::$context['can_edit_primary'] = false; } @@ -193,7 +193,7 @@ public function save(): void } // Can't leave a requestable group that you're not part of. - if ($new_group_info['type'] == 2 && !in_array($new_group_id, Profile::$member->groups)) { + if ($new_group_info['type'] == 2 && !\in_array($new_group_id, Profile::$member->groups)) { ErrorHandler::fatalLang('no_access', false); } } @@ -213,7 +213,7 @@ public function save(): void // Are they leaving? if (Profile::$member->group_id == $new_group_id) { $new_primary = $can_edit_primary ? 0 : Profile::$member->group_id; - } elseif (in_array($new_group_id, Profile::$member->additional_groups)) { + } elseif (\in_array($new_group_id, Profile::$member->additional_groups)) { $new_additional_groups = array_diff($new_additional_groups, [$new_group_id]); } // ... if not, must be joining. @@ -237,7 +237,7 @@ public function save(): void $new_additional_groups[] = Profile::$member->group_id; } - if (in_array($new_group_id, $new_additional_groups)) { + if (\in_array($new_group_id, $new_additional_groups)) { $new_additional_groups = array_diff($new_additional_groups, [$new_group_id]); } @@ -319,7 +319,7 @@ protected function loadCurrentAndAssignableGroups(): void } $group->is_primary = $group->id == Profile::$member->group_id; - $group->is_additional = in_array($group->id, Profile::$member->additional_groups); + $group->is_additional = \in_array($group->id, Profile::$member->additional_groups); $current_and_assignable_groups[$group->id] = $group; } diff --git a/Sources/Actions/Profile/IgnoreBoards.php b/Sources/Actions/Profile/IgnoreBoards.php index 531f248dfd..67ce5c4a30 100644 --- a/Sources/Actions/Profile/IgnoreBoards.php +++ b/Sources/Actions/Profile/IgnoreBoards.php @@ -102,7 +102,7 @@ public function execute(): void $temp_boards = array_merge($temp_boards, array_values($category['boards'])); } - $max_boards = max(2, ceil(count($temp_boards) / 2)); + $max_boards = max(2, ceil(\count($temp_boards) / 2)); // Now, alternate them so they can be shown left and right ;). Utils::$context['board_columns'] = []; diff --git a/Sources/Actions/Profile/Main.php b/Sources/Actions/Profile/Main.php index c590f12f2d..3713abb15e 100644 --- a/Sources/Actions/Profile/Main.php +++ b/Sources/Actions/Profile/Main.php @@ -613,7 +613,7 @@ public function execute(): void $password = Utils::htmlspecialcharsDecode($password); // Does the integration want to check passwords? - $good_password = in_array(true, IntegrationHook::call('integrate_verify_password', [Profile::$member->username, $password, false]), true); + $good_password = \in_array(true, IntegrationHook::call('integrate_verify_password', [Profile::$member->username, $password, false]), true); // Bad password!!! if (!$good_password && !Security::hashVerifyPassword(Profile::$member->username, $password, Profile::$member->passwd)) { @@ -621,7 +621,7 @@ public function execute(): void } // Warn other elements not to jump the gun and do custom changes! - if (in_array('bad_password', Profile::$member->save_errors)) { + if (\in_array('bad_password', Profile::$member->save_errors)) { Utils::$context['password_auth_failed'] = true; } } @@ -657,7 +657,7 @@ public function execute(): void $msg = $gm_action->change_type; } - $force_redirect = !in_array($menu->current_area, ['account', 'forumprofile', 'theme']); + $force_redirect = !\in_array($menu->current_area, ['account', 'forumprofile', 'theme']); Profile::$member->save(); } @@ -680,7 +680,7 @@ public function execute(): void // Is it valid? if (!empty($call)) { - call_user_func($call, Profile::$member->id); + \call_user_func($call, Profile::$member->id); } // Set the page title if it's not already set... @@ -764,11 +764,11 @@ protected function setProfileAreas(): void array_walk_recursive( $this->profile_areas, function (&$value, $key) { - if (in_array($key, ['title', 'label'])) { + if (\in_array($key, ['title', 'label'])) { $value = Lang::$txt[$value] ?? $value; } - if (is_string($value)) { + if (\is_string($value)) { $value = strtr($value, [ '{scripturl}' => Config::$scripturl, '{boardurl}' => Config::$boardurl, @@ -791,7 +791,7 @@ function (&$value, $key) { $this->profile_areas['info']['areas']['viewwarning']['enabled'] = Config::$modSettings['warning_settings'][0] == 1 && Profile::$member->warning; - $this->profile_areas['edit_profile']['areas']['account']['enabled'] = User::$me->is_admin || (Profile::$member->group_id != 1 && !in_array(1, Profile::$member->additional_groups)); + $this->profile_areas['edit_profile']['areas']['account']['enabled'] = User::$me->is_admin || (Profile::$member->group_id != 1 && !\in_array(1, Profile::$member->additional_groups)); $this->profile_areas['edit_profile']['areas']['tfasetup']['enabled'] = !empty(Config::$modSettings['tfa_mode']); @@ -809,7 +809,7 @@ function (&$value, $key) { $this->profile_areas['profile_action']['areas']['issuewarning']['enabled'] = Config::$modSettings['warning_settings'][0] == 1; - $this->profile_areas['profile_action']['areas']['banuser']['enabled'] = Profile::$member->group_id != 1 && !in_array(1, Profile::$member->additional_groups); + $this->profile_areas['profile_action']['areas']['banuser']['enabled'] = Profile::$member->group_id != 1 && !\in_array(1, Profile::$member->additional_groups); $this->profile_areas['profile_action']['areas']['subscriptions']['enabled'] = !empty(Config::$modSettings['paid_enabled']) && Utils::$context['subs_available']; @@ -911,7 +911,7 @@ protected function securityChecks(): void $token_name = $area['token'] !== true ? str_replace('%u', (string) Profile::$member->id, $area['token']) : 'profile-u' . Profile::$member->id; - $token_type = isset($area['token_type']) && in_array($area['token_type'], ['request', 'post', 'get']) ? $area['token_type'] : 'post'; + $token_type = isset($area['token_type']) && \in_array($area['token_type'], ['request', 'post', 'get']) ? $area['token_type'] : 'post'; } // Does this require session validating? @@ -959,7 +959,7 @@ protected function securityChecks(): void } // All the subactions that require a user password in order to validate. - $this->check_password = User::$me->is_owner && in_array(Menu::$loaded['profile']->current_area, Utils::$context['password_areas']); + $this->check_password = User::$me->is_owner && \in_array(Menu::$loaded['profile']->current_area, Utils::$context['password_areas']); Utils::$context['require_password'] = $this->check_password; } diff --git a/Sources/Actions/Profile/Notification.php b/Sources/Actions/Profile/Notification.php index 03e3b8492a..b3830e77ca 100644 --- a/Sources/Actions/Profile/Notification.php +++ b/Sources/Actions/Profile/Notification.php @@ -326,7 +326,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -459,7 +459,7 @@ public function configuration(bool $defaultSettings = false): void foreach ($this->alert_types as $group => $items) { foreach ($items as $alert_key => $alert_value) { if (isset($alert_value['permission'])) { - $allowed = count(array_intersect(Profile::$member->groups, $member_groups[$alert_value['permission']['name']]['allowed'])) != 0; + $allowed = \count(array_intersect(Profile::$member->groups, $member_groups[$alert_value['permission']['name']]['allowed'])) != 0; if (!$allowed) { unset($this->alert_types[$group][$alert_key]); diff --git a/Sources/Actions/Profile/PaidSubs.php b/Sources/Actions/Profile/PaidSubs.php index e8921dde2c..741077a4ff 100644 --- a/Sources/Actions/Profile/PaidSubs.php +++ b/Sources/Actions/Profile/PaidSubs.php @@ -173,7 +173,7 @@ public function execute(): void } // If this is confirmation then it's simpler... - if (isset($_GET['confirm'], $_POST['sub_id']) && is_array($_POST['sub_id'])) { + if (isset($_GET['confirm'], $_POST['sub_id']) && \is_array($_POST['sub_id'])) { // Hopefully just one. foreach ($_POST['sub_id'] as $k => $v) { $id_sub = (int) $k; @@ -253,7 +253,7 @@ public function execute(): void } // Don't get silly. - if (count($current_pending) > 9) { + if (\count($current_pending) > 9) { $current_pending = []; } @@ -266,7 +266,7 @@ public function execute(): void } } - if (!in_array($new_data, $current_pending)) { + if (!\in_array($new_data, $current_pending)) { $current_pending[] = $new_data; Db::$db->query( diff --git a/Sources/Actions/Profile/ShowPermissions.php b/Sources/Actions/Profile/ShowPermissions.php index dff3964923..eff0809bbe 100644 --- a/Sources/Actions/Profile/ShowPermissions.php +++ b/Sources/Actions/Profile/ShowPermissions.php @@ -80,7 +80,7 @@ public function execute(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (!$row['is_mod'] && !Profile::$member->can_manage_boards && count(array_intersect(Profile::$member->groups, explode(',', $row['member_groups']))) === 0) { + if (!$row['is_mod'] && !Profile::$member->can_manage_boards && \count(array_intersect(Profile::$member->groups, explode(',', $row['member_groups']))) === 0) { Utils::$context['no_access_boards'][] = [ 'id' => $row['id_board'], 'name' => $row['name'], @@ -101,7 +101,7 @@ public function execute(): void Board::sort(Utils::$context['boards']); if (!empty(Utils::$context['no_access_boards'])) { - Utils::$context['no_access_boards'][count(Utils::$context['no_access_boards']) - 1]['is_last'] = true; + Utils::$context['no_access_boards'][\count(Utils::$context['no_access_boards']) - 1]['is_last'] = true; } Profile::$member->formatted['permissions'] = [ @@ -140,7 +140,7 @@ public function execute(): void } // Permissions that end with _own or _any consist of two parts. - if (in_array(substr($row['permission'], -4), ['_own', '_any']) && isset(Lang::$txt['permissionname_' . substr($row['permission'], 0, -4)])) { + if (\in_array(substr($row['permission'], -4), ['_own', '_any']) && isset(Lang::$txt['permissionname_' . substr($row['permission'], 0, -4)])) { $name = Lang::$txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . Lang::$txt['permissionname_' . $row['permission']]; } else { $name = Lang::$txt['permissionname_' . $row['permission']]; @@ -204,7 +204,7 @@ public function execute(): void // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. if ( - in_array(substr($row['permission'], -4), ['_own', '_any']) + \in_array(substr($row['permission'], -4), ['_own', '_any']) && isset(Lang::$txt['permissionname_' . substr($row['permission'], 0, -4)]) ) { $name = Lang::$txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . Lang::$txt['permissionname_' . $row['permission']]; diff --git a/Sources/Actions/Profile/ShowPosts.php b/Sources/Actions/Profile/ShowPosts.php index 1c9ca033fe..86376f953a 100644 --- a/Sources/Actions/Profile/ShowPosts.php +++ b/Sources/Actions/Profile/ShowPosts.php @@ -117,7 +117,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -397,7 +397,7 @@ public static function list_getUnwatched(int $start, int $items_per_page, string 'SELECT lt.id_topic FROM {db_prefix}log_topics as lt LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) - LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, ['mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC']) ? ' + LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (\in_array($sort, ['mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC']) ? ' LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . ' WHERE lt.id_member = {int:current_member} AND unwatched = 1 @@ -494,7 +494,7 @@ public static function list_getAttachments(int $start, int $items_per_page, stri WHERE a.attachment_type = {int:attachment_type} AND a.id_msg != {int:no_message} AND m.id_member = {int:current_member}' . (!empty(Board::$info->id) ? ' - AND b.id_board = {int:board}' : '') . (!in_array(0, $boards_allowed) ? ' + AND b.id_board = {int:board}' : '') . (!\in_array(0, $boards_allowed) ? ' AND b.id_board IN ({array_int:boards_list})' : '') . (!Config::$modSettings['postmod_active'] || User::$me->allowedTo('approve_posts') || User::$me->is_owner ? '' : ' AND a.approved = {int:is_approved}') . ' ORDER BY {raw:sort} @@ -551,7 +551,7 @@ public static function list_getNumAttachments(array $boards_allowed): int WHERE a.attachment_type = {int:attachment_type} AND a.id_msg != {int:no_message} AND m.id_member = {int:current_member}' . (!empty(Board::$info->id) ? ' - AND b.id_board = {int:board}' : '') . (!in_array(0, $boards_allowed) ? ' + AND b.id_board = {int:board}' : '') . (!\in_array(0, $boards_allowed) ? ' AND b.id_board IN ({array_int:boards_list})' : '') . (!Config::$modSettings['postmod_active'] || User::$me->is_owner || User::$me->allowedTo('approve_posts') ? '' : ' AND m.approved = {int:is_approved} AND t.approved = {int:is_approved}'), @@ -942,7 +942,7 @@ protected function loadPosts(bool $is_topics = false): void } // Clean up after posts that cannot be deleted and quoted. - $quote_enabled = empty(Config::$modSettings['disabledBBC']) || !in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); + $quote_enabled = empty(Config::$modSettings['disabledBBC']) || !\in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); foreach (Utils::$context['posts'] as $counter => $dummy) { Utils::$context['posts'][$counter]['can_delete'] &= Utils::$context['posts'][$counter]['delete_possible']; diff --git a/Sources/Actions/Profile/Summary.php b/Sources/Actions/Profile/Summary.php index 2487f9121f..9cbc7c3dfe 100644 --- a/Sources/Actions/Profile/Summary.php +++ b/Sources/Actions/Profile/Summary.php @@ -172,7 +172,7 @@ public function execute(): void } // Check their email as well... - if (strlen(Profile::$member->formatted['email']) != 0) { + if (\strlen(Profile::$member->formatted['email']) != 0) { $ban_query[] = '({string:email} LIKE bi.email_address)'; $ban_query_vars['email'] = Profile::$member->formatted['email']; } diff --git a/Sources/Actions/Profile/TFASetup.php b/Sources/Actions/Profile/TFASetup.php index e42823e1b0..41a3d15631 100644 --- a/Sources/Actions/Profile/TFASetup.php +++ b/Sources/Actions/Profile/TFASetup.php @@ -108,7 +108,7 @@ protected function validateAndSave(): void $code = $_POST['tfa_code']; $this->totp = new Tfa($_SESSION['tfa_secret']); $this->totp->setRange(1); - $valid_code = strlen($code) == $this->totp->getCodeLength() && $this->totp->validateCode($code); + $valid_code = \strlen($code) == $this->totp->getCodeLength() && $this->totp->validateCode($code); if (empty(Utils::$context['password_auth_failed']) && $valid_code) { $backup = bin2hex(random_bytes(8)); diff --git a/Sources/Actions/Profile/Tracking.php b/Sources/Actions/Profile/Tracking.php index f043699e8a..40b7116cf2 100644 --- a/Sources/Actions/Profile/Tracking.php +++ b/Sources/Actions/Profile/Tracking.php @@ -128,7 +128,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } diff --git a/Sources/Actions/QuickModeration.php b/Sources/Actions/QuickModeration.php index 7082197b1b..6bc537296a 100644 --- a/Sources/Actions/QuickModeration.php +++ b/Sources/Actions/QuickModeration.php @@ -308,7 +308,7 @@ protected function setPossibleActions(): void foreach (self::$action_permissions as $action => $permissions) { // Skip permissions for actions that weren't requested. // Exception: always check the approval permission. - if (!in_array($action, $_REQUEST['actions']) && $action !== 'approve') { + if (!\in_array($action, $_REQUEST['actions']) && $action !== 'approve') { continue; } @@ -374,7 +374,7 @@ protected function setTopicActions(): void $temp = []; foreach ($_REQUEST['actions'] as $topic => $action) { - if (in_array($action, $this->possible_actions)) { + if (\in_array($action, $this->possible_actions)) { $temp[(int) $topic] = $action; } } @@ -390,7 +390,7 @@ protected function setTopicActions(): void LIMIT {int:limit}', [ 'action_topic_ids' => array_keys($_REQUEST['actions']), - 'limit' => count($_REQUEST['actions']), + 'limit' => \count($_REQUEST['actions']), ], ); @@ -468,7 +468,7 @@ protected function setTopicActions(): void } Db::$db->free_result($request); - if (in_array($this->topic_actions['move']['to'][$topic], $redirect_boards)) { + if (\in_array($this->topic_actions['move']['to'][$topic], $redirect_boards)) { break; } @@ -557,7 +557,7 @@ protected function doSticky(): void LIMIT {int:limit}', [ 'sticky_topic_ids' => $this->topic_actions['sticky'], - 'limit' => count($this->topic_actions['sticky']), + 'limit' => \count($this->topic_actions['sticky']), ], ); @@ -602,7 +602,7 @@ protected function doLock(): void [ 'current_member' => User::$me->id, 'locked_topic_ids' => $this->topic_actions['lock'], - 'limit' => count($locked_topic_ids), + 'limit' => \count($locked_topic_ids), ], ); @@ -625,7 +625,7 @@ protected function doLock(): void LIMIT {int:limit}', [ 'locked_topic_ids' => $this->topic_actions['lock'], - 'limit' => count($this->topic_actions['lock']), + 'limit' => \count($this->topic_actions['lock']), ], ); @@ -691,7 +691,7 @@ protected function doMove(): void [ 'current_member' => User::$me->id, 'move_topic_ids' => $this->topic_actions['move']['topics'], - 'limit' => count($this->topic_actions['move']['topics']), + 'limit' => \count($this->topic_actions['move']['topics']), ], ); @@ -825,7 +825,7 @@ protected function doRemove(): void [ 'current_member' => User::$me->id, 'removed_topic_ids' => $this->topic_actions['remove'], - 'limit' => count($this->topic_actions['remove']), + 'limit' => \count($this->topic_actions['remove']), ], ); @@ -877,7 +877,7 @@ protected function doApprove(): void [ 'approve_topic_ids' => $this->topic_actions['approve'], 'not_approved' => 0, - 'limit' => count($this->topic_actions['approve']), + 'limit' => \count($this->topic_actions['approve']), ], ); @@ -910,7 +910,7 @@ protected function doApprove(): void protected function doMerge(): void { // Merge requires at least two topics. - if (count($this->topic_actions['merge']) < 2) { + if (\count($this->topic_actions['merge']) < 2) { return; } diff --git a/Sources/Actions/QuickModerationInTopic.php b/Sources/Actions/QuickModerationInTopic.php index 6faec44338..cf524d859c 100644 --- a/Sources/Actions/QuickModerationInTopic.php +++ b/Sources/Actions/QuickModerationInTopic.php @@ -160,7 +160,7 @@ protected function delete(): void 'current_member' => User::$me->id, 'current_topic' => Topic::$topic_id, 'message_list' => $this->messages, - 'limit' => count($this->messages), + 'limit' => \count($this->messages), ], ); $message_info = []; diff --git a/Sources/Actions/Recent.php b/Sources/Actions/Recent.php index ab7cecc967..1cff2d8773 100644 --- a/Sources/Actions/Recent.php +++ b/Sources/Actions/Recent.php @@ -300,7 +300,7 @@ protected function getBoards(): void LIMIT {int:limit}', [ 'board_list' => $_REQUEST['boards'], - 'limit' => count($_REQUEST['boards']), + 'limit' => \count($_REQUEST['boards']), 'empty' => '', ], ); @@ -394,7 +394,7 @@ protected function getBoards(): void */ protected function getCatName(): void { - if (!empty($_REQUEST['c']) && is_array($_REQUEST['c']) && count($_REQUEST['c']) == 1) { + if (!empty($_REQUEST['c']) && \is_array($_REQUEST['c']) && \count($_REQUEST['c']) == 1) { $request = Db::$db->query( '', 'SELECT name @@ -490,7 +490,7 @@ protected function getMessages(): void 'LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)', ], 'order' => ['m.id_msg DESC'], - 'limit' => count($this->messages), + 'limit' => \count($this->messages), 'params' => [], ]; @@ -577,7 +577,7 @@ protected function doPermissions(): void } } - $quote_enabled = empty(Config::$modSettings['disabledBBC']) || !in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); + $quote_enabled = empty(Config::$modSettings['disabledBBC']) || !\in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); foreach (Utils::$context['posts'] as $counter => $dummy) { // Some posts - the first posts - can't just be deleted. diff --git a/Sources/Actions/Register.php b/Sources/Actions/Register.php index b0b3e9e41d..03f78e0c79 100644 --- a/Sources/Actions/Register.php +++ b/Sources/Actions/Register.php @@ -79,7 +79,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -253,7 +253,7 @@ public function show(): void $reg_fields = explode(',', Config::$modSettings['registration_fields']); // Website is a little different - if (in_array('website', $reg_fields)) { + if (\in_array('website', $reg_fields)) { unset($reg_fields['website']); if (isset($_POST['website_title'])) { diff --git a/Sources/Actions/Register2.php b/Sources/Actions/Register2.php index 32631cdd71..167714ebc9 100644 --- a/Sources/Actions/Register2.php +++ b/Sources/Actions/Register2.php @@ -174,7 +174,7 @@ function (&$value, $key) { $reg_fields = explode(',', Config::$modSettings['registration_fields']); // Website is a little different - if (in_array('website', $reg_fields)) { + if (\in_array('website', $reg_fields)) { $this->possible_strings = array_merge(['website_url', 'website_title'], $this->possible_strings); // Make sure their website URL is squeaky clean @@ -288,7 +288,7 @@ function (&$value, $key) { $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; } - $reg_options['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : []; + $reg_options['theme_vars'] = isset($_POST['options']) && \is_array($_POST['options']) ? $_POST['options'] : []; // Note when they accepted the agreement and privacy policy if (!empty(Config::$modSettings['requireAgreement'])) { @@ -330,7 +330,7 @@ function (&$value, $key) { $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; // We only care for text fields as the others are valid to be empty. - if (!in_array($row['field_type'], ['check', 'select', 'radio'])) { + if (!\in_array($row['field_type'], ['check', 'select', 'radio'])) { // Is it too long? if ($row['field_length'] && $row['field_length'] < Utils::entityStrlen($value)) { $custom_field_errors[] = ['custom_field_too_long', [$row['field_name'], $row['field_length']]]; @@ -338,7 +338,7 @@ function (&$value, $key) { // Any masks to apply? if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') { - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || \strlen($value) > 255)) { $custom_field_errors[] = ['custom_field_invalid_email', [$row['field_name']]]; } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { $custom_field_errors[] = ['custom_field_not_number', [$row['field_name']]]; @@ -376,7 +376,7 @@ function (&$value, $key) { $member_id = self::registerMember($reg_options, true); // What there actually an error of some kind dear boy? - if (is_array($member_id)) { + if (\is_array($member_id)) { $this->errors = array_merge($this->errors, $member_id); $_REQUEST['step'] = 2; $this->show(); @@ -480,7 +480,7 @@ public static function registerMember(array &$reg_options, bool $return_errors = $reg_options['username'] = Utils::htmlspecialchars($reg_options['username']); // @todo Separate the sprintf? - if (empty($reg_options['email']) || !filter_var($reg_options['email'], FILTER_VALIDATE_EMAIL) || strlen($reg_options['email']) > 255) { + if (empty($reg_options['email']) || !filter_var($reg_options['email'], FILTER_VALIDATE_EMAIL) || \strlen($reg_options['email']) > 255) { $reg_errors[] = ['lang', 'profile_error_bad_email']; } @@ -605,7 +605,7 @@ public static function registerMember(array &$reg_options, bool $return_errors = ]; // Can't change reserved vars. - if (isset($reg_options['theme_vars']) && count(array_intersect(array_keys($reg_options['theme_vars']), $reserved_vars)) != 0) { + if (isset($reg_options['theme_vars']) && \count(array_intersect(array_keys($reg_options['theme_vars']), $reserved_vars)) != 0) { ErrorHandler::fatalLang('no_theme'); } @@ -638,7 +638,7 @@ public static function registerMember(array &$reg_options, bool $return_errors = 'additional_groups' => '', 'ignore_boards' => '', 'smiley_set' => '', - 'timezone' => empty(Config::$modSettings['default_timezone']) || !array_key_exists(Config::$modSettings['default_timezone'], TimeZone::list()) ? 'UTC' : Config::$modSettings['default_timezone'], + 'timezone' => empty(Config::$modSettings['default_timezone']) || !\array_key_exists(Config::$modSettings['default_timezone'], TimeZone::list()) ? 'UTC' : Config::$modSettings['default_timezone'], ]; // Setup the activation status on this new account so it is correct - firstly is it an under age account? @@ -663,14 +663,14 @@ public static function registerMember(array &$reg_options, bool $return_errors = // Check if this group is assignable. if (isset($reg_options['memberGroup'])) { - $reg_options['register_vars']['id_group'] = in_array($reg_options['memberGroup'], Group::getUnassignable()) ? Group::REGULAR : $reg_options['memberGroup']; + $reg_options['register_vars']['id_group'] = \in_array($reg_options['memberGroup'], Group::getUnassignable()) ? Group::REGULAR : $reg_options['memberGroup']; } // Verify that timezone is correct, if provided. if ( !empty($reg_options['extra_register_vars']) && !empty($reg_options['extra_register_vars']['timezone']) - && !array_key_exists($reg_options['extra_register_vars']['timezone'], TimeZone::list()) + && !\array_key_exists($reg_options['extra_register_vars']['timezone'], TimeZone::list()) ) { unset($reg_options['extra_register_vars']['timezone']); } @@ -715,11 +715,11 @@ public static function registerMember(array &$reg_options, bool $return_errors = foreach ($reg_options['register_vars'] as $var => $val) { $type = 'string'; - if (in_array($var, $known_ints)) { + if (\in_array($var, $known_ints)) { $type = 'int'; - } elseif (in_array($var, $known_floats)) { + } elseif (\in_array($var, $known_floats)) { $type = 'float'; - } elseif (in_array($var, $known_inets)) { + } elseif (\in_array($var, $known_inets)) { $type = 'inet'; } elseif ($var == 'birthdate') { $type = 'date'; diff --git a/Sources/Actions/Reminder.php b/Sources/Actions/Reminder.php index aff865feb2..f11bf667db 100644 --- a/Sources/Actions/Reminder.php +++ b/Sources/Actions/Reminder.php @@ -87,7 +87,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -110,7 +110,7 @@ public function pickType(): ?string // Make sure we are not being slammed // Don't call this if you're coming from the "Choose a reminder type" page - otherwise you'll likely get an error - if (!in_array($_POST['reminder_type'] ?? null, ['email', 'secret'])) { + if (!\in_array($_POST['reminder_type'] ?? null, ['email', 'secret'])) { Security::spamProtection('remind'); } @@ -346,7 +346,7 @@ public function secretAnswer2(): void } // You can't use a blank one! - if (strlen(trim($_POST['passwrd1'])) === 0) { + if (\strlen(trim($_POST['passwrd1'])) === 0) { ErrorHandler::fatalLang('no_password', false); } @@ -415,7 +415,7 @@ protected function loadMember(): void $err_msg = 'username_no_exist'; // Coming with a known ID? - $uid = intval(!empty($_REQUEST['uid']) ? $_REQUEST['uid'] : (!empty($_POST['u']) ? $_POST['u'] : 0)); + $uid = \intval(!empty($_REQUEST['uid']) ? $_REQUEST['uid'] : (!empty($_POST['u']) ? $_POST['u'] : 0)); // If given a name or email, clean it up like we do during registration. if (isset($_POST['user'])) { diff --git a/Sources/Actions/ReportToMod.php b/Sources/Actions/ReportToMod.php index befd19ded9..88c33a2862 100644 --- a/Sources/Actions/ReportToMod.php +++ b/Sources/Actions/ReportToMod.php @@ -124,7 +124,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } diff --git a/Sources/Actions/RequestMembers.php b/Sources/Actions/RequestMembers.php index 74612b2e0e..cace4b4c97 100644 --- a/Sources/Actions/RequestMembers.php +++ b/Sources/Actions/RequestMembers.php @@ -55,7 +55,7 @@ public function execute(): void { User::$me->checkSession('get'); - if (Utils::$context['utf8'] || function_exists('mb_convert_encoding')) { + if (Utils::$context['utf8'] || \function_exists('mb_convert_encoding')) { header('content-type: text/plain; charset=UTF-8'); } diff --git a/Sources/Actions/Search.php b/Sources/Actions/Search.php index c1fcdc242a..d42593e37a 100644 --- a/Sources/Actions/Search.php +++ b/Sources/Actions/Search.php @@ -200,11 +200,11 @@ public function execute(): void // If user selected some particular boards, is this one of them? if (!empty(Utils::$context['search_params']['brd'])) { - Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] = in_array($row['id_board'], Utils::$context['search_params']['brd']); + Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] = \in_array($row['id_board'], Utils::$context['search_params']['brd']); } // User didn't select any boards, so select all except ignored and recycle boards. else { - Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] = !$is_recycle_board && !in_array($row['id_board'], User::$me->ignoreboards); + Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] = !$is_recycle_board && !\in_array($row['id_board'], User::$me->ignoreboards); } // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! @@ -230,7 +230,7 @@ public function execute(): void Utils::$context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']); } - $max_boards = ceil(count($temp_boards) / 2); + $max_boards = ceil(\count($temp_boards) / 2); if ($max_boards == 1) { $max_boards = 2; diff --git a/Sources/Actions/Search2.php b/Sources/Actions/Search2.php index 89ee076840..23c5395ef8 100644 --- a/Sources/Actions/Search2.php +++ b/Sources/Actions/Search2.php @@ -162,10 +162,10 @@ public function prepareSearchContext(bool $reset = false): bool|array $started = $output['first_post']['member']['id'] == User::$me->id; $output['quick_mod'] = [ - 'lock' => in_array(0, SearchResult::$boards_can['lock_any']) || in_array($output['board']['id'], SearchResult::$boards_can['lock_any']) || ($started && (in_array(0, SearchResult::$boards_can['lock_own']) || in_array($output['board']['id'], SearchResult::$boards_can['lock_own']))), - 'sticky' => (in_array(0, SearchResult::$boards_can['make_sticky']) || in_array($output['board']['id'], SearchResult::$boards_can['make_sticky'])), - 'move' => in_array(0, SearchResult::$boards_can['move_any']) || in_array($output['board']['id'], SearchResult::$boards_can['move_any']) || ($started && (in_array(0, SearchResult::$boards_can['move_own']) || in_array($output['board']['id'], SearchResult::$boards_can['move_own']))), - 'remove' => in_array(0, SearchResult::$boards_can['remove_any']) || in_array($output['board']['id'], SearchResult::$boards_can['remove_any']) || ($started && (in_array(0, SearchResult::$boards_can['remove_own']) || in_array($output['board']['id'], SearchResult::$boards_can['remove_own']))), + 'lock' => \in_array(0, SearchResult::$boards_can['lock_any']) || \in_array($output['board']['id'], SearchResult::$boards_can['lock_any']) || ($started && (\in_array(0, SearchResult::$boards_can['lock_own']) || \in_array($output['board']['id'], SearchResult::$boards_can['lock_own']))), + 'sticky' => (\in_array(0, SearchResult::$boards_can['make_sticky']) || \in_array($output['board']['id'], SearchResult::$boards_can['make_sticky'])), + 'move' => \in_array(0, SearchResult::$boards_can['move_any']) || \in_array($output['board']['id'], SearchResult::$boards_can['move_any']) || ($started && (\in_array(0, SearchResult::$boards_can['move_own']) || \in_array($output['board']['id'], SearchResult::$boards_can['move_own']))), + 'remove' => \in_array(0, SearchResult::$boards_can['remove_any']) || \in_array($output['board']['id'], SearchResult::$boards_can['remove_any']) || ($started && (\in_array(0, SearchResult::$boards_can['remove_own']) || \in_array($output['board']['id'], SearchResult::$boards_can['remove_own']))), 'restore' => Utils::$context['can_restore_perm'] && (Config::$modSettings['recycle_board'] == $output['board']['id']), ]; @@ -173,7 +173,7 @@ public function prepareSearchContext(bool $reset = false): bool|array Utils::$context['can_sticky'] |= $output['quick_mod']['sticky']; Utils::$context['can_move'] |= $output['quick_mod']['move']; Utils::$context['can_remove'] |= $output['quick_mod']['remove']; - Utils::$context['can_merge'] |= in_array($output['board']['id'], SearchResult::$boards_can['merge_any']); + Utils::$context['can_merge'] |= \in_array($output['board']['id'], SearchResult::$boards_can['merge_any']); Utils::$context['can_restore'] |= $output['quick_mod']['restore']; Utils::$context['can_markread'] = User::$me->is_logged; @@ -428,7 +428,7 @@ protected function getPosters(): void [ 'message_list' => $this->messages, 'no_member' => 0, - 'limit' => count(SearchApi::$loadedApi->results), + 'limit' => \count(SearchApi::$loadedApi->results), ], ); diff --git a/Sources/Actions/SmStats.php b/Sources/Actions/SmStats.php index 721e32d831..b0b3ae2623 100644 --- a/Sources/Actions/SmStats.php +++ b/Sources/Actions/SmStats.php @@ -103,7 +103,7 @@ public function execute(): void } if ($fp) { - $length = strlen($stats_to_send); + $length = \strlen($stats_to_send); $out = 'POST /smf/stats/collect_stats.php HTTP/1.1' . "\r\n"; $out .= 'Host: www.simplemachines.org' . "\r\n"; diff --git a/Sources/Actions/Stats.php b/Sources/Actions/Stats.php index 11a5d13b2c..4efb71b241 100644 --- a/Sources/Actions/Stats.php +++ b/Sources/Actions/Stats.php @@ -188,7 +188,7 @@ public function execute(): void // Let's calculate gender stats only every four minutes. $disabled_fields = isset(Config::$modSettings['disabled_profile_fields']) ? explode(',', Config::$modSettings['disabled_profile_fields']) : []; - if (!in_array('gender', $disabled_fields)) { + if (!\in_array('gender', $disabled_fields)) { if ((Utils::$context['gender'] = CacheApi::get('stats_gender', 240)) == null) { $result = Db::$db->query( '', @@ -564,7 +564,7 @@ public function execute(): void while ($row_members = Db::$db->fetch_assoc($members_result)) { $temp2[] = (int) $row_members['id_member']; - if (count(Utils::$context['stats_blocks']['time_online']) >= 10) { + if (\count(Utils::$context['stats_blocks']['time_online']) >= 10) { continue; } @@ -711,7 +711,7 @@ public function execute(): void while ($row_months = Db::$db->fetch_assoc($months_result)) { $ID_MONTH = $row_months['stats_year'] . sprintf('%02d', $row_months['stats_month']); - $expanded = !empty($_SESSION['expanded_stats'][$row_months['stats_year']]) && in_array($row_months['stats_month'], $_SESSION['expanded_stats'][$row_months['stats_year']]); + $expanded = !empty($_SESSION['expanded_stats'][$row_months['stats_year']]) && \in_array($row_months['stats_month'], $_SESSION['expanded_stats'][$row_months['stats_year']]); if (!isset(Utils::$context['yearly'][$row_months['stats_year']])) { Utils::$context['yearly'][$row_months['stats_year']] = [ diff --git a/Sources/Actions/TopicMerge.php b/Sources/Actions/TopicMerge.php index f6d32ba6fb..d2975d2365 100644 --- a/Sources/Actions/TopicMerge.php +++ b/Sources/Actions/TopicMerge.php @@ -189,7 +189,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -216,7 +216,7 @@ public function index(): void // Prepare a handy query bit for approval... if (Config::$modSettings['postmod_active']) { $can_approve_boards = User::$me->boardsAllowedTo('approve_posts'); - $onlyApproved = $can_approve_boards !== [0] && !in_array($_REQUEST['targetboard'], $can_approve_boards); + $onlyApproved = $can_approve_boards !== [0] && !\in_array($_REQUEST['targetboard'], $can_approve_boards); } else { $onlyApproved = false; } @@ -276,7 +276,7 @@ public function index(): void } // No sense in loading this if you can only merge on this board - if (count($this->merge_boards) > 1 || in_array(0, $this->merge_boards)) { + if (\count($this->merge_boards) > 1 || \in_array(0, $this->merge_boards)) { // Set up a couple of options for our board list $options = [ 'not_redirection' => true, @@ -284,7 +284,7 @@ public function index(): void ]; // Only include these boards in the list (0 means you're an admin') - if (!in_array(0, $this->merge_boards)) { + if (!\in_array(0, $this->merge_boards)) { $options['included_boards'] = $this->merge_boards; } @@ -334,7 +334,7 @@ public function index(): void } Db::$db->free_result($request); - if (empty(Utils::$context['topics']) && count($this->merge_boards) <= 1 && !in_array(0, $this->merge_boards)) { + if (empty(Utils::$context['topics']) && \count($this->merge_boards) <= 1 && !\in_array(0, $this->merge_boards)) { ErrorHandler::fatalLang('merge_need_more_topics'); } @@ -353,7 +353,7 @@ public function options(): void { $this->initOptionsAndMerge(); - if (count($this->polls) > 1) { + if (\count($this->polls) > 1) { $request = Db::$db->query( '', 'SELECT t.id_topic, t.id_poll, m.subject, p.question @@ -364,7 +364,7 @@ public function options(): void LIMIT {int:limit}', [ 'polls' => $this->polls, - 'limit' => count($this->polls), + 'limit' => \count($this->polls), ], ); @@ -382,7 +382,7 @@ public function options(): void Db::$db->free_result($request); } - if (count($this->boards) > 1) { + if (\count($this->boards) > 1) { $request = Db::$db->query( '', 'SELECT id_board, name @@ -392,7 +392,7 @@ public function options(): void LIMIT {int:limit}', [ 'boards' => $this->boards, - 'limit' => count($this->boards), + 'limit' => \count($this->boards), ], ); @@ -430,16 +430,16 @@ public function merge(): void $this->initOptionsAndMerge(); // Determine target board. - $target_board = count($this->boards) > 1 ? (int) $_REQUEST['board'] : $this->boards[0]; + $target_board = \count($this->boards) > 1 ? (int) $_REQUEST['board'] : $this->boards[0]; - if (!in_array($target_board, $this->boards)) { + if (!\in_array($target_board, $this->boards)) { ErrorHandler::fatalLang('no_board'); } // Determine which poll will survive and which polls won't. - $target_poll = count($this->polls) > 1 ? (int) $_POST['poll'] : (count($this->polls) == 1 ? $this->polls[0] : 0); + $target_poll = \count($this->polls) > 1 ? (int) $_POST['poll'] : (\count($this->polls) == 1 ? $this->polls[0] : 0); - if ($target_poll > 0 && !in_array($target_poll, $this->polls)) { + if ($target_poll > 0 && !\in_array($target_poll, $this->polls)) { ErrorHandler::fatalLang('no_access', false); } @@ -769,7 +769,7 @@ public function merge(): void Db::$db->free_result($request); // Merge topic notifications. - $notifications = isset($_POST['notifications']) && is_array($_POST['notifications']) ? array_intersect($this->topics, $_POST['notifications']) : []; + $notifications = isset($_POST['notifications']) && \is_array($_POST['notifications']) ? array_intersect($this->topics, $_POST['notifications']) : []; if (!empty($notifications)) { $request = Db::$db->query( @@ -971,7 +971,7 @@ public function merge(): void /** @var \SMF\Search\SearchApiInterface $searchAPI */ $searchAPI = SearchApi::load(); - if (is_callable([$searchAPI, 'topicMerge'])) { + if (\is_callable([$searchAPI, 'topicMerge'])) { // todo: undefined method $searchAPI->topicMerge($id_topic, $this->topics, $affected_msgs, empty($_POST['enforce_subject']) ? null : [Utils::$context['response_prefix'], $target_subject]); } @@ -1079,7 +1079,7 @@ protected function initOptionsAndMerge(): void $this->getTopics(); // There's nothing to merge with just one topic... - if (empty($this->topics) || !is_array($this->topics) || count($this->topics) == 1) { + if (empty($this->topics) || !\is_array($this->topics) || \count($this->topics) == 1) { ErrorHandler::fatalLang('merge_need_more_topics'); } @@ -1123,7 +1123,7 @@ protected function initOptionsAndMerge(): void protected function getTopics(): void { // Already set. - if (count($this->topics) > 1) { + if (\count($this->topics) > 1) { return; } @@ -1133,7 +1133,7 @@ protected function getTopics(): void } // If we came from a form, the topic IDs came by post. - if (!empty($_REQUEST['topics']) && is_array($_REQUEST['topics'])) { + if (!empty($_REQUEST['topics']) && \is_array($_REQUEST['topics'])) { $this->topics = (array) $_REQUEST['topics']; } } @@ -1159,7 +1159,7 @@ protected function getTopicData(): void LIMIT {int:limit}', [ 'topic_list' => $this->topics, - 'limit' => count($this->topics), + 'limit' => \count($this->topics), ], ); @@ -1184,7 +1184,7 @@ protected function getTopicData(): void } // We can't see unapproved topics here? - if (Config::$modSettings['postmod_active'] && !$row['approved'] && $this->can_approve_boards != [0] && in_array($row['id_board'], $this->can_approve_boards)) { + if (Config::$modSettings['postmod_active'] && !$row['approved'] && $this->can_approve_boards != [0] && \in_array($row['id_board'], $this->can_approve_boards)) { // If we can't see it, we should not merge it and not adjust counts! Instead skip it. unset($this->topics[$row['id_topic']]); @@ -1267,18 +1267,18 @@ protected function getMergeBoards(): void 'SELECT b.id_board FROM {db_prefix}boards AS b WHERE b.id_board IN ({array_int:boards}) - AND {query_see_board}' . (!in_array(0, $this->merge_boards) ? ' + AND {query_see_board}' . (!\in_array(0, $this->merge_boards) ? ' AND b.id_board IN ({array_int:merge_boards})' : '') . ' LIMIT {int:limit}', [ 'boards' => $this->boards, 'merge_boards' => $this->merge_boards, - 'limit' => count($this->boards), + 'limit' => \count($this->boards), ], ); // If the number of boards that's in the output isn't exactly the same as we've put in there, you're in trouble. - if (Db::$db->num_rows($request) != count($this->boards)) { + if (Db::$db->num_rows($request) != \count($this->boards)) { ErrorHandler::fatalLang('no_board'); } diff --git a/Sources/Actions/TopicRestore.php b/Sources/Actions/TopicRestore.php index 541abf2f1e..c83b33bdfa 100644 --- a/Sources/Actions/TopicRestore.php +++ b/Sources/Actions/TopicRestore.php @@ -123,7 +123,7 @@ public function execute(): void // Check for topics we are going to fully restore. foreach ($actioned_messages as $topic => $data) { - if (in_array($topic, $topics_to_restore)) { + if (\in_array($topic, $topics_to_restore)) { unset($actioned_messages[$topic]); } } @@ -156,7 +156,7 @@ public function execute(): void foreach ($actioned_messages as $topic => $data) { // If we have topics we are going to restore the whole lot ignore them. - if (in_array($topic, $topics_to_restore)) { + if (\in_array($topic, $topics_to_restore)) { unset($actioned_messages[$topic]); continue; @@ -274,7 +274,7 @@ protected static function mergePosts(array|int $msgs, int $from_topic, int $targ // !!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient. // Is it an array? - if (!is_array($msgs)) { + if (!\is_array($msgs)) { $msgs = [$msgs]; } diff --git a/Sources/Actions/TopicSplit.php b/Sources/Actions/TopicSplit.php index b3f5bacfe0..3617a2c830 100644 --- a/Sources/Actions/TopicSplit.php +++ b/Sources/Actions/TopicSplit.php @@ -111,7 +111,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -929,7 +929,7 @@ public static function splitTopic(int $split1_ID_TOPIC, array $splitMessages, st /** @var \SMF\Search\SearchApiInterface $searchAPI */ $searchAPI = SearchApi::load(); - if (is_callable([$searchAPI, 'topicSplit'])) { + if (\is_callable([$searchAPI, 'topicSplit'])) { $searchAPI->topicSplit($split2_ID_TOPIC, $splitMessages); } diff --git a/Sources/Actions/TrackIP.php b/Sources/Actions/TrackIP.php index 010c9b9b21..2306b825e1 100644 --- a/Sources/Actions/TrackIP.php +++ b/Sources/Actions/TrackIP.php @@ -91,7 +91,7 @@ public function execute(): void Utils::$context['ip'] = IP::ip2range(trim($_REQUEST['searchip'])); } - if (count(Utils::$context['ip']) !== 2) { + if (\count(Utils::$context['ip']) !== 2) { ErrorHandler::fatalLang('invalid_tracking_ip', false); } diff --git a/Sources/Actions/Unread.php b/Sources/Actions/Unread.php index 311208bd5a..281a772f6c 100644 --- a/Sources/Actions/Unread.php +++ b/Sources/Actions/Unread.php @@ -366,7 +366,7 @@ protected function getBoards(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (in_array($row['id_parent'], $this->boards)) { + if (\in_array($row['id_parent'], $this->boards)) { $this->boards[] = $row['id_board']; } } @@ -477,7 +477,7 @@ protected function getBoards(): void */ protected function getCatName(): void { - if (!empty($_REQUEST['c']) && is_array($_REQUEST['c']) && count($_REQUEST['c']) == 1) { + if (!empty($_REQUEST['c']) && \is_array($_REQUEST['c']) && \count($_REQUEST['c']) == 1) { $request = Db::$db->query( '', 'SELECT name @@ -499,7 +499,7 @@ protected function getCatName(): void protected function setSortMethod(): void { // We only know these. - if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array_keys($this->sort_methods))) { + if (isset($_REQUEST['sort']) && !\in_array($_REQUEST['sort'], array_keys($this->sort_methods))) { $_REQUEST['sort'] = 'last_post'; } @@ -942,7 +942,7 @@ protected function getTopics(): void [ 'current_member' => User::$me->id, 'topic_list' => $topic_ids, - 'limit' => count($topic_ids), + 'limit' => \count($topic_ids), ], ); diff --git a/Sources/Actions/UnreadReplies.php b/Sources/Actions/UnreadReplies.php index e931004044..b3475a1a5c 100644 --- a/Sources/Actions/UnreadReplies.php +++ b/Sources/Actions/UnreadReplies.php @@ -144,7 +144,7 @@ protected function makeTempTable(): void id_msg int(10) unsigned NOT NULL default {string:string_zero}, PRIMARY KEY (id_topic) ) - SELECT t.id_topic, t.id_board, t.id_last_msg, COALESCE(lmr.id_msg, 0) AS id_msg' . (!in_array($_REQUEST['sort'], ['t.id_last_msg', 't.id_topic']) ? ', ' . $_REQUEST['sort'] . ' AS sort_key' : '') . ' + SELECT t.id_topic, t.id_board, t.id_last_msg, COALESCE(lmr.id_msg, 0) AS id_msg' . (!\in_array($_REQUEST['sort'], ['t.id_last_msg', 't.id_topic']) ? ', ' . $_REQUEST['sort'] . ' AS sort_key' : '') . ' FROM {db_prefix}messages AS m INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic) @@ -217,7 +217,7 @@ protected function getTopicRequestWithTempTable(): void ORDER BY {raw:order} LIMIT {int:offset}, {int:limit}', array_merge($this->query_parameters, [ - 'order' => (in_array($_REQUEST['sort'], ['t.id_last_msg', 't.id_topic']) ? $_REQUEST['sort'] : 't.sort_key') . ($this->ascending ? '' : ' DESC'), + 'order' => (\in_array($_REQUEST['sort'], ['t.id_last_msg', 't.id_topic']) ? $_REQUEST['sort'] : 't.sort_key') . ($this->ascending ? '' : ' DESC'), 'offset' => Utils::$context['start'], 'limit' => Utils::$context['topics_per_page'], ]), @@ -255,7 +255,7 @@ protected function getTopicRequestWithTempTable(): void 'current_member' => User::$me->id, 'topic_list' => $topics, 'sort' => $_REQUEST['sort'], - 'limit' => count($topics), + 'limit' => \count($topics), ], ); } @@ -355,7 +355,7 @@ protected function getTopicRequestWithoutTempTable(): void 'current_member' => User::$me->id, 'topic_list' => $topics, 'sort' => $_REQUEST['sort'], - 'limit' => count($topics), + 'limit' => \count($topics), ], ); } diff --git a/Sources/Actions/VerificationCode.php b/Sources/Actions/VerificationCode.php index 524c14aa53..92d7d751ae 100644 --- a/Sources/Actions/VerificationCode.php +++ b/Sources/Actions/VerificationCode.php @@ -80,14 +80,14 @@ public function execute(): void } // If we have GD, try the nice code. elseif (empty($_REQUEST['format'])) { - if (extension_loaded('gd') && !$this->showCodeImage($this->code)) { + if (\extension_loaded('gd') && !$this->showCodeImage($this->code)) { Utils::sendHttpStatus(400); } // Otherwise just show a pre-defined letter. elseif (isset($_REQUEST['letter'])) { $_REQUEST['letter'] = (int) $_REQUEST['letter']; - if ($_REQUEST['letter'] > 0 && $_REQUEST['letter'] <= strlen($this->code) && !$this->showLetterImage(strtolower($this->code[$_REQUEST['letter'] - 1]))) { + if ($_REQUEST['letter'] > 0 && $_REQUEST['letter'] <= \strlen($this->code) && !$this->showLetterImage(strtolower($this->code[$_REQUEST['letter'] - 1]))) { header('content-type: image/gif'); die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); @@ -135,7 +135,7 @@ protected function __construct() */ protected function showCodeImage(string $code): bool { - if (!extension_loaded('gd')) { + if (!\extension_loaded('gd')) { return false; } @@ -240,7 +240,7 @@ protected function showCodeImage(string $code): bool if (!$vary_fonts) { $font_list = [$font_list[0]]; - if (in_array('AnonymousPro.ttf', $ttfont_list)) { + if (\in_array('AnonymousPro.ttf', $ttfont_list)) { $ttfont_list = ['AnonymousPro.ttf']; } else { $ttfont_list = empty($ttfont_list) ? [] : [$ttfont_list[0]]; @@ -251,7 +251,7 @@ protected function showCodeImage(string $code): bool $characters = []; $loaded_fonts = []; - for ($i = 0; $i < strlen($code); $i++) { + for ($i = 0; $i < \strlen($code); $i++) { $characters[$i] = [ 'id' => $code[$i], 'font' => array_rand($font_list), @@ -268,7 +268,7 @@ protected function showCodeImage(string $code): bool // Determine the dimensions of each character. $extra = $image_type == 4 || $image_type == 5 ? 80 : 45; - $total_width = $character_spacing * strlen($code) + $extra; + $total_width = $character_spacing * \strlen($code) + $extra; $max_height = 0; foreach ($characters as $char_index => $character) { @@ -352,7 +352,7 @@ protected function showCodeImage(string $code): bool foreach ($characters as $char_index => $character) { // Can we use true type fonts? - $can_do_ttf = function_exists('imagettftext'); + $can_do_ttf = \function_exists('imagettftext'); // How much rotation will we give? if ($rotation_type == 'none') { @@ -380,7 +380,7 @@ protected function showCodeImage(string $code): bool $new_index = $last_index; while ($last_index == $new_index) { - $new_index = random_int(0, count($colors) - 1); + $new_index = random_int(0, \count($colors) - 1); } $char_fg_color = $colors[$new_index]; @@ -408,13 +408,13 @@ protected function showCodeImage(string $code): bool // What font face? if (!empty($ttfont_list)) { - $fontface = Theme::$current->settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)]; + $fontface = Theme::$current->settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, \count($ttfont_list) - 1)]; } // What color are we to do it in? $is_reverse = $show_reverse_chars ? random_int(0, 1) : false; - if (function_exists('imagecolorallocatealpha') && $font_transparent) { + if (\function_exists('imagecolorallocatealpha') && $font_transparent) { $char_color = imagecolorallocatealpha( $code_image, $char_fg_color[0], @@ -467,7 +467,7 @@ protected function showCodeImage(string $code): bool if (!$can_do_ttf) { // Rotating the characters a little... - if (function_exists('imagerotate')) { + if (\function_exists('imagerotate')) { $char_image = imagecreatetruecolor( $character['width'], $character['height'], @@ -616,7 +616,7 @@ protected function showCodeImage(string $code): bool } // Show the image. - if (function_exists('imagegif')) { + if (\function_exists('imagegif')) { header('content-type: image/gif'); imagegif($code_image); } else { @@ -723,7 +723,7 @@ protected function createWaveFile(string $word): bool // Loop through all letters of the word $word. $sound_word = ''; - for ($i = 0; $i < count($chars); $i++) { + for ($i = 0; $i < \count($chars); $i++) { $sound_letter = implode('', file(Theme::$current->settings['default_theme_dir'] . '/fonts/sound/' . $chars[$i] . '.' . $sound_language . '.wav')); if (!str_contains($sound_letter, 'data')) { @@ -734,15 +734,15 @@ protected function createWaveFile(string $word): bool switch ($chars[$i] === 's' ? 0 : mt_rand(0, 2)) { case 0: - for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { + for ($j = 0, $n = \strlen($sound_letter); $j < $n; $j++) { for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { - $sound_word .= $chars[$i] === 's' ? $sound_letter[$j] : chr(mt_rand(max(ord($sound_letter[$j]) - 1, 0x00), min(ord($sound_letter[$j]) + 1, 0xFF))); + $sound_word .= $chars[$i] === 's' ? $sound_letter[$j] : \chr(mt_rand(max(\ord($sound_letter[$j]) - 1, 0x00), min(\ord($sound_letter[$j]) + 1, 0xFF))); } } break; case 1: - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { + for ($j = 0, $n = \strlen($sound_letter) - 1; $j < $n; $j += 2) { $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter[$j]) . (mt_rand(0, 3) === 0 ? $sound_letter[$j + 1] : $sound_letter[$j]) . (mt_rand(0, 3) === 0 ? $sound_letter[$j] : $sound_letter[$j + 1]) . $sound_letter[$j + 1] . (mt_rand(0, 3) == 0 ? $sound_letter[$j + 1] : ''); } $sound_word .= str_repeat($sound_letter[$n], 2); @@ -751,22 +751,22 @@ protected function createWaveFile(string $word): bool case 2: $shift = 0; - for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { + for ($j = 0, $n = \strlen($sound_letter); $j < $n; $j++) { if (mt_rand(0, 10) === 0) { $shift += mt_rand(-3, 3); } for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { - $sound_word .= chr(min(max(ord($sound_letter[$j]) + $shift, 0x00), 0xFF)); + $sound_word .= \chr(min(max(\ord($sound_letter[$j]) + $shift, 0x00), 0xFF)); } } break; } - $sound_word .= str_repeat(chr(0x80), mt_rand(10000, 10500)); + $sound_word .= str_repeat(\chr(0x80), mt_rand(10000, 10500)); } - $data_size = strlen($sound_word); + $data_size = \strlen($sound_word); $file_size = $data_size + 0x24; $content_length = $file_size + 0x08; $sample_rate = 16000; @@ -787,8 +787,8 @@ protected function createWaveFile(string $word): bool list($a, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); list($range) = explode(',', $range, 2); list($range, $range_end) = explode('-', $range); - $range = intval($range); - $range_end = !$range_end ? $content_length - 1 : intval($range_end); + $range = \intval($range); + $range_end = !$range_end ? $content_length - 1 : \intval($range_end); $new_length = $range_end - $range + 1; Utils::sendHttpStatus(206); diff --git a/Sources/Actions/Who.php b/Sources/Actions/Who.php index f36b38e1d3..7b3b678ac9 100644 --- a/Sources/Actions/Who.php +++ b/Sources/Actions/Who.php @@ -371,7 +371,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref IntegrationHook::call('who_allowed', [&self::$allowedActions]); - if (!is_array($urls)) { + if (!\is_array($urls)) { $url_list = [[$urls, User::$me->id]]; } else { $url_list = $urls; @@ -485,9 +485,9 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref elseif (isset(self::$allowedActions[$actions['action']])) { if (User::$me->allowedTo(self::$allowedActions[$actions['action']]) && !empty(Lang::$txt['whoallow_' . $actions['action']])) { $data[$k] = Lang::getTxt('whoallow_' . $actions['action'], ['scripturl' => Config::$scripturl]); - } elseif (in_array('moderate_forum', self::$allowedActions[$actions['action']])) { + } elseif (\in_array('moderate_forum', self::$allowedActions[$actions['action']])) { $data[$k] = Lang::$txt['who_moderate']; - } elseif (in_array('admin_forum', self::$allowedActions[$actions['action']])) { + } elseif (\in_array('admin_forum', self::$allowedActions[$actions['action']])) { $data[$k] = Lang::$txt['who_admin']; } else { $data[$k] = ['label' => 'who_hidden', 'class' => 'em']; @@ -513,7 +513,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref if (!empty($error_message)) { $error_message = ' '; - if (is_array($data[$k])) { + if (\is_array($data[$k])) { $data[$k]['error_message'] = $error_message; } else { $data[$k] .= $error_message; @@ -522,7 +522,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref } // Maybe the action is integrated into another system? - if (count($integrate_actions = IntegrationHook::call('integrate_whos_online', [$actions])) > 0) { + if (\count($integrate_actions = IntegrationHook::call('integrate_whos_online', [$actions])) > 0) { foreach ($integrate_actions as $integrate_action) { if (!empty($integrate_action)) { $data[$k] = $integrate_action; @@ -558,7 +558,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref [ 'topic_list' => array_keys($topic_ids), 'is_approved' => 1, - 'limit' => count($topic_ids), + 'limit' => \count($topic_ids), ], ); @@ -582,7 +582,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref LIMIT {int:limit}', [ 'board_list' => array_keys($board_ids), - 'limit' => count($board_ids), + 'limit' => \count($board_ids), ], ); @@ -605,7 +605,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref 'SELECT id_member, real_name FROM {db_prefix}members WHERE id_member IN ({array_int:member_list}) - LIMIT ' . count($profile_ids), + LIMIT ' . \count($profile_ids), [ 'member_list' => array_keys($profile_ids), ], @@ -627,7 +627,7 @@ public static function determineActions(mixed $urls, string|bool $preferred_pref IntegrationHook::call('whos_online_after', [&$urls, &$data]); - if (!is_array($urls)) { + if (!\is_array($urls)) { return $data[0] ?? false; } diff --git a/Sources/Actions/XmlHttp.php b/Sources/Actions/XmlHttp.php index f18354edb2..a4b688ec8e 100644 --- a/Sources/Actions/XmlHttp.php +++ b/Sources/Actions/XmlHttp.php @@ -84,7 +84,7 @@ public function execute(): void $call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } @@ -138,11 +138,11 @@ public function previews(): ?bool Utils::$context['sub_template'] = 'generic_xml'; - if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) { + if (!isset($_POST['item']) || !\in_array($_POST['item'], $items)) { return false; } - call_user_func([$this, $_POST['item']]); + \call_user_func([$this, $_POST['item']]); return null; } diff --git a/Sources/Alert.php b/Sources/Alert.php index 217e506c2d..bd2fdc683d 100644 --- a/Sources/Alert.php +++ b/Sources/Alert.php @@ -345,7 +345,7 @@ public function format(bool $with_avatar = false, bool $show_links = false): voi } // Do we want to link to the topic in general or the new messages specifically? - if (in_array($this->content_type, ['topic', 'board']) && in_array($this->content_action, ['reply', 'topic', 'unapproved_reply'])) { + if (\in_array($this->content_type, ['topic', 'board']) && \in_array($this->content_action, ['reply', 'topic', 'unapproved_reply'])) { $this->extra['topic_suffix'] = 'new;topicseen#new'; } elseif (isset($this->extra['topic'])) { $this->extra['topic_suffix'] = '0'; @@ -381,9 +381,9 @@ public function format(bool $with_avatar = false, bool $show_links = false): voi ); // Assuming all required values are present, build the message. - if (!in_array('', $msg_values)) { + if (!\in_array('', $msg_values)) { $this->extra[$msg_type] = vsprintf(self::$link_formats[$msg_type][$this->show_links ? 'link' : 'text'], $msg_values); - } elseif (in_array($msg_type, ['msg_msg', 'topic_msg', 'board_msg'])) { + } elseif (\in_array($msg_type, ['msg_msg', 'topic_msg', 'board_msg'])) { $this->extra[$msg_type] = Lang::$txt[$msg_type == 'board_msg' ? 'board_na' : 'topic_na']; } else { $this->extra[$msg_type] = '(' . Lang::$txt['not_applicable'] . ')'; @@ -412,7 +412,7 @@ public function format(bool $with_avatar = false, bool $show_links = false): voi } // Next, try determining the link based on the content action. - if (empty($this->target_href) && in_array($this->content_action, ['register_approval', 'group_request', 'buddy_request'])) { + if (empty($this->target_href) && \in_array($this->content_action, ['register_approval', 'group_request', 'buddy_request'])) { switch ($this->content_action) { case 'register_approval': $this->target_href = Config::$scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve'; @@ -434,7 +434,7 @@ public function format(bool $with_avatar = false, bool $show_links = false): voi } // Or maybe we can determine the link based on the content type. - if (empty($this->target_href) && in_array($this->content_type, ['msg', 'member', 'event'])) { + if (empty($this->target_href) && \in_array($this->content_type, ['msg', 'member', 'event'])) { switch ($this->content_type) { case 'msg': if (!empty($this->content_id)) { @@ -468,7 +468,7 @@ public function format(bool $with_avatar = false, bool $show_links = false): voi 'member_link' => !empty($this->member_started) && $this->show_links ? '' . $this->member_name . '' : '' . $this->member_name . '', ]; - if (is_array($this->extra)) { + if (\is_array($this->extra)) { foreach ($this->extra as $k => $v) { $substitutions[$k] = $v; } @@ -843,7 +843,7 @@ public static function loadForMember(int $memID, bool|array $to_fetch = false, i } // Are we being asked for some specific alerts? - $ids = is_bool($to_fetch) ? [] : array_filter(array_map('intval', (array) $to_fetch)); + $ids = \is_bool($to_fetch) ? [] : array_filter(array_map('intval', (array) $to_fetch)); // Don't reload unnecessarily. foreach (self::$loaded as $alert) { @@ -1031,7 +1031,7 @@ public static function markAll(int|array $members, bool $read): void if (Db::$db->affected_rows() > 0) { // First, make sure that all the loaded alerts have the right value. foreach (self::$loaded as $alert) { - if (in_array($alert->member, $members) && (!$read || empty($alert->is_read))) { + if (\in_array($alert->member, $members) && (!$read || empty($alert->is_read))) { $alert->is_read = $time; } } diff --git a/Sources/Attachment.php b/Sources/Attachment.php index e07d4d3a06..49f9b7617b 100644 --- a/Sources/Attachment.php +++ b/Sources/Attachment.php @@ -411,7 +411,7 @@ public function setFileProperties(): void $pathinfo = pathinfo($this->path); if (isset($pathinfo['extension'])) { - $this->path = substr($this->path, 0, -(strlen($pathinfo['extension']) + 1)); + $this->path = substr($this->path, 0, -(\strlen($pathinfo['extension']) + 1)); } $this->exists = file_exists($this->path); @@ -434,7 +434,7 @@ public function __set(string $prop, mixed $value): void $this->href = Config::$scripturl . '?action=dlattach;attach=' . $this->id; - if (in_array($this->prop_aliases[$prop] ?? $prop, ['id', 'file_hash', 'folder'])) { + if (\in_array($this->prop_aliases[$prop] ?? $prop, ['id', 'file_hash', 'folder'])) { $this->setPath(); } @@ -472,7 +472,7 @@ public static function load(array|string|int $ids, int $approval_status = self:: $loaded = []; $ids = array_filter(array_map('intval', (array) $ids)); - $approval_status = !in_array($approval_status, [self::APPROVED_TRUE, self::APPROVED_FALSE]) ? self::APPROVED_ANY : $approval_status; + $approval_status = !\in_array($approval_status, [self::APPROVED_TRUE, self::APPROVED_FALSE]) ? self::APPROVED_ANY : $approval_status; if (empty($ids)) { return $loaded; @@ -522,7 +522,7 @@ public static function load(array|string|int $ids, int $approval_status = self:: foreach (self::queryData($selects, $params, $from, $joins, $where, $order, $limit) as $props) { $id = (int) $props['id_attach']; - $props = array_filter($props, fn ($prop) => !is_null($prop)); + $props = array_filter($props, fn ($prop) => !\is_null($prop)); $loaded[$id] = new self($id, $props); } @@ -552,7 +552,7 @@ public static function loadByMsg(array|int $msgs, int $approval_status = self::A $loaded = []; $msgs = array_filter(array_map('intval', (array) $msgs)); - $approval_status = !in_array($approval_status, [self::APPROVED_TRUE, self::APPROVED_FALSE]) ? self::APPROVED_ANY : $approval_status; + $approval_status = !\in_array($approval_status, [self::APPROVED_TRUE, self::APPROVED_FALSE]) ? self::APPROVED_ANY : $approval_status; if (empty($msgs)) { return $loaded; @@ -592,7 +592,7 @@ public static function loadByMsg(array|int $msgs, int $approval_status = self::A foreach (self::queryData($selects, $params, $from, $joins, $where, $order, $limit) as $props) { $id = (int) $props['id_attach']; - $props = array_filter($props, fn ($prop) => !is_null($prop)); + $props = array_filter($props, fn ($prop) => !\is_null($prop)); // Don't reload unnecessarily. if (isset(self::$loaded[$id])) { @@ -622,7 +622,7 @@ public static function loadByMember(array|int $members, int $approval_status = s $loaded = []; $members = array_filter(array_map('intval', (array) $members)); - $approval_status = !in_array($approval_status, [self::APPROVED_TRUE, self::APPROVED_FALSE]) ? self::APPROVED_ANY : $approval_status; + $approval_status = !\in_array($approval_status, [self::APPROVED_TRUE, self::APPROVED_FALSE]) ? self::APPROVED_ANY : $approval_status; if (empty($members)) { return $loaded; @@ -652,7 +652,7 @@ public static function loadByMember(array|int $members, int $approval_status = s foreach (self::queryData($selects, $params, $from, $joins, $where, $order, $limit) as $props) { $id = (int) $props['id_attach']; - $props = array_filter($props, fn ($prop) => !is_null($prop)); + $props = array_filter($props, fn ($prop) => !\is_null($prop)); // Don't reload unnecessarily. if (isset(self::$loaded[$id])) { @@ -703,7 +703,7 @@ public static function automanageCheckDirectory(): ?bool $rand = $rand[0]; if (!empty(Config::$modSettings['attachment_basedirectories']) && !empty(Config::$modSettings['use_subdirectories_for_attachments'])) { - if (!is_array(Config::$modSettings['attachment_basedirectories'])) { + if (!\is_array(Config::$modSettings['attachment_basedirectories'])) { Config::$modSettings['attachment_basedirectories'] = Utils::jsonDecode(Config::$modSettings['attachment_basedirectories'], true); } @@ -717,7 +717,7 @@ public static function automanageCheckDirectory(): ?bool Config::$modSettings['last_attachments_directory'] = []; } - if (!is_array(Config::$modSettings['last_attachments_directory'])) { + if (!\is_array(Config::$modSettings['last_attachments_directory'])) { Config::$modSettings['last_attachments_directory'] = Utils::jsonDecode(Config::$modSettings['last_attachments_directory'], true); } @@ -757,13 +757,13 @@ public static function automanageCheckDirectory(): ?bool $updir = ''; } - if (!is_array(Config::$modSettings['attachmentUploadDir'])) { + if (!\is_array(Config::$modSettings['attachmentUploadDir'])) { Config::$modSettings['attachmentUploadDir'] = Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); } - if (!in_array($updir, Config::$modSettings['attachmentUploadDir']) && !empty($updir)) { + if (!\in_array($updir, Config::$modSettings['attachmentUploadDir']) && !empty($updir)) { $outputCreation = self::automanageCreateDirectory($updir); - } elseif (in_array($updir, Config::$modSettings['attachmentUploadDir'])) { + } elseif (\in_array($updir, Config::$modSettings['attachmentUploadDir'])) { $outputCreation = true; } @@ -789,14 +789,14 @@ public static function automanageCheckDirectory(): ?bool public static function automanageCreateDirectory($updir): bool { $tree = self::getDirectoryTreeElements($updir); - $count = count($tree); + $count = \count($tree); $directory = self::initDir($tree, $count); if ($directory === false) { // Maybe it's just the folder name $tree = self::getDirectoryTreeElements(Config::$boarddir . DIRECTORY_SEPARATOR . $updir); - $count = count($tree); + $count = \count($tree); $directory = self::initDir($tree, $count); @@ -836,7 +836,7 @@ public static function automanageCreateDirectory($updir): bool $updir = rtrim($updir, $sep); // Only update if it's a new directory - if (!in_array($updir, Config::$modSettings['attachmentUploadDir'])) { + if (!\in_array($updir, Config::$modSettings['attachmentUploadDir'])) { Config::$modSettings['currentAttachmentUploadDir'] = max(array_keys(Config::$modSettings['attachmentUploadDir'])) + 1; Config::$modSettings['attachmentUploadDir'][Config::$modSettings['currentAttachmentUploadDir']] = $updir; @@ -916,7 +916,7 @@ public static function process(): void self::automanageCheckDirectory(); } - if (!is_array(Config::$modSettings['attachmentUploadDir'])) { + if (!\is_array(Config::$modSettings['attachmentUploadDir'])) { Config::$modSettings['attachmentUploadDir'] = Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); } @@ -957,7 +957,7 @@ public static function process(): void // Hmm. There are still files in session. $ignore_temp = false; - if (!empty($_SESSION['temp_attachments']['post']['files']) && count($_SESSION['temp_attachments']) > 1) { + if (!empty($_SESSION['temp_attachments']['post']['files']) && \count($_SESSION['temp_attachments']) > 1) { // Let's try to keep them. But... $ignore_temp = true; @@ -1251,7 +1251,7 @@ public static function check(string|int $attachID): bool $allowed[$k] = trim($dummy); } - if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) { + if (!\in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) { $allowed_extensions = strtr(strtolower(Config::$modSettings['attachmentExtensions']), [',' => ', ']); $_SESSION['temp_attachments'][$attachID]['errors'][] = ['cant_upload_type', ['allowed_extensions' => $allowed_extensions]]; } @@ -1301,7 +1301,7 @@ public static function create(array &$attachmentOptions): bool $attachmentOptions['width'] = $image->width; $attachmentOptions['height'] = $image->height; - if (in_array($image->orientation, [5, 6, 7, 8])) { + if (\in_array($image->orientation, [5, 6, 7, 8])) { $attachmentOptions['width'] = $image->height; $attachmentOptions['height'] = $image->width; } @@ -1323,15 +1323,15 @@ public static function create(array &$attachmentOptions): bool // Fix up the supplied file name and extension. $name_info = array_filter(pathinfo($attachmentOptions['name']), 'strlen'); - if (strlen($attachmentOptions['fileext'] ?? '') > 8) { + if (\strlen($attachmentOptions['fileext'] ?? '') > 8) { $attachmentOptions['fileext'] = ''; } - if (strlen($attachmentOptions['fileext'] ?? '') === 0) { - $attachmentOptions['fileext'] = isset($name_info['extension']) && strlen($name_info['extension']) <= 8 ? $name_info['extension'] : ''; + if (\strlen($attachmentOptions['fileext'] ?? '') === 0) { + $attachmentOptions['fileext'] = isset($name_info['extension']) && \strlen($name_info['extension']) <= 8 ? $name_info['extension'] : ''; } - $attachmentOptions['name'] = ($name_info['filename'] ?? bin2hex(random_bytes(4))) . (strlen($attachmentOptions['fileext']) > 0 ? '.' . $attachmentOptions['fileext'] : ''); + $attachmentOptions['name'] = ($name_info['filename'] ?? bin2hex(random_bytes(4))) . (\strlen($attachmentOptions['fileext']) > 0 ? '.' . $attachmentOptions['fileext'] : ''); // Get the hash if no hash has been given yet. if (empty($attachmentOptions['file_hash'])) { @@ -1359,11 +1359,11 @@ public static function create(array &$attachmentOptions): bool IntegrationHook::call('integrate_createAttachment', [&$attachmentOptions, &$attachmentInserts]); // Make sure the folder is valid... - $tmp = is_array(Config::$modSettings['attachmentUploadDir']) ? Config::$modSettings['attachmentUploadDir'] : Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); + $tmp = \is_array(Config::$modSettings['attachmentUploadDir']) ? Config::$modSettings['attachmentUploadDir'] : Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); $folders = array_keys($tmp); - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { + if (empty($attachmentOptions['id_folder']) || !\in_array($attachmentOptions['id_folder'], $folders)) { $attachmentOptions['id_folder'] = Config::$modSettings['currentAttachmentUploadDir']; } @@ -1692,14 +1692,14 @@ public static function remove(array $condition, string $query_type = '', bool $r ]; $do_logging = []; - if (is_array($condition)) { + if (\is_array($condition)) { foreach ($condition as $real_type => $restriction) { // Doing a NOT? $is_not = substr($real_type, 0, 4) == 'not_'; $type = $is_not ? substr($real_type, 4) : $real_type; - if (in_array($type, ['id_member', 'id_attach', 'id_msg'])) { - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; + if (\in_array($type, ['id_member', 'id_attach', 'id_msg'])) { + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (\is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; } elseif ($type == 'attachment_type') { $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; } elseif ($type == 'poster_time') { @@ -1709,7 +1709,7 @@ public static function remove(array $condition, string $query_type = '', bool $r } elseif ($type == 'size') { $new_condition[] = 'a.size > {int:' . $real_type . '}'; } elseif ($type == 'id_topic') { - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; + $new_condition[] = 'm.id_topic IN (' . (\is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; } // Add the parameter! @@ -1865,7 +1865,7 @@ public static function parseAttachBBC(int|string $attachID = 0): array|string $externalParse = IntegrationHook::call('integrate_pre_parseAttachBBC', [$attachID, $msgID]); // "I am innocent of the blood of this just person: see ye to it." - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { + if (!empty($externalParse) && (\is_string($externalParse) || \is_array($externalParse))) { return $externalParse; } @@ -1883,7 +1883,7 @@ public static function parseAttachBBC(int|string $attachID = 0): array|string } // Can the user view attachments on this board? - if ($check_board_perms && !empty(Board::$info->id) && !in_array(Board::$info->id, $view_attachment_boards)) { + if ($check_board_perms && !empty(Board::$info->id) && !\in_array(Board::$info->id, $view_attachment_boards)) { return 'attachments_not_allowed_to_see'; } @@ -1901,7 +1901,7 @@ public static function parseAttachBBC(int|string $attachID = 0): array|string // Can the user view attachments on the board that holds the attachment's original post? // (This matters when one post quotes another on a different board.) - if ($check_board_perms && !in_array($attachInfo['board'], $view_attachment_boards)) { + if ($check_board_perms && !\in_array($attachInfo['board'], $view_attachment_boards)) { return 'attachments_not_allowed_to_see'; } @@ -1916,7 +1916,7 @@ public static function parseAttachBBC(int|string $attachID = 0): array|string // In case the user manually typed the thumbnail's ID into the BBC elseif (!empty(Utils::$context['loaded_attachments'][$attachInfo['msg']])) { foreach (Utils::$context['loaded_attachments'][$attachInfo['msg']] as $foundAttachID => $foundAttach) { - if (array_key_exists('id_thumb', $foundAttach) && $foundAttach['id_thumb'] == $attachID) { + if (\array_key_exists('id_thumb', $foundAttach) && $foundAttach['id_thumb'] == $attachID) { $attachContext = Utils::$context['loaded_attachments'][$attachInfo['msg']][$foundAttachID]; $attachID = $foundAttachID; break; @@ -1950,7 +1950,7 @@ public static function parseAttachBBC(int|string $attachID = 0): array|string $attachContext = $attachLoaded[$attachID]; // It's theoretically possible that prepareByMsg() changed the board id, so check again. - if ($check_board_perms && !in_array($attachContext['board'], $view_attachment_boards)) { + if ($check_board_perms && !\in_array($attachContext['board'], $view_attachment_boards)) { return 'attachments_not_allowed_to_see'; } @@ -2048,7 +2048,7 @@ public static function loadAttachmentContext(int $id_msg, array $attachments): a $attachment['width'] > Config::$modSettings['attachmentThumbWidth'] || $attachment['height'] > Config::$modSettings['attachmentThumbHeight'] ) - && strlen($attachment['filename']) < 249) { + && \strlen($attachment['filename']) < 249) { // A proper thumb doesn't exist yet? Create one! if ( empty($attachment['id_thumb']) @@ -2066,7 +2066,7 @@ public static function loadAttachmentContext(int $id_msg, array $attachments): a if (!empty($image->source) && ($thumb = $image->createThumbnail(Config::$modSettings['attachmentThumbWidth'], Config::$modSettings['attachmentThumbHeight'])) !== false) { // So what folder are we putting this image in? if (!empty(Config::$modSettings['currentAttachmentUploadDir'])) { - if (!is_array(Config::$modSettings['attachmentUploadDir'])) { + if (!\is_array(Config::$modSettings['attachmentUploadDir'])) { Config::$modSettings['attachmentUploadDir'] = Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); } @@ -2282,7 +2282,7 @@ public static function createHash(string $input = ''): string { if (is_file($input)) { $hash = hash_hmac_file('sha1', $input, Config::$image_proxy_secret); - } elseif (strlen($input) > 0) { + } elseif (\strlen($input) > 0) { $hash = hash_hmac('sha1', $input, Config::$image_proxy_secret); } else { $hash = bin2hex(random_bytes(20)); @@ -2350,16 +2350,16 @@ protected function setPath(): void } // Decode the JSON string to an array. - if (!is_array(Config::$modSettings['attachmentUploadDir'])) { + if (!\is_array(Config::$modSettings['attachmentUploadDir'])) { $temp = Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); - if (!is_null($temp)) { + if (!\is_null($temp)) { Config::$modSettings['attachmentUploadDir'] = $temp; } } // Are we using multiple directories? - if (is_array(Config::$modSettings['attachmentUploadDir'])) { + if (\is_array(Config::$modSettings['attachmentUploadDir'])) { if (!isset(Config::$modSettings['attachmentUploadDir'][$this->folder])) { return; } @@ -2386,7 +2386,7 @@ protected function setPath(): void */ protected static function isPathAllowed(string $path): bool { - $open_basedir = ini_get('open_basedir'); + $open_basedir = \ini_get('open_basedir'); if (empty($open_basedir)) { return true; diff --git a/Sources/Autolinker.php b/Sources/Autolinker.php index 0dcfa66f9b..fecf781a8e 100644 --- a/Sources/Autolinker.php +++ b/Sources/Autolinker.php @@ -267,7 +267,7 @@ public function __construct(bool $only_basic = false) } else { $this->encoding = !empty(Config::$modSettings['global_character_set']) ? Config::$modSettings['global_character_set'] : (!empty(Lang::$txt['lang_character_set']) ? Lang::$txt['lang_character_set'] : $this->encoding); - if (in_array($this->encoding, mb_encoding_aliases('UTF-8'))) { + if (\in_array($this->encoding, mb_encoding_aliases('UTF-8'))) { $this->encoding = 'UTF-8'; } } @@ -408,14 +408,14 @@ public function detectUrls(string $string, bool $plaintext_only = false): array // 4 = Closing BBC markup element. '(\[/\2\])' . '~i' . ($this->encoding === 'UTF-8' ? 'u' : ''), - fn ($matches) => $matches[1] . str_repeat('x', strlen($matches[3])) . $matches[4], + fn ($matches) => $matches[1] . str_repeat('x', \strlen($matches[3])) . $matches[4], $string, ); // Overwrite all BBC markup elements. $string = preg_replace_callback( '/\[[^\]]*\]/i' . ($this->encoding === 'UTF-8' ? 'u' : ''), - fn ($matches) => str_repeat(' ', strlen($matches[0])), + fn ($matches) => str_repeat(' ', \strlen($matches[0])), $string, ); @@ -429,14 +429,14 @@ public function detectUrls(string $string, bool $plaintext_only = false): array // 3 = Closing 'a' markup element. '()' . '~i' . ($this->encoding === 'UTF-8' ? 'u' : ''), - fn ($matches) => $matches[1] . str_repeat('x', strlen($matches[2])) . $matches[3], + fn ($matches) => $matches[1] . str_repeat('x', \strlen($matches[2])) . $matches[3], $string, ); // Overwrite all HTML elements. $string = preg_replace_callback( '~?(\w+)\b([^>]*)>~i' . ($this->encoding === 'UTF-8' ? 'u' : ''), - fn ($matches) => str_repeat(' ', strlen($matches[0])), + fn ($matches) => str_repeat(' ', \strlen($matches[0])), $string, ); } @@ -513,7 +513,7 @@ public function makeLinks(string $string, bool $link_emails = true, bool $link_u foreach (self::$no_autolink_tags as $tag) { $parts = preg_split('~(\[/' . $tag . '\]|\[' . $tag . '\b(?:[^\]]*)\])~i', $string, -1, PREG_SPLIT_DELIM_CAPTURE); - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { if ($i % 4 == 2) { $placeholder = md5($parts[$i]); $placeholders[$placeholder] = $parts[$i]; @@ -537,7 +537,7 @@ public function makeLinks(string $string, bool $link_emails = true, bool $link_u foreach ($detected_urls as $pos => $url) { $new_string .= substr($string, $prev_pos + $prev_len, $pos - ($prev_pos + $prev_len)); $prev_pos = $pos; - $prev_len = strlen($url); + $prev_len = \strlen($url); // If this isn't a clean URL, leave it alone. if ($url !== (string) Url::create($url)->sanitize()) { @@ -559,9 +559,9 @@ public function makeLinks(string $string, bool $link_emails = true, bool $link_u } // Is this version of PHP capable of validating this email address? - $can_validate = defined('FILTER_FLAG_EMAIL_UNICODE') || strlen($url->path) == strspn(strtolower($url->path), 'abcdefghijklmnopqrstuvwxyz0123456789!#$%&\'*+-/=?^_`{|}~.@'); + $can_validate = \defined('FILTER_FLAG_EMAIL_UNICODE') || \strlen($url->path) == strspn(strtolower($url->path), 'abcdefghijklmnopqrstuvwxyz0123456789!#$%&\'*+-/=?^_`{|}~.@'); - $flags = defined('FILTER_FLAG_EMAIL_UNICODE') ? FILTER_FLAG_EMAIL_UNICODE : null; + $flags = \defined('FILTER_FLAG_EMAIL_UNICODE') ? FILTER_FLAG_EMAIL_UNICODE : null; if (!$can_validate || filter_var($url->path, FILTER_VALIDATE_EMAIL, $flags) !== false) { $placeholders[md5($url->path)] = $url->path; @@ -586,9 +586,9 @@ public function makeLinks(string $string, bool $link_emails = true, bool $link_u // Make sure that $full_url really is valid if ( - in_array($url->scheme, self::$schemes['forbidden']) + \in_array($url->scheme, self::$schemes['forbidden']) || ( - !in_array($url->scheme, self::$schemes['no_authority']) + !\in_array($url->scheme, self::$schemes['no_authority']) && !$full_url->isValid() ) ) { @@ -619,7 +619,7 @@ public function makeLinks(string $string, bool $link_emails = true, bool $link_u foreach ($detected_emails as $pos => $email) { $new_string .= substr($string, $prev_pos + $prev_len, $pos - ($prev_pos + $prev_len)); $prev_pos = $pos; - $prev_len = strlen($email); + $prev_len = \strlen($email); $new_string .= '[email]' . $email . '[/email]'; } @@ -658,7 +658,7 @@ public function fixUrlsInBBC(string $string): string $parts = preg_split('~(\[/?' . $tags_to_fix_regex . '\b[^\]]*\])~u', $string, -1, PREG_SPLIT_DELIM_CAPTURE); - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { if ($i % 4 == 1) { unset($href, $bbc); @@ -700,7 +700,7 @@ public function fixUrlsInBBC(string $string): string $first_url = reset($detected_urls); // Valid URL. - if (count($detected_urls) === 1 && $parts[$i] === $first_url) { + if (\count($detected_urls) === 1 && $parts[$i] === $first_url) { // BBC param is unnecessary if it is identical to the content. if (!empty($href) && $href === $first_url) { $parts[$i - 1] = '[' . $bbc . ']'; @@ -711,7 +711,7 @@ public function fixUrlsInBBC(string $string): string } // One URL, plus some unexpected cruft... - if (count($detected_urls) === 1) { + if (\count($detected_urls) === 1) { foreach ($detected_urls as $url) { if (!str_starts_with($parts[$i], $url)) { $parts[$i - 1] = substr($parts[$i], 0, strpos($parts[$i], $url)) . $parts[$i - 1]; @@ -719,14 +719,14 @@ public function fixUrlsInBBC(string $string): string } if (!str_ends_with($parts[$i], $url)) { - $parts[$i + 1] .= substr($parts[$i], strlen($url)); - $parts[$i] = substr($parts[$i], 0, strlen($url)); + $parts[$i + 1] .= substr($parts[$i], \strlen($url)); + $parts[$i] = substr($parts[$i], 0, \strlen($url)); } } } // Multiple URLs inside one BBCode? Weird. Fix them. - if (count($detected_urls) > 1) { + if (\count($detected_urls) > 1) { $parts[$i - 1] = ''; $parts[$i + 1] = ''; diff --git a/Sources/Autoloader.php b/Sources/Autoloader.php index c4bdb1cbef..28b1a6ca42 100644 --- a/Sources/Autoloader.php +++ b/Sources/Autoloader.php @@ -43,7 +43,7 @@ } // Do any third-party scripts want in on the fun? - if (!defined('SMF_INSTALLING') && class_exists(Config::class, false) && $hook_value !== (Config::$modSettings['integrate_autoload'] ?? '')) { + if (!\defined('SMF_INSTALLING') && class_exists(Config::class, false) && $hook_value !== (Config::$modSettings['integrate_autoload'] ?? '')) { if (!class_exists(IntegrationHook::class, false) && is_file($sourcedir . '/IntegrationHook.php')) { require_once $sourcedir . '/IntegrationHook.php'; } @@ -56,7 +56,7 @@ foreach ($class_map as $prefix => $dirname) { // Does the class use the namespace prefix? - $len = strlen($prefix); + $len = \strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { continue; diff --git a/Sources/BBCodeParser.php b/Sources/BBCodeParser.php index f38734e17b..edfc23c40e 100644 --- a/Sources/BBCodeParser.php +++ b/Sources/BBCodeParser.php @@ -993,7 +993,7 @@ function ($a, $b) { public function parse(string $message, bool $smileys = true, string|int $cache_id = '', array $parse_tags = []): string { // Don't waste cycles - if (strval($message) === '') { + if (\strval($message) === '') { return ''; } @@ -1027,7 +1027,7 @@ public function parse(string $message, bool $smileys = true, string|int $cache_i IntegrationHook::call('integrate_pre_parsebbc', [&$this->message, &$this->smileys, &$cache_id, &$this->parse_tags, &$this->cache_key_extras]); // If no cache id was given, make a generic one. - $cache_id = strval($cache_id) !== '' ? $cache_id : 'str' . substr(md5($this->message), 0, 7); + $cache_id = \strval($cache_id) !== '' ? $cache_id : 'str' . substr(md5($this->message), 0, 7); // Use a unique identifier key for this combination of string and settings. $cache_key = 'parse:' . $cache_id . '-' . md5(json_encode([ @@ -1144,7 +1144,7 @@ public function parseSmileys(string $message): string $search_parts = []; $smileys_path = Utils::htmlspecialchars($this->smileys_url . '/' . rawurlencode($this->smiley_set) . '/'); - for ($i = 0, $n = count($smileysfrom); $i < $n; $i++) { + for ($i = 0, $n = \count($smileysfrom); $i < $n; $i++) { $special_chars = Utils::htmlspecialchars($smileysfrom[$i], ENT_QUOTES); $smiley_code = ''; @@ -1216,7 +1216,7 @@ public function unparse(string $string): string $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $string, -1, PREG_SPLIT_DELIM_CAPTURE); // Only mess with stuff outside [code] tags. - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { // Value of 2 means we're inside the tag. if ($i % 4 == 2) { $parts[$i] = strip_tags($parts[$i]); @@ -1250,7 +1250,7 @@ public function unparse(string $string): string foreach ($matches[1] as $k => $possible_code) { $possible_code = Utils::htmlspecialcharsDecode($possible_code); - if (in_array($possible_code, $smiley_codes)) { + if (\in_array($possible_code, $smiley_codes)) { $matches[1][$k] = '-[]-smf_smily_start#|#' . $possible_code . '-[]-smf_smily_end#|#'; } else { $matches[1][$k] = $matches[0][$k]; @@ -1383,7 +1383,7 @@ public function unparse(string $string): string } // Preserve some tags stripping the styling. - if (in_array($matches[2], ['a', 'font', 'td'])) { + if (\in_array($matches[2], ['a', 'font', 'td'])) { $replacement .= $precedingStyle . $afterStyle; $curCloseTags = '' . $matches[2] . '>' . $curCloseTags; } @@ -1404,7 +1404,7 @@ public function unparse(string $string): string // Closing tag. elseif (preg_match('~([A-Za-z]+)>~', $part, $matches) === 1) { // Is this the element that we've been waiting for to be closed? - if (!empty($stack) && strtolower((string) $matches[1]) === $stack[count($stack) - 1]['element']) { + if (!empty($stack) && strtolower((string) $matches[1]) === $stack[\count($stack) - 1]['element']) { $byebyeTag = array_pop($stack); $replacement .= $byebyeTag['closeTags']; } @@ -1441,15 +1441,15 @@ public function unparse(string $string): string $end_pos = strpos($string, '' . $matches[1] . '>', $start_pos); // Remove the align from that tag so it's never checked again. - $tag = substr($string, $start_pos, strlen((string) $matches[0])); - $content = substr($string, $start_pos + strlen((string) $matches[0]), $end_pos - $start_pos - strlen((string) $matches[0])); + $tag = substr($string, $start_pos, \strlen((string) $matches[0])); + $content = substr($string, $start_pos + \strlen((string) $matches[0]), $end_pos - $start_pos - \strlen((string) $matches[0])); $tag = str_replace($matches[2], '', $tag); // Put the tags back into the body. $string = substr($string, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($string, $end_pos); } else { // Just get rid of this evil tag. - $string = substr($string, 0, $start_pos) . substr($string, $start_pos + strlen((string) $matches[0])); + $string = substr($string, 0, $start_pos) . substr($string, $start_pos + \strlen((string) $matches[0])); } } @@ -1470,7 +1470,7 @@ public function unparse(string $string): string $start_pos_test = $start_pos + 4; $start_font_tag_stack = 0; - while ($start_pos_test < strlen($string)) { + while ($start_pos_test < \strlen($string)) { // Where is the next starting font? $next_start_pos = strpos($lower_text, '', $start_pos_test); @@ -1526,7 +1526,7 @@ public function unparse(string $string): string } // Remove the tag so it's never checked again. - $content = substr($string, $start_pos + strlen((string) $matches[0]), $end_pos - $start_pos - strlen((string) $matches[0])); + $content = substr($string, $start_pos + \strlen((string) $matches[0]), $end_pos - $start_pos - \strlen((string) $matches[0])); // Put the tags back into the body. $string = substr($string, 0, $start_pos) . $before . $content . $after . substr($string, $end_pos + 7); @@ -1537,7 +1537,7 @@ public function unparse(string $string): string Sapi::resetTimeout(); } - if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) > 1) { + if (\count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) > 1) { // A toggle that determines whether we're directly under a or . $inList = false; @@ -1557,7 +1557,7 @@ public function unparse(string $string): string ]; // $i: text, $i + 1: '/', $i + 2: tag, $i + 3: tail. - for ($i = 0, $numParts = count($parts) - 1; $i < $numParts; $i += 4) { + for ($i = 0, $numParts = \count($parts) - 1; $i < $numParts; $i += 4) { $tag = strtolower($parts[$i + 2]); $is_opening_tag = $parts[$i + 1] === ''; @@ -1574,7 +1574,7 @@ public function unparse(string $string): string str_repeat("\t", $listDepth) . '[li]', '', ]); - $numParts = count($parts) - 1; + $numParts = \count($parts) - 1; // The inlist status changes a bit. $inList = false; @@ -1655,7 +1655,7 @@ public function unparse(string $string): string '', // $i + 3 '', // $i + 4 ]); - $numParts = count($parts) - 1; + $numParts = \count($parts) - 1; // Now that we've closed the li, we're in list space. $inList = true; @@ -1699,7 +1699,7 @@ public function unparse(string $string): string '', // No tail. ]); - $numParts = count($parts) - 1; + $numParts = \count($parts) - 1; } } @@ -1724,7 +1724,7 @@ public function unparse(string $string): string break; } - $end_pos = $start_pos + strlen((string) $matches[0]); + $end_pos = $start_pos + \strlen((string) $matches[0]); $params = ''; $src = ''; @@ -1732,7 +1732,7 @@ public function unparse(string $string): string $attrs = self::fetchTagAttributes((string) $matches[1]); foreach ($attrs as $attrib => $value) { - if (in_array($attrib, ['width', 'height'])) { + if (\in_array($attrib, ['width', 'height'])) { $params .= ' ' . $attrib . '=' . (int) $value; } elseif ($attrib == 'alt' && trim($value) != '') { $params .= ' alt=' . trim($value); @@ -1747,7 +1747,7 @@ public function unparse(string $string): string $src = new Url($src); // Attempt to fix the path in case it's not present. - if (in_array($src->scheme, ['http', 'https']) && isset($src->host)) { + if (\in_array($src->scheme, ['http', 'https']) && isset($src->host)) { $base_url = ($src->scheme ?? 'http') . '://' . $src->host . (empty($src->port) ? '' : ':' . $src->port); if (str_starts_with((string) $src, '/')) { @@ -1909,7 +1909,7 @@ public function unparse(string $string): string break; } - $end_pos = $start_pos + strlen((string) $matches[0]); + $end_pos = $start_pos + \strlen((string) $matches[0]); $tag_type = 'url'; $href = ''; @@ -1922,7 +1922,7 @@ public function unparse(string $string): string $our_url = new Url(Config::$boardurl); // Are we dealing with an FTP link? - if (in_array($href->scheme, ['ftp', 'ftps'])) { + if (\in_array($href->scheme, ['ftp', 'ftps'])) { $tag_type = 'ftp'; } // Or is this a link to an email address? @@ -1931,7 +1931,7 @@ public function unparse(string $string): string $href = $href->path; } // No http(s), so attempt to fix this potential relative URL. - elseif (!in_array($href->scheme, ['http', 'https']) && isset($our_url->host)) { + elseif (!\in_array($href->scheme, ['http', 'https']) && isset($our_url->host)) { $base_url = ($our_url->scheme ?? 'http') . '://' . $our_url->host . (empty($our_url->port) ? '' : ':' . $our_url->port); if (str_starts_with((string) $href, '/')) { @@ -2045,7 +2045,7 @@ public static function getSigTags(): array $allowed_tags = []; foreach ($temp as $tag) { - if (!in_array($tag['tag'], $disabled_tags)) { + if (!\in_array($tag['tag'], $disabled_tags)) { $allowed_tags[] = $tag['tag']; } } @@ -2120,13 +2120,13 @@ public static function sanitizeMSCutPaste(string $string): string // windows 1252 / iso equivalents $findchars_iso = [ - chr(130), - chr(132), - chr(133), - chr(145), - chr(146), - chr(147), - chr(148), + \chr(130), + \chr(132), + \chr(133), + \chr(145), + \chr(146), + \chr(147), + \chr(148), ]; // safe replacements @@ -2165,7 +2165,7 @@ public static function backcompatParseBbc(string|bool $message, bool $smileys = self::load(); - $cache_id = (is_string($cache_id) || is_int($cache_id)) && strlen($cache_id) === strspn($cache_id, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_') ? (string) $cache_id : ''; + $cache_id = (\is_string($cache_id) || \is_int($cache_id)) && \strlen($cache_id) === strspn($cache_id, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_') ? (string) $cache_id : ''; $for_print = self::$parser->for_print; self::$parser->for_print = $smileys === 'print'; @@ -2213,7 +2213,7 @@ public static function integrateBBC(): void $temp = []; // Reverse order because mods typically append to the array. - for ($i = count(self::$codes) - 1; $i >= 0; $i--) { + for ($i = \count(self::$codes) - 1; $i >= 0; $i--) { $value = self::$codes[$i]; // Since validation functions may be closures, and @@ -2222,7 +2222,7 @@ public static function integrateBBC(): void $serialized = serialize($value); - if (!in_array($serialized, $temp)) { + if (!\in_array($serialized, $temp)) { $temp[] = $serialized; } else { unset(self::$codes[$i]); @@ -2260,7 +2260,7 @@ public static function attachValidate(array &$tag, array|string &$data, array $d $current_attachment = Attachment::parseAttachBBC($attach_id); // parseAttachBBC will return a string (Lang::$txt key) rather than dying with a fatal_error. Up to you to decide what to do. - if (is_string($current_attachment)) { + if (\is_string($current_attachment)) { $data = '' . (!empty(Lang::$txt[$current_attachment]) ? Lang::$txt[$current_attachment] : $current_attachment) . ''; return; @@ -2344,7 +2344,7 @@ public static function attachValidate(array &$tag, array|string &$data, array $d public static function codeValidate(array &$tag, array|string &$data, array $disabled, array $params): void { if (!isset($disabled['code'])) { - $code = is_array($data) ? $data[0] : $data; + $code = \is_array($data) ? $data[0] : $data; $add_begin = ( is_array($data) @@ -2360,7 +2360,7 @@ public static function codeValidate(array &$tag, array|string &$data, array $dis $php_parts = preg_split('~(<\?php|\?>)~', $code, -1, PREG_SPLIT_DELIM_CAPTURE); - for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) { + for ($php_i = 0, $php_n = \count($php_parts); $php_i < $php_n; $php_i++) { // Do PHP code coloring? if ($php_parts[$php_i] != '<?php') { continue; @@ -2368,7 +2368,7 @@ public static function codeValidate(array &$tag, array|string &$data, array $dis $php_string = ''; - while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') { + while ($php_i + 1 < \count($php_parts) && $php_parts[$php_i] != '?>') { $php_string .= $php_parts[$php_i]; $php_parts[$php_i++] = ''; } @@ -2389,7 +2389,7 @@ public static function codeValidate(array &$tag, array|string &$data, array $dis $code = preg_replace(['/^(.+?)<\?.{0,40}?php(?: |\s)/', '/\?>((?:\s*<\/(font|span)>)*)$/m'], '$1', $code, 2); } - if (is_array($data)) { + if (\is_array($data)) { $data[0] = $code; } else { $data = $code; @@ -2641,7 +2641,7 @@ protected function parseMessage(): void // Failsafe. if ($this->pos === false || $this->last_pos > $this->pos) { - $this->pos = strlen($this->message) + 1; + $this->pos = \strlen($this->message) + 1; } // Can't have a one letter smiley, URL, or email! (Sorry.) @@ -2664,14 +2664,14 @@ protected function parseMessage(): void $this->message = substr($this->message, 0, $this->last_pos) . $data . substr($this->message, $this->pos); // Since we changed it, look again in case we added or removed a tag. But we don't want to skip any. - $old_pos = strlen($data) + $this->last_pos; + $old_pos = \strlen($data) + $this->last_pos; $this->pos = strpos($this->message, '[', $this->last_pos); $this->pos = $this->pos === false ? $old_pos : min($this->pos, $old_pos); } } // Are we there yet? Are we there yet? - if ($this->pos >= strlen($this->message) - 1) { + if ($this->pos >= \strlen($this->message) - 1) { break; } @@ -2688,7 +2688,7 @@ protected function parseMessage(): void continue; } - $this->inside = empty($this->open_tags) ? null : $this->open_tags[count($this->open_tags) - 1]; + $this->inside = empty($this->open_tags) ? null : $this->open_tags[\count($this->open_tags) - 1]; // What tag do we have? list($tag, $params) = $this->detectTag($tag_character); @@ -2703,7 +2703,7 @@ protected function parseMessage(): void array_pop($this->open_tags); $this->message = substr($this->message, 0, $this->pos) . "\n" . $this->inside['after'] . "\n" . substr($this->message, $this->pos); - $this->pos += strlen($this->inside['after']) - 1 + 2; + $this->pos += \strlen($this->inside['after']) - 1 + 2; } continue; @@ -2725,7 +2725,7 @@ protected function parseMessage(): void } // Can't read past the end of the message - $this->pos1 = min(strlen($this->message), $this->pos1); + $this->pos1 = min(\strlen($this->message), $this->pos1); $this->transformToHtml($tag, $params); } @@ -2739,7 +2739,7 @@ protected function parseMessage(): void if ($this->smileys === true) { $message_parts = explode("\n", $this->message); - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { + for ($i = 0, $n = \count($message_parts); $i < $n; $i += 2) { $message_parts[$i] = $this->parseSmileys($message_parts[$i]); } @@ -2782,7 +2782,7 @@ protected function setDisabled(): void $this->disabled[trim($tag)] = true; } - if (in_array('color', $this->disabled)) { + if (\in_array('color', $this->disabled)) { $this->disabled = array_merge( $this->disabled, [ @@ -2797,15 +2797,15 @@ protected function setDisabled(): void } if (!empty($this->parse_tags)) { - if (!in_array('email', $this->parse_tags)) { + if (!\in_array('email', $this->parse_tags)) { $this->disabled['email'] = true; } - if (!in_array('url', $this->parse_tags)) { + if (!\in_array('url', $this->parse_tags)) { $this->disabled['url'] = true; } - if (!in_array('iurl', $this->parse_tags)) { + if (!\in_array('iurl', $this->parse_tags)) { $this->disabled['iurl'] = true; } } @@ -2943,7 +2943,7 @@ protected function setBbcCodes(): void } // If we are not doing every tag only do ones we are interested in. - if (empty($this->parse_tags) || in_array($code['tag'], $this->parse_tags)) { + if (empty($this->parse_tags) || \in_array($code['tag'], $this->parse_tags)) { $this->bbc_codes[substr($code['tag'], 0, 1)][] = $code; } } @@ -3077,7 +3077,7 @@ protected function closeTags(): void $look_for = strtolower(substr($this->message, $this->pos + 2, $pos2 - $this->pos - 2)); // A closing tag that doesn't match any open tags? Skip it. - if (!in_array($look_for, array_map(function ($tag) { return $tag['tag']; }, $this->open_tags))) { + if (!\in_array($look_for, array_map(function ($tag) { return $tag['tag']; }, $this->open_tags))) { return; } @@ -3099,7 +3099,7 @@ protected function closeTags(): void } // The idea is, if we are LOOKING for a block level tag, we can close them on the way. - if (strlen($look_for) > 0 && isset($this->bbc_codes[$look_for[0]])) { + if (\strlen($look_for) > 0 && isset($this->bbc_codes[$look_for[0]])) { foreach ($this->bbc_codes[$look_for[0]] as $temp) { if ($temp['tag'] == $look_for) { $block_level = !empty($temp['block_level']); @@ -3147,7 +3147,7 @@ protected function closeTags(): void foreach ($to_close as $tag) { $this->message = substr($this->message, 0, $this->pos) . "\n" . $tag['after'] . "\n" . substr($this->message, $pos2 + 1); - $this->pos += strlen($tag['after']) + 2; + $this->pos += \strlen($tag['after']) + 2; $pos2 = $this->pos - 1; // See the comment at the end of the big loop - just eating whitespace ;). @@ -3163,7 +3163,7 @@ protected function closeTags(): void } if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($this->message, $this->pos), $matches) != 0) { - $this->message = substr($this->message, 0, $this->pos) . substr($this->message, $this->pos + strlen($matches[0])); + $this->message = substr($this->message, 0, $this->pos) . substr($this->message, $this->pos + \strlen($matches[0])); } } @@ -3185,7 +3185,7 @@ protected function detectTag(string $tag_character): array $params = []; foreach ($this->bbc_codes[$tag_character] as $possible) { - $pt_strlen = strlen($possible['tag']); + $pt_strlen = \strlen($possible['tag']); // Not a match? if (strtolower(substr($this->message, $this->pos + 1, $pt_strlen)) != $possible['tag']) { @@ -3223,7 +3223,7 @@ protected function detectTag(string $tag_character): array // No parameters, so does the next character match what we expect? elseif (isset($possible['type'])) { // Do we need an equal sign? - if (in_array($possible['type'], ['unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals']) && $next_c != '=') { + if (\in_array($possible['type'], ['unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals']) && $next_c != '=') { continue; } @@ -3243,16 +3243,16 @@ protected function detectTag(string $tag_character): array } // Check allowed tree? - if (isset($possible['require_parents']) && ($this->inside === null || !in_array($this->inside['tag'], $possible['require_parents']))) { + if (isset($possible['require_parents']) && ($this->inside === null || !\in_array($this->inside['tag'], $possible['require_parents']))) { continue; } - if (isset($this->inside['require_children']) && !in_array($possible['tag'], (array) $this->inside['require_children'])) { + if (isset($this->inside['require_children']) && !\in_array($possible['tag'], (array) $this->inside['require_children'])) { continue; } // If this is in the list of disallowed child tags, don't parse it. - if (isset($this->inside['disallow_children']) && in_array($possible['tag'], (array) $this->inside['disallow_children'])) { + if (isset($this->inside['disallow_children']) && \in_array($possible['tag'], (array) $this->inside['disallow_children'])) { continue; } @@ -3296,8 +3296,8 @@ protected function detectTag(string $tag_character): array // Progressively append more blobs until we find our parameters or run out of blobs $blob_counter = 1; - while ($blob_counter <= count($blobs)) { - $given_param_string = implode(']', array_slice($blobs, 0, $blob_counter++)); + while ($blob_counter <= \count($blobs)) { + $given_param_string = implode(']', \array_slice($blobs, 0, $blob_counter++)); $given_params = preg_split('~\s(?=(' . $splitters . '))~i', $given_param_string); sort($given_params, SORT_STRING); @@ -3316,7 +3316,7 @@ protected function detectTag(string $tag_character): array $params = []; - for ($i = 1, $n = count($matches); $i < $n; $i += 2) { + for ($i = 1, $n = \count($matches); $i < $n; $i += 2) { $key = strtok(ltrim($matches[$i]), '='); if ($key === false) { @@ -3364,7 +3364,7 @@ protected function detectTag(string $tag_character): array $tag['content'] = strtr($tag['content'], $params); } - $this->pos1 += strlen($given_param_string); + $this->pos1 += \strlen($given_param_string); } else { $tag = $possible; $params = []; @@ -3381,7 +3381,7 @@ protected function detectTag(string $tag_character): array */ protected function parseItemCode(): void { - if ($this->message[$this->pos + 1] == '0' && !in_array($this->message[$this->pos - 1], [';', ' ', "\t", "\n", '>'])) { + if ($this->message[$this->pos + 1] == '0' && !\in_array($this->message[$this->pos - 1], [';', ' ', "\t", "\n", '>'])) { return; } @@ -3421,7 +3421,7 @@ protected function parseItemCode(): void $this->message = substr($this->message, 0, $this->pos) . "\n" . $html . "\n" . substr($this->message, $this->pos + 3); - $this->pos += strlen($html) - 1 + 2; + $this->pos += \strlen($html) - 1 + 2; // Next, find the next break (if any.) If there's more itemcode after it, keep it going - otherwise close! $pos2 = strpos($this->message, '', $this->pos); @@ -3432,13 +3432,13 @@ protected function parseItemCode(): void $this->message = substr($this->message, 0, $pos2) . (!empty($matches[0]) && str_ends_with($matches[0], '[') ? '[/li]' : '[/li][/list]') . substr($this->message, $pos2); - $this->open_tags[count($this->open_tags) - 2]['after'] = ''; + $this->open_tags[\count($this->open_tags) - 2]['after'] = ''; } // Tell the [list] that it needs to close specially. else { // Move the li over, because we're not sure what we'll hit. - $this->open_tags[count($this->open_tags) - 1]['after'] = ''; - $this->open_tags[count($this->open_tags) - 2]['after'] = ''; + $this->open_tags[\count($this->open_tags) - 1]['after'] = ''; + $this->open_tags[\count($this->open_tags) - 2]['after'] = ''; } } @@ -3470,17 +3470,17 @@ protected function useDisabledTag(array $tag): array */ protected function closeInlineTags(): void { - $n = count($this->open_tags) - 1; + $n = \count($this->open_tags) - 1; while (empty($this->open_tags[$n]['block_level']) && $n >= 0) { $n--; } // Close all the non block level tags so this tag isn't surrounded by them. - for ($i = count($this->open_tags) - 1; $i > $n; $i--) { + for ($i = \count($this->open_tags) - 1; $i > $n; $i--) { $this->message = substr($this->message, 0, $this->pos) . "\n" . $this->open_tags[$i]['after'] . "\n" . substr($this->message, $this->pos); - $ot_strlen = strlen($this->open_tags[$i]['after']); + $ot_strlen = \strlen($this->open_tags[$i]['after']); $this->pos += $ot_strlen + 2; $this->pos1 += $ot_strlen + 2; @@ -3496,7 +3496,7 @@ protected function closeInlineTags(): void } if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($this->message, $this->pos), $matches) != 0) { - $this->message = substr($this->message, 0, $this->pos) . substr($this->message, $this->pos + strlen($matches[0])); + $this->message = substr($this->message, 0, $this->pos) . substr($this->message, $this->pos + \strlen($matches[0])); } array_pop($this->open_tags); @@ -3524,10 +3524,10 @@ protected function transformToHtml(array $tag, array $params): void } // We use this a lot. - $tag_strlen = strlen($tag['tag']); + $tag_strlen = \strlen($tag['tag']); // Set the validation method to something we can call. - if (isset($tag['validate']) && is_string($tag['validate'])) { + if (isset($tag['validate']) && \is_string($tag['validate'])) { $tag['validate'] = Utils::getCallable($tag['validate']); } @@ -3539,12 +3539,12 @@ protected function transformToHtml(array $tag, array $params): void $data = null; if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } $this->message = substr($this->message, 0, $this->pos) . "\n" . $tag['before'] . "\n" . substr($this->message, $this->pos1); - $this->pos += strlen($tag['before']) - 1 + 2; + $this->pos += \strlen($tag['before']) - 1 + 2; } // Don't parse the content, just skip it. elseif ($tag['type'] == 'unparsed_content') { @@ -3561,14 +3561,14 @@ protected function transformToHtml(array $tag, array $params): void } if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } $html = strtr($tag['content'], ['$1' => $data]); $this->message = substr($this->message, 0, $this->pos) . "\n" . $html . "\n" . substr($this->message, $pos2 + 3 + $tag_strlen); - $this->pos += strlen($html) - 1 + 2; + $this->pos += \strlen($html) - 1 + 2; $this->last_pos = $this->pos + 1; } // Don't parse the content, just skip it. @@ -3615,14 +3615,14 @@ protected function transformToHtml(array $tag, array $params): void // Validation for my parking, please! if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } $html = strtr($tag['content'], ['$1' => $data[0], '$2' => $data[1]]); $this->message = substr($this->message, 0, $this->pos) . "\n" . $html . "\n" . substr($this->message, $pos3 + 3 + $tag_strlen); - $this->pos += strlen($html) - 1 + 2; + $this->pos += \strlen($html) - 1 + 2; } // A closed tag, with no content or value. elseif ($tag['type'] == 'closed') { @@ -3632,12 +3632,12 @@ protected function transformToHtml(array $tag, array $params): void $data = null; if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } $this->message = substr($this->message, 0, $this->pos) . "\n" . $tag['content'] . "\n" . substr($this->message, $pos2 + 1); - $this->pos += strlen($tag['content']) - 1 + 2; + $this->pos += \strlen($tag['content']) - 1 + 2; } // This one is sorta ugly... :/. Unfortunately, it's needed for flash. elseif ($tag['type'] == 'unparsed_commas_content') { @@ -3658,7 +3658,7 @@ protected function transformToHtml(array $tag, array $params): void $data[0] = substr($this->message, $pos2 + 1, $pos3 - $pos2 - 1); if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } $html = $tag['content']; @@ -3669,7 +3669,7 @@ protected function transformToHtml(array $tag, array $params): void $this->message = substr($this->message, 0, $this->pos) . "\n" . $html . "\n" . substr($this->message, $pos3 + 3 + $tag_strlen); - $this->pos += strlen($html) - 1 + 2; + $this->pos += \strlen($html) - 1 + 2; } // This has parsed content, and a csv value which is unparsed. elseif ($tag['type'] == 'unparsed_commas') { @@ -3682,7 +3682,7 @@ protected function transformToHtml(array $tag, array $params): void $data = explode(',', substr($this->message, $this->pos1, $pos2 - $this->pos1)); if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } // Fix after, for disabled code mainly. @@ -3701,7 +3701,7 @@ protected function transformToHtml(array $tag, array $params): void $this->message = substr($this->message, 0, $this->pos) . "\n" . $html . "\n" . substr($this->message, $pos2 + 1); - $this->pos += strlen($html) - 1 + 2; + $this->pos += \strlen($html) - 1 + 2; } // A tag set to a value, parsed or not. elseif ($tag['type'] == 'unparsed_equals' || $tag['type'] == 'parsed_equals') { @@ -3748,7 +3748,7 @@ protected function transformToHtml(array $tag, array $params): void // Validation for my parking, please! if (isset($tag['validate'])) { - call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); + \call_user_func_array($tag['validate'], [&$tag, &$data, $this->disabled, $params]); } // For parsed content, we must recurse to avoid security problems. @@ -3773,7 +3773,7 @@ protected function transformToHtml(array $tag, array $params): void $this->message = substr($this->message, 0, $this->pos) . "\n" . $html . "\n" . substr($this->message, $pos2 + ($quoted == false ? 1 : 1 + strlen($quot))); - $this->pos += strlen($html) - 1 + 2; + $this->pos += \strlen($html) - 1 + 2; } // If this is block level, eat any breaks after it. @@ -3783,7 +3783,7 @@ protected function transformToHtml(array $tag, array $params): void // Are we trimming outside this tag? if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(| |\s)*~', substr($this->message, $this->pos + 1), $matches) != 0) { - $this->message = substr($this->message, 0, $this->pos + 1) . substr($this->message, $this->pos + 1 + strlen($matches[0])); + $this->message = substr($this->message, 0, $this->pos + 1) . substr($this->message, $this->pos + 1 + \strlen($matches[0])); } } @@ -3801,7 +3801,7 @@ protected function fetchTagAttributes(string $string): array $key = $value = ''; $tag_state = 0; // 0 = key, 1 = attribute with no string, 2 = attribute with string - for ($i = 0; $i < strlen($string); $i++) { + for ($i = 0; $i < \strlen($string); $i++) { // We're either moving from the key to the attribute or we're in a string and this is fine. if ($string[$i] == '=') { if ($tag_state == 0) { @@ -3859,7 +3859,7 @@ protected function fetchTagAttributes(string $string): array protected function legalise(string $string): string { // Don't care about the texts that are too short. - if (strlen($string) < 3) { + if (\strlen($string) < 3) { return $string; } @@ -3888,7 +3888,7 @@ protected function legalise(string $string): string $align_tags = array_intersect($align_tags, array_keys($valid_tags)); // These keep track of where we are! - if (!empty($align_tags) && count($matches = preg_split('~(\[/?(?:' . implode('|', $align_tags) . ')\])~', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) > 1) { + if (!empty($align_tags) && \count($matches = preg_split('~(\[/?(?:' . implode('|', $align_tags) . ')\])~', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) > 1) { // The first one is never a tag. $is_tag = false; @@ -3933,15 +3933,15 @@ protected function legalise(string $string): string $lastlen = 0; - while (strlen($string) !== $lastlen) { - $lastlen = strlen($string = preg_replace($back_to_back_pattern, '', $string)); + while (\strlen($string) !== $lastlen) { + $lastlen = \strlen($string = preg_replace($back_to_back_pattern, '', $string)); } // Need to sort the tags by name length. uksort( $valid_tags, function ($a, $b) { - return strlen($a) < strlen($b) ? 1 : -1; + return \strlen($a) < \strlen($b) ? 1 : -1; }, ); @@ -3952,7 +3952,7 @@ function ($a, $b) { ]; // These keep track of where we are! - if (count($parts = preg_split(sprintf('~(\[)(/?)(%1$s)((?:[\s=][^\]\[]*)?\])~', implode('|', array_keys($valid_tags))), $string, -1, PREG_SPLIT_DELIM_CAPTURE)) > 1) { + if (\count($parts = preg_split(sprintf('~(\[)(/?)(%1$s)((?:[\s=][^\]\[]*)?\])~', implode('|', array_keys($valid_tags))), $string, -1, PREG_SPLIT_DELIM_CAPTURE)) > 1) { // Start outside [nobbc] or [code] blocks. $in_code = false; $in_nobbc = false; @@ -3967,12 +3967,12 @@ function ($a, $b) { $competing_elements = []; // $i: text, $i + 1: '[', $i + 2: '/', $i + 3: tag, $i + 4: tag tail. - for ($i = 0, $n = count($parts) - 1; $i < $n; $i += 5) { + for ($i = 0, $n = \count($parts) - 1; $i < $n; $i += 5) { $tag = $parts[$i + 3]; $is_opening_tag = $parts[$i + 2] === ''; $is_closing_tag = $parts[$i + 2] === '/'; - $is_block_level_tag = isset($valid_tags[$tag]) && $valid_tags[$tag] && !in_array($tag, $self_closing_tags); - $is_competing_tag = in_array($tag, $competing_tags); + $is_block_level_tag = isset($valid_tags[$tag]) && $valid_tags[$tag] && !\in_array($tag, $self_closing_tags); + $is_competing_tag = \in_array($tag, $competing_tags); // Check if this might be one of those cleaned out tags. if ($tag === '') { @@ -4052,7 +4052,7 @@ function ($a, $b) { $block_elements[] = $tag; } // Inline opening tag. - elseif (!in_array($tag, $self_closing_tags)) { + elseif (!\in_array($tag, $self_closing_tags)) { // Can't have two opening elements with the same contents! if (isset($inline_elements[$element_content])) { // Get rid of this tag. @@ -4061,7 +4061,7 @@ function ($a, $b) { // Now try to find the corresponding closing tag. $cur_level = 1; - for ($j = $i + 5, $m = count($parts) - 1; $j < $m; $j += 5) { + for ($j = $i + 5, $m = \count($parts) - 1; $j < $m; $j += 5) { // Find the tags with the same tagname if ($parts[$j + 3] === $tag) { // If it's an opening tag, increase the level. @@ -4090,7 +4090,7 @@ function ($a, $b) { $competing_elements[$tag][] = $parts[$i + 4]; - if (count($competing_elements[$tag]) > 1) { + if (\count($competing_elements[$tag]) > 1) { $parts[$i] .= '[/' . $tag . ']'; } } @@ -4121,7 +4121,7 @@ function ($a, $b) { } // Apparently the closing tag was not found on the stack. - if (!is_string($element) || $element !== $tag) { + if (!\is_string($element) || $element !== $tag) { // Get rid of this particular closing tag, it was never opened. $parts[$i + 1] = substr($parts[$i + 1], 0, -1); $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; @@ -4147,7 +4147,7 @@ function ($a, $b) { // Inline tag. else { // Are we expecting this tag to end? - if (in_array($tag, $inline_elements)) { + if (\in_array($tag, $inline_elements)) { foreach (array_reverse($inline_elements, true) as $tag_content_to_be_closed => $tag_to_be_closed) { // Closing it one way or the other. unset($inline_elements[$tag_content_to_be_closed]); @@ -4164,8 +4164,8 @@ function ($a, $b) { if ($is_competing_tag && !empty($competing_elements[$tag])) { array_pop($competing_elements[$tag]); - if (count($competing_elements[$tag]) > 0) { - $parts[$i + 5] = '[' . $tag . $competing_elements[$tag][count($competing_elements[$tag]) - 1] . $parts[$i + 5]; + if (\count($competing_elements[$tag]) > 0) { + $parts[$i + 5] = '[' . $tag . $competing_elements[$tag][\count($competing_elements[$tag]) - 1] . $parts[$i + 5]; } } } @@ -4201,8 +4201,8 @@ function ($a, $b) { // Final clean up of back-to-back tags. $lastlen = 0; - while (strlen($string) !== $lastlen) { - $lastlen = strlen($string = preg_replace($back_to_back_pattern, '', $string)); + while (\strlen($string) !== $lastlen) { + $lastlen = \strlen($string = preg_replace($back_to_back_pattern, '', $string)); } return $string; diff --git a/Sources/Board.php b/Sources/Board.php index ff38ab9674..af3aea3d2e 100644 --- a/Sources/Board.php +++ b/Sources/Board.php @@ -458,15 +458,15 @@ class Board implements \ArrayAccess */ public function __set(string $prop, mixed $value): void { - if (in_array($this->prop_aliases[$prop] ?? $prop, ['member_groups', 'deny_groups'])) { - if (!is_array($value)) { + if (\in_array($this->prop_aliases[$prop] ?? $prop, ['member_groups', 'deny_groups'])) { + if (!\is_array($value)) { $value = explode(',', $value); } $value = array_map('intval', array_filter($value, 'strlen')); // Special handling for access for board manager groups. - if (!empty(Config::$modSettings['board_manager_groups']) && in_array($this->prop_aliases[$prop] ?? $prop, ['member_groups', 'deny_groups']) && is_array($value)) { + if (!empty(Config::$modSettings['board_manager_groups']) && \in_array($this->prop_aliases[$prop] ?? $prop, ['member_groups', 'deny_groups']) && \is_array($value)) { $board_manager_groups = array_map('intval', array_filter(explode(',', Config::$modSettings['board_manager_groups']), 'strlen')); if (($this->prop_aliases[$prop] ?? $prop) === 'deny_groups') { @@ -839,7 +839,7 @@ public function move( continue; } - $board->order += (1 + count($child_list)); + $board->order += (1 + \count($child_list)); $affected_boards[] = $board->id; } @@ -1202,7 +1202,7 @@ public static function markRead(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (in_array($row['id_parent'], $boards)) { + if (\in_array($row['id_parent'], $boards)) { $boards[] = $row['id_board']; } } @@ -1309,7 +1309,7 @@ public static function markRead(): void public static function markBoardsRead(int|array $boards, bool $unread = false): void { // Force $boards to be an array. - if (!is_array($boards)) { + if (!\is_array($boards)) { $boards = [$boards]; } else { $boards = array_unique($boards); @@ -1554,7 +1554,7 @@ public static function modify(int $board_id, array &$boardOptions): void 'invalid_groups' => [Group::ADMIN, Group::MOD], 'moderator_group_list' => $moderator_groups, ], - 'limit' => count($moderator_groups), + 'limit' => \count($moderator_groups), ]; foreach (Group::load([], $query_customizations) as $group) { @@ -1564,7 +1564,7 @@ public static function modify(int $board_id, array &$boardOptions): void } if (isset($boardOptions['moderators'])) { - if (!is_array($boardOptions['moderators'])) { + if (!\is_array($boardOptions['moderators'])) { $boardOptions['moderators'] = array_filter(explode(',', $boardOptions['moderators']), 'strlen'); } @@ -1572,7 +1572,7 @@ public static function modify(int $board_id, array &$boardOptions): void } if (isset($boardOptions['moderator_groups'])) { - if (!is_array($boardOptions['moderator_groups'])) { + if (!\is_array($boardOptions['moderator_groups'])) { $boardOptions['moderator_groups'] = array_filter(explode(',', $boardOptions['moderator_groups']), 'strlen'); } @@ -1634,7 +1634,7 @@ public static function create(array $boardOptions): int trigger_error(Lang::$txt['create_board_missing_options'], E_USER_ERROR); } - if (in_array($boardOptions['move_to'], ['child', 'before', 'after']) && !isset($boardOptions['target_board'])) { + if (\in_array($boardOptions['move_to'], ['child', 'before', 'after']) && !isset($boardOptions['target_board'])) { Lang::load('Errors'); trigger_error(Lang::$txt['move_board_no_target'], E_USER_ERROR); } @@ -1973,9 +1973,9 @@ public static function sort(array &$boards): void if (!empty($boards[$board])) { $ordered[$board] = $boards[$board]; - if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) { + if (\is_array($ordered[$board]) && !empty($ordered[$board]['children'])) { self::sort($ordered[$board]['children']); - } elseif (is_object($ordered[$board]) && !empty($ordered[$board]->children)) { + } elseif (\is_object($ordered[$board]) && !empty($ordered[$board]->children)) { Board::sort($ordered[$board]->children); } } @@ -2184,7 +2184,7 @@ public static function getParents(int $id_parent): array public static function queryData(array $selects, array $params = [], array $joins = [], array $where = [], array $order = [], array $group = [], int $limit = 0): \Generator { // If we only want some child boards, use a CTE query for improved performance. - if (!empty($params['id_parent']) && in_array('b.id_parent != 0', $where) && Db::$db->cte_support()) { + if (!empty($params['id_parent']) && \in_array('b.id_parent != 0', $where) && Db::$db->cte_support()) { // Ensure we include all the necessary fields for the CTE query. preg_match_all('/\bb\.(\w+)/', implode(', ', $selects), $matches); @@ -2218,13 +2218,13 @@ function ($field) { $cte_where1 = ['b.id_board = {int:id_parent}']; $cte_where2 = []; - if (in_array('{query_see_board}', $where)) { + if (\in_array('{query_see_board}', $where)) { array_unshift($cte_where1, '{query_see_board}'); $cte_where2[] = '{query_see_board}'; $where = array_diff($where, ['{query_see_board}']); } - if (in_array('b.child_level BETWEEN {int:child_level} AND {int:max_child_level}', $where)) { + if (\in_array('b.child_level BETWEEN {int:child_level} AND {int:max_child_level}', $where)) { $cte_where2[] = 'b.child_level BETWEEN {int:child_level} AND {int:max_child_level}'; $where = array_diff($where, ['b.child_level BETWEEN {int:child_level} AND {int:max_child_level}']); } @@ -2596,9 +2596,9 @@ protected function checkAccess(): void return; } - if (count(array_intersect(User::$me->groups, $this->member_groups)) == 0) { + if (\count(array_intersect(User::$me->groups, $this->member_groups)) == 0) { $this->error = 'access'; - } elseif (!empty(Config::$modSettings['deny_boards_access']) && count(array_intersect(User::$me->groups, $this->deny_groups)) != 0) { + } elseif (!empty(Config::$modSettings['deny_boards_access']) && \count(array_intersect(User::$me->groups, $this->deny_groups)) != 0) { $this->error = 'access'; } } @@ -2667,7 +2667,7 @@ protected function blockOnError(): void } // Export properties to global namespace for backward compatibility. -if (is_callable([Board::class, 'exportStatic'])) { +if (\is_callable([Board::class, 'exportStatic'])) { Board::exportStatic(); } diff --git a/Sources/BrowserDetector.php b/Sources/BrowserDetector.php index 347aa449c8..f5676f5c19 100644 --- a/Sources/BrowserDetector.php +++ b/Sources/BrowserDetector.php @@ -133,7 +133,7 @@ public function detectBrowser(): void $this->_browsers['possibly_robot'] = !empty(User::$me->possibly_robot); // Robots shouldn't be logging in or registering. So, they aren't a bot. Better to be wrong than sorry (or people won't be able to log in!), anyway. - if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], ['login', 'login2', 'register', 'signup'])) || !User::$me->is_guest) { + if ((isset($_REQUEST['action']) && \in_array($_REQUEST['action'], ['login', 'login2', 'register', 'signup'])) || !User::$me->is_guest) { $this->_browsers['possibly_robot'] = false; } } else { @@ -489,7 +489,7 @@ private function setupBrowserPriority(): void $active = array_reverse(array_keys($this->_browsers, true)); foreach ($active as $browser) { - if (array_key_exists($browser, $browser_priority)) { + if (\array_key_exists($browser, $browser_priority)) { Utils::$context['browser_body_id'] = $browser_priority[$browser]; break; } diff --git a/Sources/Cache/APIs/Apcu.php b/Sources/Cache/APIs/Apcu.php index d930795db5..671bf01355 100644 --- a/Sources/Cache/APIs/Apcu.php +++ b/Sources/Cache/APIs/Apcu.php @@ -18,7 +18,7 @@ use SMF\Cache\CacheApi; use SMF\Cache\CacheApiInterface; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } @@ -34,7 +34,7 @@ class Apcu extends CacheApi implements CacheApiInterface */ public function isSupported(bool $test = false): bool { - $supported = function_exists('apcu_fetch') && function_exists('apcu_store'); + $supported = \function_exists('apcu_fetch') && \function_exists('apcu_store'); if ($test) { return $supported; diff --git a/Sources/Cache/APIs/FileBased.php b/Sources/Cache/APIs/FileBased.php index 10c9e89130..1ea041558d 100644 --- a/Sources/Cache/APIs/FileBased.php +++ b/Sources/Cache/APIs/FileBased.php @@ -23,7 +23,7 @@ use SMF\Lang; use SMF\Utils; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } @@ -122,7 +122,7 @@ public function putData(string $key, mixed $value, ?int $ttl = null): mixed // Write out the cache file, check that the cache write was successful; all the data must be written // If it fails due to low diskspace, or other, remove the cache file - if ($this->writeFile($file, $cache_data) !== strlen($cache_data)) { + if ($this->writeFile($file, $cache_data) !== \strlen($cache_data)) { @unlink($file); return false; @@ -202,7 +202,7 @@ public function cacheSettings(array &$config_vars): void public function setCachedir(?string $dir = null): void { // If it's invalid, use SMF's. - if (is_null($dir) || !is_writable($dir)) { + if (\is_null($dir) || !is_writable($dir)) { $this->cachedir = Config::$cachedir; } else { $this->cachedir = $dir; diff --git a/Sources/Cache/APIs/MemcacheImplementation.php b/Sources/Cache/APIs/MemcacheImplementation.php index 4b945c12fe..2ce2fa99ab 100644 --- a/Sources/Cache/APIs/MemcacheImplementation.php +++ b/Sources/Cache/APIs/MemcacheImplementation.php @@ -22,7 +22,7 @@ use SMF\Lang; use SMF\Utils; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } @@ -97,7 +97,7 @@ public function connect(): bool $level = 0; // We should keep trying if a server times out, but only for the amount of servers we have. - while (!$connected && $level < count($this->servers)) { + while (!$connected && $level < \count($this->servers)) { ++$level; $server = $this->servers[array_rand($this->servers)]; @@ -171,7 +171,7 @@ public function cleanCache($type = ''): bool */ public function cacheSettings(array &$config_vars): void { - if (!in_array(Lang::$txt[self::CLASS_KEY . '_settings'], $config_vars)) { + if (!\in_array(Lang::$txt[self::CLASS_KEY . '_settings'], $config_vars)) { $config_vars[] = Lang::$txt[self::CLASS_KEY . '_settings']; $config_vars[] = [ self::CLASS_KEY, @@ -200,7 +200,7 @@ public function cacheSettings(array &$config_vars): void */ public function getVersion(): string|bool { - if (!is_object($this->memcache)) { + if (!\is_object($this->memcache)) { return false; } diff --git a/Sources/Cache/APIs/MemcachedImplementation.php b/Sources/Cache/APIs/MemcachedImplementation.php index da2406f54a..22e6d38d86 100644 --- a/Sources/Cache/APIs/MemcachedImplementation.php +++ b/Sources/Cache/APIs/MemcachedImplementation.php @@ -22,7 +22,7 @@ use SMF\Lang; use SMF\Utils; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } @@ -178,7 +178,7 @@ public function quit(): bool */ public function cacheSettings(array &$config_vars): void { - if (!in_array(Lang::$txt[self::CLASS_KEY . '_settings'], $config_vars)) { + if (!\in_array(Lang::$txt[self::CLASS_KEY . '_settings'], $config_vars)) { $config_vars[] = Lang::$txt[self::CLASS_KEY . '_settings']; $config_vars[] = [ self::CLASS_KEY, @@ -207,7 +207,7 @@ public function cacheSettings(array &$config_vars): void */ public function getVersion(): string|bool { - if (!is_object($this->memcached)) { + if (!\is_object($this->memcached)) { return false; } diff --git a/Sources/Cache/APIs/Postgres.php b/Sources/Cache/APIs/Postgres.php index 5ed4a828c7..ae31cfe4de 100644 --- a/Sources/Cache/APIs/Postgres.php +++ b/Sources/Cache/APIs/Postgres.php @@ -20,7 +20,7 @@ use SMF\Config; use SMF\Db\DatabaseApi as Db; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } @@ -109,7 +109,7 @@ function ($el) { ); foreach ($stmtnames as $idx => $stmtname) { - if (!in_array($stmtname, $arr)) { + if (!\in_array($stmtname, $arr)) { pg_prepare($this->db_connection, $stmtname, $queries[$idx]); } } diff --git a/Sources/Cache/APIs/Sqlite.php b/Sources/Cache/APIs/Sqlite.php index 2a10e6df98..5aeb84bfcf 100755 --- a/Sources/Cache/APIs/Sqlite.php +++ b/Sources/Cache/APIs/Sqlite.php @@ -22,7 +22,7 @@ use SMF\Utils; use SQLite3; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } diff --git a/Sources/Cache/APIs/Zend.php b/Sources/Cache/APIs/Zend.php index d0e5b594bd..6bc3aef546 100644 --- a/Sources/Cache/APIs/Zend.php +++ b/Sources/Cache/APIs/Zend.php @@ -18,7 +18,7 @@ use SMF\Cache\CacheApi; use SMF\Cache\CacheApiInterface; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } @@ -34,7 +34,7 @@ class Zend extends CacheApi implements CacheApiInterface */ public function isSupported(bool $test = false): bool { - $supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get'); + $supported = \function_exists('zend_shm_cache_fetch') || \function_exists('output_cache_get'); if ($test) { return $supported; @@ -56,11 +56,11 @@ public function getData(string $key, ?int $ttl = null): mixed $key = $this->prefix . strtr($key, ':/', '-_'); // Zend's pricey stuff. - if (function_exists('zend_shm_cache_fetch')) { + if (\function_exists('zend_shm_cache_fetch')) { return zend_shm_cache_fetch('SMF::' . $key); } - if (function_exists('output_cache_get')) { + if (\function_exists('output_cache_get')) { return output_cache_get($key, $ttl); } @@ -74,11 +74,11 @@ public function putData(string $key, mixed $value, ?int $ttl = null): mixed { $key = $this->prefix . strtr($key, ':/', '-_'); - if (function_exists('zend_shm_cache_store')) { + if (\function_exists('zend_shm_cache_store')) { return zend_shm_cache_store('SMF::' . $key, $value, $ttl); } - if (function_exists('output_cache_put')) { + if (\function_exists('output_cache_put')) { return output_cache_put($key, $value); } diff --git a/Sources/Cache/CacheApi.php b/Sources/Cache/CacheApi.php index 3ed4070d6d..202b73d220 100644 --- a/Sources/Cache/CacheApi.php +++ b/Sources/Cache/CacheApi.php @@ -171,7 +171,7 @@ public function isSupported(bool $test = false): bool */ public function setPrefix(string $prefix = ''): bool { - if (!is_string($prefix)) { + if (!\is_string($prefix)) { $prefix = ''; } @@ -314,13 +314,13 @@ public function housekeeping(): void */ public function getImplementationClassKeyName(): string { - $class_name = get_class($this); + $class_name = \get_class($this); if ($position = strrpos($class_name, '\\')) { return substr($class_name, $position + 1); } - return get_class($this); + return \get_class($this); } /*********************** @@ -353,11 +353,11 @@ final public static function load(string $overrideCache = '', bool $fallbackSMF } // Not overriding this and we have a cacheAPI, send it back. - if (empty($overrideCache) && is_object(self::$loadedApi)) { + if (empty($overrideCache) && \is_object(self::$loadedApi)) { return self::$loadedApi; } - if (is_null(self::$loadedApi)) { + if (\is_null(self::$loadedApi)) { self::$loadedApi = false; } @@ -495,12 +495,12 @@ final public static function quickGet(string $key, string $file, string|array $f 4. The cached item has a custom expiration condition evaluating to true. 5. The expire time set in the cache item has passed (needed for Zend). */ - if (empty(self::$enable) || self::$enable < $level || !is_array($cache_block = self::get($key, 3600)) || (!empty($cache_block['refresh_eval']) && eval($cache_block['refresh_eval'])) || (!empty($cache_block['expires']) && $cache_block['expires'] < time())) { + if (empty(self::$enable) || self::$enable < $level || !\is_array($cache_block = self::get($key, 3600)) || (!empty($cache_block['refresh_eval']) && eval($cache_block['refresh_eval'])) || (!empty($cache_block['expires']) && $cache_block['expires'] < time())) { if (!empty($file) && is_file(Config::$sourcedir . '/' . $file)) { require_once Config::$sourcedir . '/' . $file; } - $cache_block = call_user_func_array($function, $params); + $cache_block = \call_user_func_array($function, $params); if (!empty(self::$enable) && self::$enable >= $level) { self::put($key, $cache_block, $cache_block['expires'] - time()); @@ -588,7 +588,7 @@ final public static function get(string $key, int $ttl = 120): mixed if (isset(Config::$db_show_debug) && Config::$db_show_debug === true) { self::$hits[self::$count_hits]['t'] = microtime(true) - $st; - self::$hits[self::$count_hits]['s'] = isset($value) ? strlen((string) $value) : 0; + self::$hits[self::$count_hits]['s'] = isset($value) ? \strlen((string) $value) : 0; if (empty($value)) { self::$count_misses++; @@ -617,7 +617,7 @@ final public static function get(string $key, int $ttl = 120): mixed } // Export properties to global namespace for backward compatibility. -if (is_callable([CacheApi::class, 'exportStatic'])) { +if (\is_callable([CacheApi::class, 'exportStatic'])) { CacheApi::exportStatic(); } diff --git a/Sources/Cache/CacheApiInterface.php b/Sources/Cache/CacheApiInterface.php index e2435b4fd8..011b3089a2 100644 --- a/Sources/Cache/CacheApiInterface.php +++ b/Sources/Cache/CacheApiInterface.php @@ -15,7 +15,7 @@ namespace SMF\Cache; -if (!defined('SMF')) { +if (!\defined('SMF')) { die('No direct access...'); } diff --git a/Sources/Calendar/Event.php b/Sources/Calendar/Event.php index c1bb14d7c0..d7e9a83b89 100644 --- a/Sources/Calendar/Event.php +++ b/Sources/Calendar/Event.php @@ -493,7 +493,7 @@ public function __construct(int $id = 0, array $props = []) } if (!empty($props['rdates'])) { - $this->rdates = is_array($props['rdates']) ? $props['rdates'] : explode(',', $props['rdates']); + $this->rdates = \is_array($props['rdates']) ? $props['rdates'] : explode(',', $props['rdates']); $vs = $this->view_start->format('Ymd'); $ve = $this->view_end->format('Ymd'); @@ -516,7 +516,7 @@ public function __construct(int $id = 0, array $props = []) } if (!empty($props['exdates'])) { - $this->exdates = is_array($props['exdates']) ? $props['exdates'] : explode(',', $props['exdates']); + $this->exdates = \is_array($props['exdates']) ? $props['exdates'] : explode(',', $props['exdates']); foreach ($this->exdates as $key => $exdate) { $this->exdates[$key] = new \DateTimeImmutable($exdate); @@ -819,7 +819,7 @@ public function export(): string $filecontents[] = 'SEQUENCE:' . $this->sequence; $filecontents[] = 'DTSTAMP:' . date('Ymd\\THis\\Z', $this->modified_time ?? time()); - $filecontents[] = 'DTSTART' . ($this->allday ? ';VALUE=DATE' : (!in_array($this->tz, RRule::UTC_SYNONYMS) ? ';TZID=' . $this->tz : '')) . ':' . $this->start->format('Ymd' . ($this->allday ? '' : '\\THis' . (in_array($this->tz, RRule::UTC_SYNONYMS) ? '\\Z' : ''))); + $filecontents[] = 'DTSTART' . ($this->allday ? ';VALUE=DATE' : (!\in_array($this->tz, RRule::UTC_SYNONYMS) ? ';TZID=' . $this->tz : '')) . ':' . $this->start->format('Ymd' . ($this->allday ? '' : '\\THis' . (\in_array($this->tz, RRule::UTC_SYNONYMS) ? '\\Z' : ''))); $filecontents[] = 'DURATION:' . (string) $this->duration; if ((string) $this->recurrence_iterator->getRRule() !== 'FREQ=YEARLY;COUNT=1') { @@ -1247,7 +1247,7 @@ public function __set(string $prop, mixed $value): void break; case 'rdates': - $this->rdates = is_array($value) ? $value : explode(',', (string) $value); + $this->rdates = \is_array($value) ? $value : explode(',', (string) $value); foreach ($this->rdates as $key => $rdate) { $rdate = explode('/', $rdate); @@ -1260,7 +1260,7 @@ public function __set(string $prop, mixed $value): void break; case 'exdates': - $this->exdates = is_array($value) ? $value : explode(',', (string) $value); + $this->exdates = \is_array($value) ? $value : explode(',', (string) $value); foreach ($this->exdates as $key => $exdate) { $this->exdates[$key] = new \DateTimeImmutable($exdate); @@ -2016,7 +2016,7 @@ public static function foldICalLine(string $line): string $temp = ''; foreach (mb_str_split($line) as $char) { - if (strlen($temp . $char) > 75) { + if (\strlen($temp . $char) > 75) { $folded[] = $temp; $temp = ''; } @@ -2132,7 +2132,7 @@ public static function setRequestedStartAndDuration(array &$eventOptions): void ]; foreach($eventOptions as $key => $value) { - if (is_null($value) || in_array($key, $scalars)) { + if (\is_null($value) || \in_array($key, $scalars)) { unset($eventOptions[$key]); } } @@ -2334,7 +2334,7 @@ protected static function queryData(array $selects, array $params = [], array $j $row = array_diff($row, array_filter($row, 'is_null')); // Is this an all-day event? - $row['allday'] = !isset($row['start_time']) || !isset($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(\DateTimeZone::ALL_WITH_BC)); + $row['allday'] = !isset($row['start_time']) || !isset($row['timezone']) || !\in_array($row['timezone'], timezone_identifiers_list(\DateTimeZone::ALL_WITH_BC)); // Replace start time and date scalars with a Time object. $row['start'] = new Time($row['start_date'] . (!$row['allday'] ? ' ' . $row['start_time'] . ' ' . $row['timezone'] : ' ' . User::getTimezone())); @@ -2399,7 +2399,7 @@ protected static function setRequestedRRule(array &$eventOptions): void unset($_REQUEST['RRULE']); $eventOptions['rrule'] = 'FREQ=YEARLY;COUNT=1'; } - } elseif (in_array($_REQUEST['FREQ'] ?? null, RRule::FREQUENCIES)) { + } elseif (\in_array($_REQUEST['FREQ'] ?? null, RRule::FREQUENCIES)) { $rrule = []; if (isset($_REQUEST['BYDAY_num'], $_REQUEST['BYDAY_name'])) { @@ -2439,7 +2439,7 @@ protected static function setRequestedRRule(array &$eventOptions): void ] as $part ) { if (isset($_REQUEST[$part])) { - if (is_array($_REQUEST[$part])) { + if (\is_array($_REQUEST[$part])) { $rrule[] = $part . '=' . Utils::htmlspecialchars(implode(',', $_REQUEST[$part])); } else { $rrule[] = $part . '=' . Utils::htmlspecialchars($_REQUEST[$part]); @@ -2592,11 +2592,11 @@ protected static function standardizeEventOptions(array $input): array if (isset($datetime_string)) { $datetime_string_parsed = date_parse(str_replace(',', '', Calendar::convertDateToEnglish($datetime_string))); - if (is_array($datetime_string_parsed) && empty($datetime_string_parsed['error_count']) && empty($datetime_string_parsed['warning_count'])) { + if (\is_array($datetime_string_parsed) && empty($datetime_string_parsed['error_count']) && empty($datetime_string_parsed['warning_count'])) { $datetime_string_parsed = array_filter( $datetime_string_parsed, function ($key) { - return in_array($key, ['year', 'month', 'day', 'hour', 'minute', 'second']); + return \in_array($key, ['year', 'month', 'day', 'hour', 'minute', 'second']); }, ARRAY_FILTER_USE_KEY, ); diff --git a/Sources/Calendar/EventOccurrence.php b/Sources/Calendar/EventOccurrence.php index 456441d071..4ec41b476d 100644 --- a/Sources/Calendar/EventOccurrence.php +++ b/Sources/Calendar/EventOccurrence.php @@ -214,7 +214,7 @@ public function export(): string $filecontents[] = 'RECURRENCE-ID' . (isset($this->adjustment) && $this->adjustment->affects_future ? ';RANGE=THISANDFUTURE' : '') . ($this->allday ? ';VALUE=DATE' : '') . ':' . $this->id; $filecontents[] = 'DTSTAMP:' . date('Ymd\\THis\\Z', $this->modified_time ?? time()); - $filecontents[] = 'DTSTART' . ($this->allday ? ';VALUE=DATE' : (!in_array($this->tz, RRule::UTC_SYNONYMS) ? ';TZID=' . $this->tz : '')) . ':' . $this->start->format('Ymd' . ($this->allday ? '' : '\\THis' . (in_array($this->tz, RRule::UTC_SYNONYMS) ? '\\Z' : ''))); + $filecontents[] = 'DTSTART' . ($this->allday ? ';VALUE=DATE' : (!\in_array($this->tz, RRule::UTC_SYNONYMS) ? ';TZID=' . $this->tz : '')) . ':' . $this->start->format('Ymd' . ($this->allday ? '' : '\\THis' . (\in_array($this->tz, RRule::UTC_SYNONYMS) ? '\\Z' : ''))); $filecontents[] = 'DURATION:' . (string) $this->duration; $filecontents[] = 'END:VEVENT'; @@ -482,7 +482,7 @@ public function __get(string $prop): mixed */ public function __isset(string $prop): bool { - if (in_array($prop, ['year', 'month', 'day', 'hour', 'minute', 'second'])) { + if (\in_array($prop, ['year', 'month', 'day', 'hour', 'minute', 'second'])) { $prop = 'start_' . $prop; } diff --git a/Sources/Calendar/Holiday.php b/Sources/Calendar/Holiday.php index 34ecd72bc0..485767e953 100644 --- a/Sources/Calendar/Holiday.php +++ b/Sources/Calendar/Holiday.php @@ -387,7 +387,7 @@ public static function modify(int $id, array &$eventOptions): void if (isset(self::$special_rrules[$_POST['RRULE']])) { $event->special_rrule = $_POST['RRULE']; - if (in_array($event->special_rrule, ['EASTER_W', 'EASTER_E'])) { + if (\in_array($event->special_rrule, ['EASTER_W', 'EASTER_E'])) { $eventOptions['start_date'] = implode('-', self::easter((int) $event->start->format('Y'), $event->special_rrule === 'EASTER_E' ? 'Eastern' : 'Western')); } } diff --git a/Sources/Calendar/RRule.php b/Sources/Calendar/RRule.php index fd93d1203a..5f6c2f8fda 100644 --- a/Sources/Calendar/RRule.php +++ b/Sources/Calendar/RRule.php @@ -221,7 +221,7 @@ public function __construct(string $rrule) } // Parse the RRule into an associative array. - parse_str(strtr($rrule, ';', substr(ini_get('arg_separator.input'), 0, 1)), $rrule); + parse_str(strtr($rrule, ';', substr(\ini_get('arg_separator.input'), 0, 1)), $rrule); // Set initial values of properties. foreach ($rrule as $prop => $value) { @@ -231,7 +231,7 @@ public function __construct(string $rrule) case 'freq': $value = strtoupper($value); - if (!in_array($value, self::FREQUENCIES)) { + if (!\in_array($value, self::FREQUENCIES)) { continue 2; } @@ -240,7 +240,7 @@ public function __construct(string $rrule) case 'wkst': $value = strtoupper($value); - if (!in_array($value, self::WEEKDAYS)) { + if (!\in_array($value, self::WEEKDAYS)) { continue 2; } @@ -252,7 +252,7 @@ public function __construct(string $rrule) if (str_contains($value_part, 'TZID')) { $tzid = str_replace('TZID=', '', $value_part); - if (in_array($tzid, self::UTC_SYNONYMS)) { + if (\in_array($tzid, self::UTC_SYNONYMS)) { $tzid = 'UTC'; } @@ -316,7 +316,7 @@ public function __construct(string $rrule) explode(',', $value), function ($v) { // Simple case. - if (in_array($v, self::WEEKDAYS)) { + if (\in_array($v, self::WEEKDAYS)) { return true; } @@ -385,7 +385,7 @@ function ($a, $b) { } // BYYEARDAY never applies with these frequencies. - if (in_array($this->freq, ['DAILY', 'WEEKLY', 'MONTHLY'])) { + if (\in_array($this->freq, ['DAILY', 'WEEKLY', 'MONTHLY'])) { unset($this->byyearday); } @@ -399,13 +399,13 @@ function ($a, $b) { !empty($this->byday) && ( // Can't have integer modifiers with frequencies besides these. - !in_array($this->freq, ['MONTHLY', 'YEARLY']) + !\in_array($this->freq, ['MONTHLY', 'YEARLY']) // Can't have integer modifiers in combination with BYWEEKNO. || isset($this->byweekno) ) ) { foreach ($this->byday as $value) { - if (!in_array($value, self::WEEKDAYS)) { + if (!\in_array($value, self::WEEKDAYS)) { unset($this->byday); break; } @@ -477,7 +477,7 @@ public function __toString(): string // Skip if default. $value === 'MO' // Skip if irrelevant. - || !in_array($this->freq, ['WEEKLY', 'YEARLY']) + || !\in_array($this->freq, ['WEEKLY', 'YEARLY']) || ($this->freq === 'WEEKLY' && empty($this->byday)) || ($this->freq === 'YEARLY' && empty($this->byweekno)) ) { @@ -513,7 +513,7 @@ public function __toString(): string break; } - if (isset($value) && strlen($value) > 0) { + if (isset($value) && \strlen($value) > 0) { $rrule[] = $part . '=' . $value; } } @@ -547,7 +547,7 @@ public function getDescription(EventOccurrence $occurrence, ?bool $show_start = // When the repetition ends. if (isset($this->until)) { if ( - !in_array($this->freq, ['HOURLY', 'MINUTELY', 'SECONDLY']) + !\in_array($this->freq, ['HOURLY', 'MINUTELY', 'SECONDLY']) && empty($this->byhour) && empty($this->byminute) && empty($this->bysecond) @@ -632,12 +632,12 @@ protected function getDescriptionBySetPos(\DateTimeInterface $start): string && empty($bysecond) ) { if (!empty($this->byday)) { - $days_long_or_short = count($this->byday) > 3 ? 'days_short' : 'days'; + $days_long_or_short = \count($this->byday) > 3 ? 'days_short' : 'days'; $day_names = []; foreach ($this->byday as $day) { - if (in_array($day, self::WEEKDAYS)) { + if (\in_array($day, self::WEEKDAYS)) { $day_names[] = Lang::$txt[$days_long_or_short][(array_search($day, self::WEEKDAYS) + 1) % 7]; } else { $desc_byday = 'calendar_rrule_desc_byday'; @@ -681,7 +681,7 @@ protected function getDescriptionBySetPos(\DateTimeInterface $start): string 'calendar_rrule_desc_bysetpos', [ 'ordinal_list' => Lang::sentenceList($ordinals), - 'count' => count($this->bysetpos), + 'count' => \count($this->bysetpos), 'rrule_description' => implode(' ', $description), ], ); @@ -705,12 +705,12 @@ protected function getDescriptionByDay(\DateTimeInterface $start, array &$descri $desc_byday = ($this->freq === 'YEARLY' && empty($this->byweekno)) || $this->freq === 'MONTHLY' ? 'calendar_rrule_desc_byday_every' : 'calendar_rrule_desc_byday'; - $days_long_or_short = count($this->byday) > 3 ? 'days_short' : 'days'; + $days_long_or_short = \count($this->byday) > 3 ? 'days_short' : 'days'; $day_names = []; foreach ($this->byday as $day) { - if (in_array($day, self::WEEKDAYS)) { + if (\in_array($day, self::WEEKDAYS)) { $day_names[] = Lang::$txt[$days_long_or_short][(array_search($day, self::WEEKDAYS) + 1) % 7]; } else { $desc_byday = 'calendar_rrule_desc_byday'; @@ -800,7 +800,7 @@ protected function getDescriptionByWeekNo(\DateTimeInterface $start, array &$des } $ordinals = array_map(fn ($n) => Lang::getTxt('ordinal_spellout', [$n]), $this->byweekno); - $description['byweekno'] = Lang::getTxt('calendar_rrule_desc_byweekno', ['ordinal_list' => Lang::sentenceList($ordinals), 'count' => count($ordinals)]); + $description['byweekno'] = Lang::getTxt('calendar_rrule_desc_byweekno', ['ordinal_list' => Lang::sentenceList($ordinals), 'count' => \count($ordinals)]); } /** @@ -820,7 +820,7 @@ protected function getDescriptionByYearDay(\DateTimeInterface $start, array &$de } $ordinals = array_map(fn ($n) => Lang::getTxt('ordinal_spellout', [$n]), $this->byyearday); - $description['byeyarday'] = Lang::getTxt('calendar_rrule_desc_byyearday', ['ordinal_list' => Lang::sentenceList($ordinals), 'count' => count($ordinals)]); + $description['byeyarday'] = Lang::getTxt('calendar_rrule_desc_byyearday', ['ordinal_list' => Lang::sentenceList($ordinals), 'count' => \count($ordinals)]); } /** @@ -841,13 +841,13 @@ protected function getDescriptionByMonthDay(\DateTimeInterface $start, array &$d // Special cases for when we have both day names and month days. if ( - count($this->byday ?? []) >= 1 + \count($this->byday ?? []) >= 1 && array_intersect($this->byday, self::WEEKDAYS) === $this->byday ) { - $days_long_or_short = count($this->byday) > 3 ? 'days_short' : 'days'; + $days_long_or_short = \count($this->byday) > 3 ? 'days_short' : 'days'; // "Friday the 13th" - if (count($this->bymonthday) === 1 && count($this->byday) === 1) { + if (\count($this->bymonthday) === 1 && \count($this->byday) === 1) { $named_monthday = Lang::getTxt( 'calendar_rrule_desc_named_monthday', [ @@ -881,7 +881,7 @@ protected function getDescriptionByMonthDay(\DateTimeInterface $start, array &$d $day_names[] = Lang::$txt[$days_long_or_short][(array_search($day_abbrev, self::WEEKDAYS) + 1) % 7]; } - $ordinal_form = max(array_map('abs', $this->bymonthday)) < 10 && count($this->bymonthday) <= 3 ? 'ordinal_spellout' : 'ordinal'; + $ordinal_form = max(array_map('abs', $this->bymonthday)) < 10 && \count($this->bymonthday) <= 3 ? 'ordinal_spellout' : 'ordinal'; $ordinals = array_map(fn ($n) => Lang::getTxt($n < 0 ? $ordinal_form . '_last' : $ordinal_form, [abs($n)]), $this->bymonthday); @@ -902,7 +902,7 @@ protected function getDescriptionByMonthDay(\DateTimeInterface $start, array &$d // Normal case. else { $ordinals = array_map(fn ($n) => Lang::getTxt($n < 0 ? 'ordinal_spellout_last' : 'ordinal_spellout', [abs($n)]), $this->bymonthday); - $description['bymonthday'] = Lang::getTxt('calendar_rrule_desc_bymonthday', ['ordinal_list' => Lang::sentenceList($ordinals), 'count' => count($ordinals)]); + $description['bymonthday'] = Lang::getTxt('calendar_rrule_desc_bymonthday', ['ordinal_list' => Lang::sentenceList($ordinals), 'count' => \count($ordinals)]); } } diff --git a/Sources/Calendar/RecurrenceIterator.php b/Sources/Calendar/RecurrenceIterator.php index 09cee9dae2..15927c2044 100644 --- a/Sources/Calendar/RecurrenceIterator.php +++ b/Sources/Calendar/RecurrenceIterator.php @@ -330,7 +330,7 @@ public function __construct( ) { $this->rrule = $rrule; - $this->type = isset($type) && in_array($type, range(0, 2)) ? $type : ($this->rrule->until_type ?? self::TYPE_ABSOLUTE); + $this->type = isset($type) && \in_array($type, range(0, 2)) ? $type : ($this->rrule->until_type ?? self::TYPE_ABSOLUTE); $this->dtstart = $this->type === self::TYPE_ABSOLUTE ? \DateTimeImmutable::createFromInterface($dtstart) : \DateTime::createFromInterface($dtstart); $this->view_start = $this->type === self::TYPE_ABSOLUTE ? \DateTimeImmutable::createFromInterface($view_start ?? $this->dtstart) : \DateTime::createFromInterface($view_start ?? $this->dtstart); @@ -523,12 +523,12 @@ public function add(\DateTimeInterface $date, ?\DateInterval $duration = null): $string = (clone $date)->setTimezone(new \DateTimeZone('UTC'))->format($this->record_format); - if (in_array($string, $this->occurrences)) { + if (\in_array($string, $this->occurrences)) { return; } // Re-adding a date that was previously removed. - if (in_array($string, $this->exdates)) { + if (\in_array($string, $this->exdates)) { $this->exdates = array_values(array_diff($this->exdates, [$string])); } // Adding a new date. @@ -571,7 +571,7 @@ public function remove(\DateTimeInterface $date): void } } - if (!$is_rdate && !in_array($string, $this->exdates)) { + if (!$is_rdate && !\in_array($string, $this->exdates)) { $this->exdates[] = $string; } @@ -586,7 +586,7 @@ public function remove(\DateTimeInterface $date): void */ public function dateOccurs(\DateTimeInterface $date): bool { - return in_array((clone $date)->setTimezone(new \DateTimeZone('UTC'))->format($this->record_format), $this->occurrences); + return \in_array((clone $date)->setTimezone(new \DateTimeZone('UTC'))->format($this->record_format), $this->occurrences); } /** @@ -776,7 +776,7 @@ private function setFrequencyInterval(): void { $interval_string = 'P'; - if (in_array($this->rrule->freq, ['HOURLY', 'MINUTELY', 'SECONDLY'])) { + if (\in_array($this->rrule->freq, ['HOURLY', 'MINUTELY', 'SECONDLY'])) { $interval_string .= 'T'; } @@ -803,7 +803,7 @@ private function record(\DateTimeInterface $occurrence): bool $string = (clone $occurrence)->setTimezone(new \DateTimeZone('UTC'))->format($this->record_format); // If it is already in the array, don't add it. - if (in_array($string, $this->occurrences)) { + if (\in_array($string, $this->occurrences)) { return false; } @@ -817,7 +817,7 @@ private function record(\DateTimeInterface $occurrence): bool } // If we don't need to truncate the array, return true now. - if ($this->max_occurrences >= count($this->occurrences)) { + if ($this->max_occurrences >= \count($this->occurrences)) { return true; } @@ -825,7 +825,7 @@ private function record(\DateTimeInterface $occurrence): bool array_splice($this->occurrences, $this->max_occurrences); // Is this occurrence still in the array? - return in_array($string, $this->occurrences); + return \in_array($string, $this->occurrences); } /** @@ -848,7 +848,7 @@ private function calculate(): void $current <= $this->limit_after && ( !empty($this->rrule->bysetpos) - || count($this->occurrences) < $max + || \count($this->occurrences) < $max ) ) { if ($current < $this->view_start) { @@ -899,7 +899,7 @@ private function calculate(): void fn ($occurrence) => $view_start <= $occurrence && $view_end >= $occurrence, )); - if ($this->max_occurrences < count($this->occurrences)) { + if ($this->max_occurrences < \count($this->occurrences)) { array_splice($this->occurrences, $this->max_occurrences); } } @@ -931,7 +931,7 @@ private function jumpToVisible(\DateTime &$current): void (int) $this->view_start->format('d'), ); - while (!in_array(strtoupper(substr($current->format('D'), 0, 2)), $weekdays)) { + while (!\in_array(strtoupper(substr($current->format('D'), 0, 2)), $weekdays)) { $current->modify('-1 day'); } @@ -944,7 +944,7 @@ private function jumpToVisible(\DateTime &$current): void continue; } - if (!empty($this->rrule->{$prop}) && count($this->rrule->{$prop}) > 1) { + if (!empty($this->rrule->{$prop}) && \count($this->rrule->{$prop}) > 1) { return; } } @@ -1093,7 +1093,7 @@ private function limit(\DateTime $current): bool break; } - $valid &= in_array($current_value, $allowed_values); + $valid &= \in_array($current_value, $allowed_values); } return (bool) $valid; @@ -1170,7 +1170,7 @@ private function limitBySetPos(): void foreach ($groups as $group_key => $strings) { foreach ($bysetpos as $setpos) { - $occurrences = array_merge($occurrences, array_slice($strings, $setpos, 1)); + $occurrences = array_merge($occurrences, \array_slice($strings, $setpos, 1)); } } @@ -1408,7 +1408,7 @@ private function expandMonthByDay(\DateTime $current, array $expansion_values, s if ($this->frequency_interval->m === 1) { $upperlimit->add($this->frequency_interval); - } elseif (!empty($this->rrule->bymonth) && in_array((($upperlimit->format('m') + 1) % 12), $this->rrule->bymonth)) { + } elseif (!empty($this->rrule->bymonth) && \in_array((($upperlimit->format('m') + 1) % 12), $this->rrule->bymonth)) { $upperlimit->modify('last day of ' . $upperlimit->format('F H:i:s e')); $upperlimit->modify('+ 1 day'); } else { @@ -1460,7 +1460,7 @@ private function expandMonthByDay(\DateTime $current, array $expansion_values, s } } - if ($key === count($expansion_values) - 1) { + if ($key === \count($expansion_values) - 1) { break; } } @@ -1489,7 +1489,7 @@ private function expandMonthByDay(\DateTime $current, array $expansion_values, s } } - if ($key === count($expansion_values) - 1) { + if ($key === \count($expansion_values) - 1) { break; } } @@ -1517,7 +1517,7 @@ private function expandMonthByDay(\DateTime $current, array $expansion_values, s } $key++; - $key %= count($expansion_values); + $key %= \count($expansion_values); $i++; } } @@ -1622,7 +1622,7 @@ private function expandYearByDay(\DateTime $current, array $expansion_values, st } $key++; - $key %= count($expansion_values); + $key %= \count($expansion_values); } } diff --git a/Sources/Category.php b/Sources/Category.php index 53b910d967..4c8cd1365d 100644 --- a/Sources/Category.php +++ b/Sources/Category.php @@ -542,7 +542,7 @@ public static function delete(array $categories, ?int $moveBoardsTo = null): voi } } // Make sure the safe category is really safe. - elseif (in_array($moveBoardsTo, $categories)) { + elseif (\in_array($moveBoardsTo, $categories)) { Lang::load('Errors'); trigger_error(Lang::$txt['cannot_move_to_deleted_category'], E_USER_ERROR); } @@ -594,9 +594,9 @@ public static function sort(array &$categories): void if (!empty($categories[$cat])) { $ordered[$cat] = $categories[$cat]; - if (is_array($ordered[$cat]) && !empty($ordered[$cat]['boards'])) { + if (\is_array($ordered[$cat]) && !empty($ordered[$cat]['boards'])) { Board::sort($ordered[$cat]['boards']); - } elseif (is_object($ordered[$cat]) && !empty($ordered[$cat]->children)) { + } elseif (\is_object($ordered[$cat]) && !empty($ordered[$cat]->children)) { Board::sort($ordered[$cat]->children); } } @@ -632,7 +632,7 @@ public static function getTreeOrder(): array ); foreach (Db::$db->fetch_all($request) as $row) { - if (!in_array($row['id_cat'], self::$tree_order['cats'])) { + if (!\in_array($row['id_cat'], self::$tree_order['cats'])) { self::$tree_order['cats'][] = $row['id_cat']; } @@ -822,7 +822,7 @@ protected function __construct(int $id, array $props = []) $this->set($props); self::$loaded[$this->id] = $this; - if (count(self::$loaded) > 1) { + if (\count(self::$loaded) > 1) { uasort( self::$loaded, function ($a, $b) { @@ -888,7 +888,7 @@ protected static function queryData(array $selects, array $params = [], array $j } // Export properties to global namespace for backward compatibility. -if (is_callable([Category::class, 'exportStatic'])) { +if (\is_callable([Category::class, 'exportStatic'])) { Category::exportStatic(); } diff --git a/Sources/Config.php b/Sources/Config.php index 2b63cb6985..e5aa219483 100644 --- a/Sources/Config.php +++ b/Sources/Config.php @@ -881,7 +881,7 @@ class Config public static function load(): void { // Load Settings.php. - if (!in_array(SMF_SETTINGS_FILE, get_included_files())) { + if (!\in_array(SMF_SETTINGS_FILE, get_included_files())) { require SMF_SETTINGS_FILE; } // If it has already been included, make sure to avoid possible problems @@ -913,11 +913,11 @@ public static function set(array $settings): void $class_vars = get_class_vars(__CLASS__); foreach ($class_vars['settings_defs'] as $var => $def) { - if (is_string($var) && property_exists(__CLASS__, $var) && !isset(self::${$var})) { + if (\is_string($var) && property_exists(__CLASS__, $var) && !isset(self::${$var})) { if (!empty($def['raw_default'])) { $default = strtr($def['default'], [ '__FILE__' => var_export(SMF_SETTINGS_FILE, true), - '__DIR__' => var_export(dirname(SMF_SETTINGS_FILE), true), + '__DIR__' => var_export(\dirname(SMF_SETTINGS_FILE), true), ]); self::${$var} = eval($default . ';'); @@ -932,14 +932,14 @@ public static function set(array $settings): void // Ensure there are no trailing slashes in these settings. foreach (['boardurl', 'boarddir', 'sourcedir', 'packagesdir', 'cachedir', 'languagesdir'] as $var) { - if (!is_null(self::${$var})) { + if (!\is_null(self::${$var})) { self::${$var} = rtrim(self::${$var}, '\\/'); } } // Make sure the paths are correct... at least try to fix them. if (empty(self::$boarddir) || !is_dir(realpath(self::$boarddir))) { - self::$boarddir = !empty($_SERVER['SCRIPT_FILENAME']) ? dirname(realpath($_SERVER['SCRIPT_FILENAME'])) : dirname(__DIR__); + self::$boarddir = !empty($_SERVER['SCRIPT_FILENAME']) ? \dirname(realpath($_SERVER['SCRIPT_FILENAME'])) : \dirname(__DIR__); } if ((empty(self::$sourcedir) || !is_dir(realpath(self::$sourcedir))) && is_dir(self::$boarddir . '/Sources')) { @@ -1048,7 +1048,7 @@ public static function reloadModSettings(): void self::$modSettings['defaultMaxListItems'] = 15; } - if (!is_array(self::$modSettings['attachmentUploadDir'])) { + if (!\is_array(self::$modSettings['attachmentUploadDir'])) { $attachmentUploadDir = Utils::jsonDecode(self::$modSettings['attachmentUploadDir'], true, 512, 0, false); self::$modSettings['attachmentUploadDir'] = !empty($attachmentUploadDir) ? $attachmentUploadDir : self::$modSettings['attachmentUploadDir']; @@ -1061,7 +1061,7 @@ public static function reloadModSettings(): void // Going anything further when the files don't match the database can make nasty messes (unless we're actively installing or upgrading) if ( - !defined('SMF_INSTALLING') + !\defined('SMF_INSTALLING') && ( !isset($_REQUEST['action']) || $_REQUEST['action'] !== 'admin' @@ -1097,16 +1097,16 @@ public static function reloadModSettings(): void } // Setting the timezone is a requirement for some functions. - if (isset(self::$modSettings['default_timezone']) && in_array(self::$modSettings['default_timezone'], timezone_identifiers_list())) { + if (isset(self::$modSettings['default_timezone']) && \in_array(self::$modSettings['default_timezone'], timezone_identifiers_list())) { date_default_timezone_set(self::$modSettings['default_timezone']); } else { // Get PHP's default timezone, if set - $ini_tz = ini_get('date.timezone'); + $ini_tz = \ini_get('date.timezone'); self::$modSettings['default_timezone'] = !empty($ini_tz) ? $ini_tz : ''; // If date.timezone is unset, invalid, or just plain weird, make a best guess - if (!in_array(self::$modSettings['default_timezone'], timezone_identifiers_list())) { + if (!\in_array(self::$modSettings['default_timezone'], timezone_identifiers_list())) { $server_offset = @mktime(0, 0, 0, 1, 1, 1970) * -1; self::$modSettings['default_timezone'] = timezone_name_from_abbr('', $server_offset, 0); @@ -1171,14 +1171,14 @@ public static function reloadModSettings(): void } // Respect PHP's limits. - $post_max_kb = floor(Sapi::memoryReturnBytes(ini_get('post_max_size')) / 1024); - $file_max_kb = floor(Sapi::memoryReturnBytes(ini_get('upload_max_filesize')) / 1024); + $post_max_kb = floor(Sapi::memoryReturnBytes(\ini_get('post_max_size')) / 1024); + $file_max_kb = floor(Sapi::memoryReturnBytes(\ini_get('upload_max_filesize')) / 1024); self::$modSettings['attachmentPostLimit'] = empty(self::$modSettings['attachmentPostLimit']) ? $post_max_kb : min(self::$modSettings['attachmentPostLimit'], $post_max_kb); self::$modSettings['attachmentSizeLimit'] = empty(self::$modSettings['attachmentSizeLimit']) ? $file_max_kb : min(self::$modSettings['attachmentSizeLimit'], $file_max_kb); self::$modSettings['attachmentNumPerPostLimit'] = !isset(self::$modSettings['attachmentNumPerPostLimit']) ? 4 : self::$modSettings['attachmentNumPerPostLimit']; // Integration is cool. - if (defined('SMF_INTEGRATION_SETTINGS')) { + if (\defined('SMF_INTEGRATION_SETTINGS')) { $integration_settings = Utils::jsonDecode(SMF_INTEGRATION_SETTINGS, true); foreach ($integration_settings as $hook => $function) { @@ -1225,7 +1225,7 @@ public static function reloadModSettings(): void */ public static function updateModSettings(array $change_array, bool $update = false): void { - if (empty($change_array) || !is_array($change_array)) { + if (empty($change_array) || !\is_array($change_array)) { return; } @@ -1413,7 +1413,7 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes if (isset($config_vars['db_last_error'])) { self::updateDbLastError($config_vars['db_last_error']); - if (count($config_vars) === 1 && empty($rebuild)) { + if (\count($config_vars) === 1 && empty($rebuild)) { return true; } @@ -1422,21 +1422,21 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes } // Rebuilding should not be undertaken lightly, so we're picky about the parameter. - if (!is_bool($rebuild)) { + if (!\is_bool($rebuild)) { $rebuild = false; } - $mtime = isset($mtime) ? (int) $mtime : (defined('TIME_START') ? TIME_START : $_SERVER['REQUEST_TIME']); + $mtime = isset($mtime) ? (int) $mtime : (\defined('TIME_START') ? TIME_START : $_SERVER['REQUEST_TIME']); /***************** * PART 1: Setup * *****************/ // Is Settings.php where we expect it to be, or do we need to find it? - if (defined('SMF_SETTINGS_FILE') && is_file(SMF_SETTINGS_FILE)) { + if (\defined('SMF_SETTINGS_FILE') && is_file(SMF_SETTINGS_FILE)) { $settingsFile = SMF_SETTINGS_FILE; - $backupFile = defined('SMF_SETTINGS_BACKUP_FILE') ? SMF_SETTINGS_BACKUP_FILE : dirname(SMF_SETTINGS_FILE) . DIRECTORY_SEPARATOR . pathinfo(SMF_SETTINGS_FILE, PATHINFO_FILENAME) . '_bak.php'; + $backupFile = \defined('SMF_SETTINGS_BACKUP_FILE') ? SMF_SETTINGS_BACKUP_FILE : \dirname(SMF_SETTINGS_FILE) . DIRECTORY_SEPARATOR . pathinfo(SMF_SETTINGS_FILE, PATHINFO_FILENAME) . '_bak.php'; } else { foreach (get_included_files() as $settingsFile) { if (basename($settingsFile) === 'Settings.php') { @@ -1446,10 +1446,10 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes // Fallback in case Settings.php isn't loaded (e.g. while installing) if (basename($settingsFile) !== 'Settings.php') { - $settingsFile = (!empty(self::$boarddir) && @realpath(self::$boarddir) ? self::$boarddir : (!empty($_SERVER['SCRIPT_FILENAME']) ? dirname($_SERVER['SCRIPT_FILENAME']) : dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'Settings.php'; + $settingsFile = (!empty(self::$boarddir) && @realpath(self::$boarddir) ? self::$boarddir : (!empty($_SERVER['SCRIPT_FILENAME']) ? \dirname($_SERVER['SCRIPT_FILENAME']) : \dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'Settings.php'; } - $backupFile = dirname($settingsFile) . DIRECTORY_SEPARATOR . pathinfo($settingsFile, PATHINFO_FILENAME) . '_bak.php'; + $backupFile = \dirname($settingsFile) . DIRECTORY_SEPARATOR . pathinfo($settingsFile, PATHINFO_FILENAME) . '_bak.php'; } // File not found? Attempt an emergency on-the-fly fix! @@ -1494,9 +1494,9 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes } // During install/upgrade, don't set anything until we're ready for it. - if (defined('SMF_INSTALLING') && empty($rebuild)) { + if (\defined('SMF_INSTALLING') && empty($rebuild)) { foreach ($settings_defs as $var => $setting_def) { - if (!in_array($var, array_keys($new_settings_vars)) && !is_int($var)) { + if (!\in_array($var, array_keys($new_settings_vars)) && !\is_int($var)) { unset($settings_defs[$var]); } } @@ -1614,11 +1614,11 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes } } - if (is_string($var)) { + if (\is_string($var)) { // Ensure the value is good. - if (in_array($var, array_keys($new_settings_vars))) { + if (\in_array($var, array_keys($new_settings_vars))) { // Objects without a __set_state method need a fallback. - if (is_object($new_settings_vars[$var]) && !method_exists($new_settings_vars[$var], '__set_state')) { + if (\is_object($new_settings_vars[$var]) && !method_exists($new_settings_vars[$var], '__set_state')) { if (method_exists($new_settings_vars[$var], '__toString')) { $new_settings_vars[$var] = (string) $new_settings_vars[$var]; } else { @@ -1629,20 +1629,20 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes // Normalize the type if necessary. if (isset($setting_def['type'])) { $expected_types = (array) $setting_def['type']; - $var_type = gettype($new_settings_vars[$var]); + $var_type = \gettype($new_settings_vars[$var]); // Variable is not of an expected type. - if (!in_array($var_type, $expected_types)) { + if (!\in_array($var_type, $expected_types)) { // Passed in an unexpected array. if ($var_type == 'array') { $temp = reset($new_settings_vars[$var]); // Use the first element if there's only one and it is a scalar. - if (count($new_settings_vars[$var]) === 1 && is_scalar($temp)) { + if (\count($new_settings_vars[$var]) === 1 && \is_scalar($temp)) { $new_settings_vars[$var] = $temp; } // Or keep the old value, if that is good. - elseif (isset($settings_vars[$var]) && in_array(gettype($settings_vars[$var]), $expected_types)) { + elseif (isset($settings_vars[$var]) && \in_array(\gettype($settings_vars[$var]), $expected_types)) { $new_settings_vars[$var] = $settings_vars[$var]; } // Fall back to the default @@ -1654,7 +1654,7 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes // Cast it to whatever type was expected. // Note: the order of the types in this loop matters. foreach (['boolean', 'integer', 'double', 'string', 'array'] as $to_type) { - if (in_array($to_type, $expected_types)) { + if (\in_array($to_type, $expected_types)) { settype($new_settings_vars[$var], $to_type); break; } @@ -1663,7 +1663,7 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes } } // Abort if a required one is undefined (unless we're installing). - elseif (!empty($setting_def['required']) && !defined('SMF_INSTALLING')) { + elseif (!empty($setting_def['required']) && !\defined('SMF_INSTALLING')) { return false; } @@ -1679,16 +1679,16 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes } } - if (in_array($var, array_keys($config_vars))) { - $var_pattern[] = @$type_regex[gettype($config_vars[$var])]; + if (\in_array($var, array_keys($config_vars))) { + $var_pattern[] = @$type_regex[\gettype($config_vars[$var])]; if (is_string($config_vars[$var]) && str_starts_with($config_vars[$var], dirname($settingsFile))) { $var_pattern[] = '(?:__DIR__|dirname\(__FILE__\)) . \'' . (preg_quote(str_replace(dirname($settingsFile), '', $config_vars[$var]), '~')) . '\''; } } - if (in_array($var, array_keys($settings_vars))) { - $var_pattern[] = @$type_regex[gettype($settings_vars[$var])]; + if (\in_array($var, array_keys($settings_vars))) { + $var_pattern[] = @$type_regex[\gettype($settings_vars[$var])]; if (is_string($settings_vars[$var]) && str_starts_with($settings_vars[$var], dirname($settingsFile))) { $var_pattern[] = '(?:__DIR__|dirname\(__FILE__\)) . \'' . (preg_quote(str_replace(dirname($settingsFile), '', $settings_vars[$var]), '~')) . '\''; @@ -1709,7 +1709,7 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes $var_pattern = array_unique($var_pattern); - $var_pattern = count($var_pattern) > 1 ? '(?:' . (implode('|', $var_pattern)) . ')' : $var_pattern[0]; + $var_pattern = \count($var_pattern) > 1 ? '(?:' . (implode('|', $var_pattern)) . ')' : $var_pattern[0]; $substitutions[$var]['search_pattern'] = '~(?<=^|\s)\h*\$' . preg_quote($var, '~') . '\s*=\s*' . $var_pattern . ';~' . (!empty($utf8) ? 'u' : ''); } @@ -1724,7 +1724,7 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes // Now create the replacement. // A setting to delete. if (!empty($setting_def['auto_delete']) && empty($new_settings_vars[$var])) { - if ($setting_def['auto_delete'] === 2 && empty($rebuild) && in_array($var, array_keys($new_settings_vars))) { + if ($setting_def['auto_delete'] === 2 && empty($rebuild) && \in_array($var, array_keys($new_settings_vars))) { $replacement .= '$' . $var . ' = ' . ($new_settings_vars[$var] === $setting_def['default'] && !empty($setting_def['raw_default']) ? sprintf($new_settings_vars[$var]) : self::varExport($new_settings_vars[$var])) . ';'; } else { $replacement = ''; @@ -1735,7 +1735,7 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes } } // Add this setting's value. - elseif (in_array($var, array_keys($new_settings_vars))) { + elseif (\in_array($var, array_keys($new_settings_vars))) { $replacement .= '$' . $var . ' = ' . ($new_settings_vars[$var] === $setting_def['default'] && !empty($setting_def['raw_default']) ? sprintf($new_settings_vars[$var]) : self::varExport($new_settings_vars[$var])) . ';'; } // Fall back to the default value. @@ -1758,17 +1758,17 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes foreach ($new_settings_vars as $var => $val) { $var_pattern = []; - if (in_array($var, array_keys($config_vars))) { - $var_pattern[] = $type_regex[gettype($config_vars[$var])]; + if (\in_array($var, array_keys($config_vars))) { + $var_pattern[] = $type_regex[\gettype($config_vars[$var])]; } - if (in_array($var, array_keys($settings_vars))) { - $var_pattern[] = $type_regex[gettype($settings_vars[$var])]; + if (\in_array($var, array_keys($settings_vars))) { + $var_pattern[] = $type_regex[\gettype($settings_vars[$var])]; } $var_pattern = array_unique($var_pattern); - $var_pattern = count($var_pattern) > 1 ? '(?:' . (implode('|', $var_pattern)) . ')' : $var_pattern[0]; + $var_pattern = \count($var_pattern) > 1 ? '(?:' . (implode('|', $var_pattern)) . ')' : $var_pattern[0]; $placeholder = md5($prefix . $var); @@ -1781,15 +1781,15 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes uksort( $substitutions, function ($a, $b) { - if (is_int($a) && is_int($b)) { + if (\is_int($a) && \is_int($b)) { return $a > $b ? 1 : ($a < $b ? -1 : 0); } - if (is_int($a)) { + if (\is_int($a)) { return -1; } - if (is_int($b)) { + if (\is_int($b)) { return 1; } @@ -1864,8 +1864,8 @@ function ($a, $b) { if (is_string($var) && count($matches[0]) !== 1 && $substitution['replacement'] !== '') { // More than one instance of the variable = not good. - if (count($matches[0]) > 1) { - if (is_string($var)) { + if (\count($matches[0]) > 1) { + if (\is_string($var)) { // Maybe we can try something more interesting? $sp = substr($substitution['search_pattern'], 1); @@ -1887,10 +1887,10 @@ function ($a, $b) { } // Found at least some that are simple assignment statements. - if (count($matches[0]) > 0) { + if (\count($matches[0]) > 0) { // Remove any duplicates. - if (count($matches[0]) > 1) { - $settingsText = preg_replace($sp, '', $settingsText, count($matches[0]) - 1); + if (\count($matches[0]) > 1) { + $settingsText = preg_replace($sp, '', $settingsText, \count($matches[0]) - 1); } // Insert placeholder for the last one. @@ -1906,10 +1906,10 @@ function ($a, $b) { } } // No matches found. - elseif (count($matches[0]) === 0) { + elseif (\count($matches[0]) === 0) { $found = false; - $in_c = in_array($var, array_keys($config_vars)); - $in_s = in_array($var, array_keys($settings_vars)); + $in_c = \in_array($var, array_keys($config_vars)); + $in_s = \in_array($var, array_keys($settings_vars)); // Is it in there at all? if (!preg_match('~(^|\s)\$' . preg_quote($var, '~') . '\s*=\s*~', $bare_settingsText)) { @@ -1931,7 +1931,7 @@ function ($a, $b) { foreach (['scalar', 'object', 'array'] as $type) { // Try all the other scalar types first. if ($type == 'scalar') { - $sp = '(?:' . (implode('|', array_diff_key($type_regex, [$in_c ? gettype($config_vars[$var]) : ($in_s ? gettype($settings_vars[$var]) : PHP_INT_MAX) => '', 'array' => '', 'object' => '']))) . ')'; + $sp = '(?:' . (implode('|', array_diff_key($type_regex, [$in_c ? \gettype($config_vars[$var]) : ($in_s ? \gettype($settings_vars[$var]) : PHP_INT_MAX) => '', 'array' => '', 'object' => '']))) . ')'; } // Maybe it's an object? (Probably not, but we should check.) elseif ($type == 'object') { @@ -1970,7 +1970,7 @@ function ($a, $b) { } // Once the code blocks are done, we want to compare to a version without comments. - if (is_int($last_var) && is_string($var)) { + if (\is_int($last_var) && \is_string($var)) { $bare_settingsText = self::stripPhpComments($settingsText); } @@ -2026,7 +2026,7 @@ function ($a, $b) { } // Build a list of placeholders for this section. - if (in_array($part, $trimmed_placeholders) && !in_array($part, $newsection_placeholders)) { + if (\in_array($part, $trimmed_placeholders) && !\in_array($part, $newsection_placeholders)) { $sections[$section_num][] = $part; } // Custom content and newsection_placeholders get their own sections. @@ -2039,7 +2039,7 @@ function ($a, $b) { ++$section_num; - if (!in_array($part, $trimmed_placeholders)) { + if (!\in_array($part, $trimmed_placeholders)) { $all_custom_content .= "\n" . $part; } } @@ -2052,9 +2052,9 @@ function ($a, $b) { foreach ($sections as $sectionkey => $section) { // Custom content needs to be preserved. - if (count($section) === 1 && !in_array($section[0], $trimmed_placeholders)) { - $prev_section_end = $sectionkey < 1 ? 0 : strpos($settingsText, end($sections[$sectionkey - 1])) + strlen(end($sections[$sectionkey - 1])); - $next_section_start = $sectionkey == end($sectionkeys) ? strlen($settingsText) : strpos($settingsText, $sections[$sectionkey + 1][0]); + if (\count($section) === 1 && !\in_array($section[0], $trimmed_placeholders)) { + $prev_section_end = $sectionkey < 1 ? 0 : strpos($settingsText, end($sections[$sectionkey - 1])) + \strlen(end($sections[$sectionkey - 1])); + $next_section_start = $sectionkey == end($sectionkeys) ? \strlen($settingsText) : strpos($settingsText, $sections[$sectionkey + 1][0]); $new_settingsText .= "\n" . substr($settingsText, $prev_section_end, $next_section_start - $prev_section_end) . "\n"; } @@ -2065,18 +2065,18 @@ function ($a, $b) { foreach ($settings_defs as $var => $setting_def) { // Already did this setting, so move on to the next. - if (in_array($var, $done_defs)) { + if (\in_array($var, $done_defs)) { continue; } // Stop when we hit a setting definition that will start a later section. - if (isset($newsection_placeholders[$var]) && count($section) !== 1) { + if (isset($newsection_placeholders[$var]) && \count($section) !== 1) { break; } // Stop when everything in this section is done, unless it's the last. // This helps maintain the relative position of any custom content. - if (empty($section_parts) && $sectionkey < (count($sections) - 1)) { + if (empty($section_parts) && $sectionkey < (\count($sections) - 1)) { break; } @@ -2136,7 +2136,7 @@ function ($a, $b) { $bare_settingsText = $settingsText; foreach ($substitutions as $var => $substitution) { - if (!is_int($var)) { + if (!\is_int($var)) { break; } @@ -2179,7 +2179,7 @@ function ($a, $b) { continue; } - $before = is_int($prev_var) ? preg_quote($settings_defs[$prev_var]['text'], '~') . '\s*\K' : ''; + $before = \is_int($prev_var) ? preg_quote($settings_defs[$prev_var]['text'], '~') . '\s*\K' : ''; // If this setting's comment is immediately preceded by another // DocBlock comment, remove the preceding one. @@ -2247,7 +2247,7 @@ function ($a, $b) { */ public static function getCurrentSettings(int|float|null $mtime = null, string $settingsFile = SMF_SETTINGS_FILE): array|bool { - $mtime = is_null($mtime) ? (defined('TIME_START') ? TIME_START : $_SERVER['REQUEST_TIME']) : (int) $mtime; + $mtime = \is_null($mtime) ? (\defined('TIME_START') ? TIME_START : $_SERVER['REQUEST_TIME']) : (int) $mtime; if (!is_file($settingsFile)) { if ($settingsFile !== SMF_SETTINGS_FILE && is_file(SMF_SETTINGS_FILE)) { @@ -2286,7 +2286,7 @@ public static function getCurrentSettings(int|float|null $mtime = null, string $ // Since we're using eval, we need to manually replace these with strings. $settingsText = strtr($settingsText, [ '__FILE__' => var_export($settingsFile, true), - '__DIR__' => var_export(dirname($settingsFile), true), + '__DIR__' => var_export(\dirname($settingsFile), true), ]); // Prevents warnings about constants that are already defined. @@ -2336,12 +2336,12 @@ function ($matches) { public static function safeFileWrite(string $file, string $data, ?string $backup_file = null, ?int $mtime = null, bool $append = false): bool { // Sanity checks. - if (!file_exists($file) && !is_dir(dirname($file))) { + if (!file_exists($file) && !is_dir(\dirname($file))) { return false; } - if (!is_int($mtime)) { - $mtime = defined('TIME_START') ? (int) TIME_START : $_SERVER['REQUEST_TIME']; + if (!\is_int($mtime)) { + $mtime = \defined('TIME_START') ? (int) TIME_START : $_SERVER['REQUEST_TIME']; } $temp_dir = self::getTempDir(); @@ -2373,7 +2373,7 @@ public static function safeFileWrite(string $file, string $data, ?string $backup } // Now let's see if writing to a temp file succeeds. - if (!$failed && file_put_contents($temp_sfile, $data, LOCK_EX) !== strlen($data)) { + if (!$failed && file_put_contents($temp_sfile, $data, LOCK_EX) !== \strlen($data)) { $failed = true; } @@ -2406,7 +2406,7 @@ public static function safeFileWrite(string $file, string $data, ?string $backup rewind($sfhandle); } - $failed = fwrite($sfhandle, $data) !== strlen($data); + $failed = fwrite($sfhandle, $data) !== \strlen($data); } else { $failed = true; } @@ -2447,7 +2447,7 @@ public static function safeFileWrite(string $file, string $data, ?string $backup // Even though on normal installations the filemtime should invalidate // any cached version, it seems that there are times it might not. // So let's MAKE it dump the cache. - if (function_exists('opcache_invalidate')) { + if (\function_exists('opcache_invalidate')) { opcache_invalidate($file, true); } @@ -2474,7 +2474,7 @@ public static function varExport(mixed $var): string static $object_recursion = 0; // Objects. - if (is_object($var)) { + if (\is_object($var)) { // First, check for object recursion. try { $prev_error_handler = set_error_handler(function ($errno, $errstr, $errfile, $errline) { @@ -2527,7 +2527,7 @@ public static function varExport(mixed $var): string } // Arrays. We like tab indentation and short array syntax. - if (is_array($var)) { + if (\is_array($var)) { $return = []; $is_simple_list = array_is_list($var) && $var === array_filter($var, 'is_scalar'); @@ -2567,7 +2567,7 @@ public static function varExport(mixed $var): string } // We typically use lowercase true/false/null. - if (in_array(gettype($var), ['boolean', 'NULL'])) { + if (\in_array(\gettype($var), ['boolean', 'NULL'])) { return strtolower(var_export($var, true)); } @@ -2584,13 +2584,13 @@ public static function varExport(mixed $var): string public static function stripPhpComments(string $code_str): string { // This is the faster, better way. - if (is_callable('token_get_all')) { + if (\is_callable('token_get_all')) { $tokens = token_get_all($code_str); $parts = []; foreach ($tokens as $token) { - if (is_string($token)) { + if (\is_string($token)) { $parts[] = $token; } else { list($id, $text) = $token; @@ -2610,7 +2610,7 @@ public static function stripPhpComments(string $code_str): string if (str_starts_with($text, '/*')) { if (str_ends_with($parts[$prev_part], "\r\n")) { $parts[$prev_part] = substr($parts[$prev_part], 0, -2); - } elseif (in_array(substr($parts[$prev_part], -1), ["\r", "\n"])) { + } elseif (\in_array(substr($parts[$prev_part], -1), ["\r", "\n"])) { $parts[$prev_part] = substr($parts[$prev_part], 0, -1); } } @@ -2662,13 +2662,13 @@ public static function stripPhpComments(string $code_str): string if ($one_char == "'") { if (!empty($in_comment)) { $in_string = 0; - } elseif (in_array($in_string, [0, 1])) { + } elseif (\in_array($in_string, [0, 1])) { $in_string = ($in_string ^ 1); } } elseif ($one_char == '"') { if (!empty($in_comment)) { $in_string = 0; - } elseif (in_array($in_string, [0, 2])) { + } elseif (\in_array($in_string, [0, 2])) { $in_string = ($in_string ^ 2); } } @@ -2687,7 +2687,7 @@ public static function stripPhpComments(string $code_str): string if (substr($parts[$partkey - 1], -2) === "\r\n") { $parts[$partkey - 1] = substr($parts[$partkey - 1], 0, -2); - } elseif (in_array(substr($parts[$partkey - 1], -1), ["\r", "\n"])) { + } elseif (\in_array(substr($parts[$partkey - 1], -1), ["\r", "\n"])) { $parts[$partkey - 1] = substr($parts[$partkey - 1], 0, -1); } } @@ -2703,7 +2703,7 @@ public static function stripPhpComments(string $code_str): string if (substr($parts[$partkey - 1], -2) === "\r\n") { $parts[$partkey - 1] = substr($parts[$partkey - 1], 0, -2); - } elseif (in_array(substr($parts[$partkey - 1], -1), ["\r", "\n"])) { + } elseif (\in_array(substr($parts[$partkey - 1], -1), ["\r", "\n"])) { $parts[$partkey - 1] = substr($parts[$partkey - 1], 0, -1); } } @@ -2717,7 +2717,7 @@ public static function stripPhpComments(string $code_str): string } if (empty($in_comment)) { - $parts[$partkey] = strlen($part) > $to_remove ? substr($part, $to_remove) : ''; + $parts[$partkey] = \strlen($part) > $to_remove ? substr($part, $to_remove) : ''; } else { $parts[$partkey] = ''; } @@ -2825,7 +2825,7 @@ public static function getTempDir(): string } // Determine if we should detect a restriction and what restrictions that may be. - $open_base_dir = ini_get('open_basedir'); + $open_base_dir = \ini_get('open_basedir'); $restriction = !empty($open_base_dir) ? explode(':', $open_base_dir) : false; // Prevent any errors as we search. @@ -2839,11 +2839,11 @@ public static function getTempDir(): string break; case 'session.save_path': - $possible_temp = rtrim(ini_get('session.save_path'), '\\/'); + $possible_temp = rtrim(\ini_get('session.save_path'), '\\/'); break; case 'upload_tmp_dir': - $possible_temp = rtrim(ini_get('upload_tmp_dir'), '\\/'); + $possible_temp = rtrim(\ini_get('upload_tmp_dir'), '\\/'); break; default: @@ -2898,7 +2898,7 @@ public static function generateSeed(): void */ public static function checkCron(): void { - if (!empty(self::$modSettings['cron_is_real_cron']) && time() - @intval(self::$modSettings['cron_last_checked']) > 86400) { + if (!empty(self::$modSettings['cron_is_real_cron']) && time() - @\intval(self::$modSettings['cron_last_checked']) > 86400) { $request = Db\DatabaseApi::$db->query( '', 'SELECT COUNT(*) diff --git a/Sources/Cookie.php b/Sources/Cookie.php index a1de08408e..fe2cec04a4 100644 --- a/Sources/Cookie.php +++ b/Sources/Cookie.php @@ -163,7 +163,7 @@ public function __construct( $this->custom_data = $custom_data ?? []; // Special case for the login and TFA cookies. - if (in_array($this->name, [Config::$cookiename, Config::$cookiename . '_tfa'])) { + if (\in_array($this->name, [Config::$cookiename, Config::$cookiename . '_tfa'])) { $this->member = (int) ($this->custom_data[0] ?? User::$me->id); $this->hash = $this->custom_data[1] ?? self::encrypt(User::$me->passwd, User::$me->password_salt); @@ -200,7 +200,7 @@ public function __construct( */ public function set(): bool { - if (in_array($this->name, [Config::$cookiename, Config::$cookiename . '_tfa'])) { + if (\in_array($this->name, [Config::$cookiename, Config::$cookiename . '_tfa'])) { $data = [ $this->member, $this->hash, @@ -212,7 +212,7 @@ public function set(): bool $data = array_merge($data, (array) $this->custom_data); $value = Utils::jsonEncode($data, JSON_FORCE_OBJECT); - } elseif (!is_scalar($this->custom_data)) { + } elseif (!\is_scalar($this->custom_data)) { $value = Utils::jsonEncode($this->custom_data, JSON_FORCE_OBJECT); } else { $value = $this->custom_data; diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index d98e926a06..4a3829b2ea 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -151,7 +151,7 @@ public function query(string $identifier, string $db_string, array $db_values = if (str_contains($db_string, 'GROUP BY') && str_contains($db_string, 'ORDER BY') && preg_match('~^\s+SELECT~i', $db_string)) { // Add before LIMIT if ($pos = strpos($db_string, 'LIMIT ')) { - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, \strlen($db_string)); } else { // Append it. $db_string .= "\n\t\t\tORDER BY null"; @@ -217,7 +217,7 @@ public function query(string $identifier, string $db_string, array $db_values = $fail = true; } - if (!empty($fail) && function_exists('log_error')) { + if (!empty($fail) && \function_exists('log_error')) { $this->error_backtrace('No direct access...', 'No direct access...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); } } @@ -229,7 +229,7 @@ public function query(string $identifier, string $db_string, array $db_values = if (!empty($_SESSION['debug_redirect'])) { self::$cache = array_merge($_SESSION['debug_redirect'], self::$cache); - self::$count = count(self::$cache) + 1; + self::$count = \count(self::$cache) + 1; $_SESSION['debug_redirect'] = []; } @@ -353,7 +353,7 @@ public function insert(string $method, string $table, array $columns, array $dat $with_returning = false; - if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) { + if (!empty($keys) && (\count($keys) > 0) && $returnmode > 0) { $with_returning = true; if ($returnmode == 2) { @@ -362,7 +362,7 @@ public function insert(string $method, string $table, array $columns, array $dat } // Inserting data as a single row can be done as a single array. - if (!is_array($data[array_rand($data)])) { + if (!\is_array($data[array_rand($data)])) { $data = [$data]; } @@ -405,7 +405,7 @@ public function insert(string $method, string $table, array $columns, array $dat ); } - if (count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { + if (\count(array_intersect_key($columns, array_flip($keys))) !== \count($keys)) { $this->error_backtrace( 'Primary Key field missing in insert call', 'Change the method of db insert to insert or add the pk field to the columns array', @@ -443,7 +443,7 @@ public function insert(string $method, string $table, array $columns, array $dat } // Special way for ignore method with returning else { - $count = count($insertRows); + $count = \count($insertRows); $ai = 0; for ($i = 0; $i < $count; $i++) { @@ -470,7 +470,7 @@ public function insert(string $method, string $table, array $columns, array $dat else { $where_string = ''; - $count2 = count($keys); + $count2 = \count($keys); for ($x = 0; $x < $count2; $x++) { $keyPos = array_search($keys[$x], array_keys($columns)); @@ -509,11 +509,11 @@ public function insert(string $method, string $table, array $columns, array $dat if ($with_returning) { if ($returnmode == 1 && empty($return_var)) { - $return_var = $this->insert_id($table, $keys[0]) + count($insertRows) - 1; + $return_var = $this->insert_id($table, $keys[0]) + \count($insertRows) - 1; } elseif ($returnmode == 2 && empty($return_var)) { $return_var = []; - $count = count($insertRows); + $count = \count($insertRows); $start = $this->insert_id($table, $keys[0]); @@ -635,7 +635,7 @@ public function transaction(string $type = 'commit', ?object $connection = null) { $type = strtoupper($type); - if (in_array($type, ['BEGIN', 'ROLLBACK', 'COMMIT'])) { + if (\in_array($type, ['BEGIN', 'ROLLBACK', 'COMMIT'])) { return @mysqli_query($connection ?? $this->connection, $type); } @@ -752,7 +752,7 @@ public function error_insert(array $error_array): void public function custom_order(string $field, array $array_values, bool $desc = false): string { $return = 'CASE ' . $field . ' '; - $count = count($array_values); + $count = \count($array_values); $then = ($desc ? ' THEN -' : ' THEN '); for ($i = 0; $i < $count; $i++) { @@ -1051,7 +1051,7 @@ public function table_sql(string $tableName): string $this->free_result($result); // Take off the last comma. - $schema_create = substr($schema_create, 0, -strlen($crlf) - 1); + $schema_create = substr($schema_create, 0, -\strlen($crlf) - 1); // Find the keys. $result = $this->query( @@ -1194,7 +1194,7 @@ public function get_vendor(): string */ public function allow_persistent(): bool { - $value = ini_get('mysqli.allow_persistent'); + $value = \ini_get('mysqli.allow_persistent'); return (bool) (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1'); } @@ -1218,7 +1218,7 @@ public function search_support(string $search_type): bool { $supported_types = ['fulltext']; - return in_array($search_type, $supported_types); + return \in_array($search_type, $supported_types); } /** @@ -1324,7 +1324,7 @@ public function add_index(string $table_name, array $index_info, array $paramete // If a size was already specified, we won't be able to match it anyways. if ( !isset($cols[$c]) - || !in_array($cols[$c]['type'], ['text', 'mediumtext', 'longtext', 'varchar', 'char']) + || !\in_array($cols[$c]['type'], ['text', 'mediumtext', 'longtext', 'varchar', 'char']) || ( isset($size) && $size <= 191 @@ -1480,7 +1480,7 @@ public function change_column(string $table_name, string $old_column, array $col $column_info['name'] = $old_column; } - if (!array_key_exists('default', $column_info) && array_key_exists('default', $old_info) && empty($column_info['drop_default'])) { + if (!\array_key_exists('default', $column_info) && \array_key_exists('default', $old_info) && empty($column_info['drop_default'])) { $column_info['default'] = $old_info['default']; } @@ -1500,20 +1500,20 @@ public function change_column(string $table_name, string $old_column, array $col $column_info['size'] = $old_info['size']; } - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'])) { + if (!isset($column_info['unsigned']) || !\in_array($column_info['type'], ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'])) { $column_info['unsigned'] = ''; } // If truly unspecified, make that clear, otherwise, might be confused with NULL... // (Unspecified = no default whatsoever = column is not nullable with a value of null...) - if (($column_info['not_null'] === true) && !$column_info['drop_default'] && array_key_exists('default', $column_info) && is_null($column_info['default'])) { + if (($column_info['not_null'] === true) && !$column_info['drop_default'] && \array_key_exists('default', $column_info) && \is_null($column_info['default'])) { unset($column_info['default']); } list($type, $size) = $this->calculate_type($column_info['type'], (int) $column_info['size']); // Allow for unsigned integers (mysql only) - $unsigned = in_array($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint']) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; + $unsigned = \in_array($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint']) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; // If you need to drop the default, that needs its own thing... // Must be done first, in case the default type is inconsistent with the other changes. @@ -1531,12 +1531,12 @@ public function change_column(string $table_name, string $old_column, array $col // Set the default clause. $default_clause = ''; - if (!$column_info['drop_default'] && array_key_exists('default', $column_info)) { - if (is_null($column_info['default'])) { + if (!$column_info['drop_default'] && \array_key_exists('default', $column_info)) { + if (\is_null($column_info['default'])) { $default_clause = 'DEFAULT NULL'; } elseif (is_numeric($column_info['default'])) { - $default_clause = 'DEFAULT ' . (strpos((string) $column_info['default'], '.') ? floatval($column_info['default']) : intval($column_info['default'])); - } elseif (is_string($column_info['default'])) { + $default_clause = 'DEFAULT ' . (strpos((string) $column_info['default'], '.') ? \floatval($column_info['default']) : \intval($column_info['default'])); + } elseif (\is_string($column_info['default'])) { $default_clause = 'DEFAULT \'' . $this->escape_string((string) $column_info['default']) . '\''; } } @@ -1577,7 +1577,7 @@ public function create_table(string $table_name, array $columns, array $indexes $short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name); // First - no way do we touch SMF tables. - if (in_array(strtolower($short_table_name), $this->reservedTables)) { + if (\in_array(strtolower($short_table_name), $this->reservedTables)) { return false; } @@ -1587,7 +1587,7 @@ public function create_table(string $table_name, array $columns, array $indexes // Slightly easier on MySQL than the others... $tables = $this->list_tables($database); - if (in_array($full_table_name, $tables)) { + if (\in_array($full_table_name, $tables)) { // This is a sad day... drop the table? If not, return false (error) by default. if ($if_exists == 'overwrite') { $this->drop_table($table_name); @@ -1629,7 +1629,7 @@ public function create_table(string $table_name, array $columns, array $indexes if ( $key === false || !isset($columns[$key]) - || !in_array($columns[$key]['type'], ['text', 'mediumtext', 'longtext', 'varchar', 'char']) + || !\in_array($columns[$key]['type'], ['text', 'mediumtext', 'longtext', 'varchar', 'char']) || ( isset($size) && $size <= 191 @@ -1676,8 +1676,8 @@ public function create_table(string $table_name, array $columns, array $indexes // If we don't have this engine, or didn't specify one, default to InnoDB or MyISAM // depending on which one is available - if (!isset($parameters['engine']) || !in_array($parameters['engine'], $this->engines)) { - $parameters['engine'] = in_array('InnoDB', $this->engines) ? 'InnoDB' : 'MyISAM'; + if (!isset($parameters['engine']) || !\in_array($parameters['engine'], $this->engines)) { + $parameters['engine'] = \in_array('InnoDB', $this->engines) ? 'InnoDB' : 'MyISAM'; } $table_query .= ') ENGINE=' . $parameters['engine']; @@ -1749,14 +1749,14 @@ public function drop_table(string $table_name, array $parameters = [], string $e $short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name); // God no - dropping one of these = bad. - if (in_array(strtolower($short_table_name), $this->reservedTables)) { + if (\in_array(strtolower($short_table_name), $this->reservedTables)) { return false; } // Does it exist? $tables = $this->list_tables($database); - if (in_array($full_table_name, $tables)) { + if (\in_array($full_table_name, $tables)) { $query = 'DROP TABLE ' . $short_table_name; $this->query( '', @@ -2058,7 +2058,7 @@ protected function __construct(array $options = []) } // For backward compatibility. - if (!is_object(self::$db_connection)) { + if (!\is_object(self::$db_connection)) { self::$db_connection = $this->connection; } @@ -2089,7 +2089,7 @@ protected function initiate(string $user, string $passwd, array $options = []): $server = ($this->persist ? 'p:' : '') . $this->server; // We are not going to make it very far without these. - if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) { + if (!\function_exists('mysqli_init') || !\function_exists('mysqli_real_connect')) { ErrorHandler::displayDbError(); } @@ -2157,7 +2157,7 @@ protected function initiate(string $user, string $passwd, array $options = []): */ protected function replacement__callback(array $matches): string { - if (!is_object($this->temp_connection)) { + if (!\is_object($this->temp_connection)) { ErrorHandler::displayDbError(); } @@ -2200,7 +2200,7 @@ protected function replacement__callback(array $matches): string return sprintf('\'%1$s\'', mysqli_real_escape_string($this->temp_connection, Utils::fixUtf8mb4((string) $replacement))); case 'array_int': - if (is_array($replacement)) { + if (\is_array($replacement)) { if (empty($replacement)) { $this->error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } @@ -2221,7 +2221,7 @@ protected function replacement__callback(array $matches): string break; case 'array_string': - if (is_array($replacement)) { + if (\is_array($replacement)) { if (empty($replacement)) { $this->error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } @@ -2282,12 +2282,12 @@ protected function replacement__callback(array $matches): string case 'uuid': if ($replacement instanceof Uuid) { - return sprintf('UUID_TO_BIN(\'%1$s\')', strval($replacement)); + return sprintf('UUID_TO_BIN(\'%1$s\')', \strval($replacement)); } $uuid = @Uuid::createFromString($replacement, false); - if (in_array($replacement, [(string) $uuid, $uuid->getShortForm(), $uuid->getBinary()])) { + if (\in_array($replacement, [(string) $uuid, $uuid->getShortForm(), $uuid->getBinary()])) { return sprintf('UUID_TO_BIN(\'%1$s\')', (string) $uuid); } @@ -2310,7 +2310,7 @@ protected function replacement__callback(array $matches): string return sprintf('unhex(\'%1$s\')', $ip->toHex()); case 'array_inet': - if (is_array($replacement)) { + if (\is_array($replacement)) { if (empty($replacement)) { $this->error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } @@ -2379,11 +2379,11 @@ protected function error_backtrace(string $error_message, string $log_message = } // Is always a critical error. - if (function_exists('log_error')) { + if (\function_exists('log_error')) { ErrorHandler::log($log_message, 'critical', $file, $line); } - if (function_exists('fatal_error')) { + if (\function_exists('fatal_error')) { ErrorHandler::fatal($error_message, false); // Cannot continue... @@ -2414,12 +2414,12 @@ protected function create_query_column(array $column): string $default = 'auto_increment'; } // Make it null. - elseif (array_key_exists('default', $column) && is_null($column['default'])) { + elseif (\array_key_exists('default', $column) && \is_null($column['default'])) { $default = 'DEFAULT NULL'; } // Numbers don't need quotes. elseif (isset($column['default']) && is_numeric($column['default'])) { - $default = 'DEFAULT ' . (strpos((string) $column['default'], '.') ? floatval($column['default']) : intval($column['default'])); + $default = 'DEFAULT ' . (strpos((string) $column['default'], '.') ? \floatval($column['default']) : \intval($column['default'])); } // Non empty string. elseif (isset($column['default'])) { @@ -2438,7 +2438,7 @@ protected function create_query_column(array $column): string list($type, $size) = $this->calculate_type($column['type'], (int) $column['size']); // Allow unsigned integers (mysql only) - $unsigned = in_array($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint']) && !empty($column['unsigned']) ? 'unsigned ' : ''; + $unsigned = \in_array($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint']) && !empty($column['unsigned']) ? 'unsigned ' : ''; if ($size > 0) { $type = $type . '(' . $size . ')'; diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index 79d8154969..5bd4fec954 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -201,7 +201,7 @@ public function query(string $identifier, string $db_string, array $db_values = if (str_contains($db_string, 'GROUP BY') && !str_contains($db_string, 'ORDER BY') && preg_match('~^\s+SELECT~i', $db_string)) { // Add before LIMIT if ($pos = strpos($db_string, 'LIMIT ')) { - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, \strlen($db_string)); } else { // Append it. $db_string .= "\n\t\t\tORDER BY null"; @@ -267,7 +267,7 @@ public function query(string $identifier, string $db_string, array $db_values = $fail = true; } - if (!empty($fail) && function_exists('log_error')) { + if (!empty($fail) && \function_exists('log_error')) { $this->error_backtrace('No direct access...', 'No direct access...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); } } @@ -295,7 +295,7 @@ public function query(string $identifier, string $db_string, array $db_values = if (!empty($_SESSION['debug_redirect'])) { self::$cache = array_merge($_SESSION['debug_redirect'], self::$cache); - self::$count = count(self::$cache) + 1; + self::$count = \count(self::$cache) + 1; $_SESSION['debug_redirect'] = []; } @@ -387,7 +387,7 @@ public function insert(string $method, string $table, array $columns, array $dat // Force method to lower case $method = strtolower($method); - if (!is_array($data[array_rand($data)])) { + if (!\is_array($data[array_rand($data)])) { $data = [$data]; } @@ -406,7 +406,7 @@ public function insert(string $method, string $table, array $columns, array $dat ); } - if (count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { + if (\count(array_intersect_key($columns, array_flip($keys))) !== \count($keys)) { $this->error_backtrace( 'Primary Key field missing in insert call', 'Change the method of db insert to insert or add the pk field to the columns array', @@ -427,7 +427,7 @@ public function insert(string $method, string $table, array $columns, array $dat foreach ($columns as $columnName => $type) { // Check pk field. - if (in_array($columnName, $keys)) { + if (\in_array($columnName, $keys)) { $key_str .= ($count_pk > 0 ? ',' : ''); $key_str .= $columnName; $count_pk++; @@ -451,7 +451,7 @@ public function insert(string $method, string $table, array $columns, array $dat $with_returning = false; // Let's build the returning string. (MySQL allows this only in normal mode) - if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) { + if (!empty($keys) && (\count($keys) > 0) && $returnmode > 0) { // We only take the first key. $returning = ' RETURNING ' . $keys[0]; $with_returning = true; @@ -665,12 +665,12 @@ public function transaction(string $type = 'commit', ?object $connection = null) { $type = strtoupper($type); - if (in_array($type, ['BEGIN', 'ROLLBACK', 'COMMIT'])) { + if (\in_array($type, ['BEGIN', 'ROLLBACK', 'COMMIT'])) { $this->inTransaction = $type === 'BEGIN'; $return = @pg_query($connection ?? $this->connection, $type); - if (is_bool($return)) { + if (\is_bool($return)) { return $return; } @@ -730,7 +730,7 @@ public function escape_wildcard_string(string $string, bool $translate_human_wil */ public function is_resource(mixed $result): bool { - return is_resource($result); + return \is_resource($result); } /** @@ -799,7 +799,7 @@ public function error_insert(array $error_array): void public function custom_order(string $field, array $array_values, bool $desc = false): string { $return = 'CASE ' . $field . ' '; - $count = count($array_values); + $count = \count($array_values); $then = ($desc ? ' THEN -' : ' THEN '); for ($i = 0; $i < $count; $i++) { @@ -1034,7 +1034,7 @@ public function table_sql(string $tableName): string $this->free_result($result); // Take off the last comma. - $schema_create = substr($schema_create, 0, -strlen($crlf) - 1); + $schema_create = substr($schema_create, 0, -\strlen($crlf) - 1); $result = $this->query( '', @@ -1128,7 +1128,7 @@ public function get_vendor(): string */ public function allow_persistent(): bool { - $value = ini_get('pgsql.allow_persistent'); + $value = \ini_get('pgsql.allow_persistent'); return (bool) (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1'); } @@ -1213,7 +1213,7 @@ public function search_support(string $search_type): bool { $supported_types = ['custom', 'fulltext']; - return in_array($search_type, $supported_types); + return \in_array($search_type, $supported_types); } /** @@ -1327,7 +1327,7 @@ public function add_column(string $table_name, array $column_info, array $parame // If there's more attributes they need to be done via a change on PostgreSQL. unset($column_info['type'], $column_info['size']); - if (count($column_info) != 1) { + if (\count($column_info) != 1) { return $this->change_column($table_name, $column_info['name'], $column_info); } @@ -1498,7 +1498,7 @@ public function change_column(string $table_name, string $old_column, array $col $column_info['name'] = $old_column; } - if (!array_key_exists('default', $column_info) && array_key_exists('default', $old_info) && empty($column_info['drop_default'])) { + if (!\array_key_exists('default', $column_info) && \array_key_exists('default', $old_info) && empty($column_info['drop_default'])) { $column_info['default'] = $old_info['default']; } @@ -1518,13 +1518,13 @@ public function change_column(string $table_name, string $old_column, array $col $column_info['size'] = $old_info['size']; } - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'])) { + if (!isset($column_info['unsigned']) || !\in_array($column_info['type'], ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'])) { $column_info['unsigned'] = ''; } // If truly unspecified, make that clear, otherwise, might be confused with NULL... // (Unspecified = no default whatsoever = column is not nullable with a value of null...) - if (($column_info['not_null'] === true) && !$column_info['drop_default'] && array_key_exists('default', $column_info) && is_null($column_info['default'])) { + if (($column_info['not_null'] === true) && !$column_info['drop_default'] && \array_key_exists('default', $column_info) && \is_null($column_info['default'])) { unset($column_info['default']); } @@ -1601,14 +1601,14 @@ public function change_column(string $table_name, string $old_column, array $col // Different default? // Just go ahead & honor the setting. Type changes above introduce defaults that we might need to override here... - if (!$column_info['drop_default'] && array_key_exists('default', $column_info)) { + if (!$column_info['drop_default'] && \array_key_exists('default', $column_info)) { // Fix the default. $default = ''; - if (is_null($column_info['default'])) { + if (\is_null($column_info['default'])) { $default = 'NULL'; } elseif (isset($column_info['default']) && is_numeric($column_info['default'])) { - $default = strpos($column_info['default'], '.') ? floatval($column_info['default']) : intval($column_info['default']); + $default = strpos($column_info['default'], '.') ? \floatval($column_info['default']) : \intval($column_info['default']); } else { $default = '\'' . $this->escape_string($column_info['default']) . '\''; } @@ -1661,7 +1661,7 @@ public function create_table(string $table_name, array $columns, array $indexes $short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name); // First - no way do we touch SMF tables. - if (in_array(strtolower($short_table_name), $this->reservedTables)) { + if (\in_array(strtolower($short_table_name), $this->reservedTables)) { return false; } @@ -1671,7 +1671,7 @@ public function create_table(string $table_name, array $columns, array $indexes // This... my friends... is a function in a half - let's start by checking if the table exists! $tables = $this->list_tables($database); - if (in_array($full_table_name, $tables)) { + if (\in_array($full_table_name, $tables)) { // This is a sad day... drop the table? If not, return false (error) by default. if ($if_exists == 'overwrite') { $this->drop_table($table_name); @@ -1853,14 +1853,14 @@ public function drop_table(string $table_name, array $parameters = [], string $e $short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name); // God no - dropping one of these = bad. - if (in_array(strtolower($table_name), $this->reservedTables)) { + if (\in_array(strtolower($table_name), $this->reservedTables)) { return false; } // Does it exist? $tables = $this->list_tables($database); - if (in_array($full_table_name, $tables)) { + if (\in_array($full_table_name, $tables)) { // We can then drop the table. $this->transaction('begin'); @@ -2169,7 +2169,7 @@ protected function __construct(array $options = []) } // For backward compatibility. - if (!is_object(self::$db_connection)) { + if (!\is_object(self::$db_connection)) { self::$db_connection = $this->connection; } @@ -2195,7 +2195,7 @@ protected function __construct(array $options = []) protected function initiate(string $user, string $passwd, array $options = []): void { // We are not going to make it very far without this. - if (!function_exists('pg_pconnect')) { + if (!\function_exists('pg_pconnect')) { ErrorHandler::displayDbError(); } @@ -2245,7 +2245,7 @@ function ($errno, $errstr) { */ protected function replacement__callback(array $matches): string { - if (!is_object($this->temp_connection)) { + if (!\is_object($this->temp_connection)) { ErrorHandler::displayDbError(); } @@ -2288,7 +2288,7 @@ protected function replacement__callback(array $matches): string return sprintf('\'%1$s\'', pg_escape_string($this->connection, (string) $replacement)); case 'array_int': - if (is_array($replacement)) { + if (\is_array($replacement)) { if (empty($replacement)) { $this->error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } @@ -2309,7 +2309,7 @@ protected function replacement__callback(array $matches): string break; case 'array_string': - if (is_array($replacement)) { + if (\is_array($replacement)) { if (empty($replacement)) { $this->error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } @@ -2374,7 +2374,7 @@ protected function replacement__callback(array $matches): string $uuid = @Uuid::createFromString($replacement, false); - if (in_array($replacement, [(string) $uuid, $uuid->getShortForm(), $uuid->getBinary()])) { + if (\in_array($replacement, [(string) $uuid, $uuid->getShortForm(), $uuid->getBinary()])) { return sprintf('\'%1$s\'::uuid', (string) $uuid); } @@ -2393,10 +2393,10 @@ protected function replacement__callback(array $matches): string $this->error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } - return sprintf('\'%1$s\'::inet', pg_escape_string($this->connection, strval($ip))); + return sprintf('\'%1$s\'::inet', pg_escape_string($this->connection, \strval($ip))); case 'array_inet': - if (is_array($replacement)) { + if (\is_array($replacement)) { if (empty($replacement)) { $this->error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } @@ -2412,7 +2412,7 @@ protected function replacement__callback(array $matches): string $this->error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); } - $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($this->connection, strval($ip))); + $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($this->connection, \strval($ip))); } return implode(', ', $replacement); @@ -2465,11 +2465,11 @@ protected function error_backtrace(string $error_message, string $log_message = } // Is always a critical error. - if (function_exists('log_error')) { + if (\function_exists('log_error')) { ErrorHandler::log($log_message, 'critical', $file, $line); } - if (function_exists('fatal_error')) { + if (\function_exists('fatal_error')) { ErrorHandler::fatal($error_message, $error_type); // Cannot continue... diff --git a/Sources/Db/DatabaseApi.php b/Sources/Db/DatabaseApi.php index 79f1781677..d9b0680988 100644 --- a/Sources/Db/DatabaseApi.php +++ b/Sources/Db/DatabaseApi.php @@ -538,7 +538,7 @@ protected function mapToSmcFunc(): void } // Export properties to global namespace for backward compatibility. -if (is_callable([DatabaseApi::class, 'exportStatic'])) { +if (\is_callable([DatabaseApi::class, 'exportStatic'])) { DatabaseApi::exportStatic(); } diff --git a/Sources/DebugUtils.php b/Sources/DebugUtils.php index d5b6d32494..a0dcb10c4a 100644 --- a/Sources/DebugUtils.php +++ b/Sources/DebugUtils.php @@ -43,7 +43,7 @@ public static function trimIndent(string $string): string $min_indent = PHP_INT_MAX; foreach ($matches[0] as $match) { - $min_indent = min($min_indent, strlen($match)); + $min_indent = min($min_indent, \strlen($match)); } if ($min_indent != PHP_INT_MAX) { diff --git a/Sources/Draft.php b/Sources/Draft.php index c23d1c60b3..c2acad52db 100644 --- a/Sources/Draft.php +++ b/Sources/Draft.php @@ -259,7 +259,7 @@ public function save(array &$post_errors): bool return false; } - if (in_array('session_timeout', $post_errors)) { + if (\in_array('session_timeout', $post_errors)) { return false; } diff --git a/Sources/DynamicPropertyHelper.php b/Sources/DynamicPropertyHelper.php index 5bc1db3d3e..7198954315 100644 --- a/Sources/DynamicPropertyHelper.php +++ b/Sources/DynamicPropertyHelper.php @@ -164,16 +164,16 @@ public function __unset(string $prop): void */ protected function customPropertySet(mixed $prop, mixed $value): void { - if (!empty($this->prop_aliases) && array_key_exists($prop, $this->prop_aliases)) { + if (!empty($this->prop_aliases) && \array_key_exists($prop, $this->prop_aliases)) { // Can't unset a virtual property. - if (is_null($value)) { + if (\is_null($value)) { return; } $real_prop = $this->prop_aliases[$prop]; // Callable properties can't be set. - if (is_callable($real_prop)) { + if (\is_callable($real_prop)) { return; } @@ -185,7 +185,7 @@ protected function customPropertySet(mixed $prop, mixed $value): void if (str_contains($real_prop, '[')) { $real_prop = explode('[', rtrim($real_prop, ']')); - if (is_object($this->{$real_prop[0]})) { + if (\is_object($this->{$real_prop[0]})) { $this->{$real_prop[0]}->{$real_prop[1]} = $value; } else { $this->{$real_prop[0]}[$real_prop[1]] = $value; @@ -207,12 +207,12 @@ protected function customPropertySet(mixed $prop, mixed $value): void */ protected function customPropertyGet(mixed $prop): mixed { - if (!empty($this->prop_aliases) && array_key_exists($prop, $this->prop_aliases)) { + if (!empty($this->prop_aliases) && \array_key_exists($prop, $this->prop_aliases)) { $real_prop = $this->prop_aliases[$prop]; // Callable properties are calculated dynamically. - if (str_contains($real_prop, '::') && is_callable($real_prop)) { - return call_user_func($real_prop, $this); + if (str_contains($real_prop, '::') && \is_callable($real_prop)) { + return \call_user_func($real_prop, $this); } if (($not = str_starts_with($real_prop, '!'))) { @@ -222,7 +222,7 @@ protected function customPropertyGet(mixed $prop): mixed if (str_contains($real_prop, '[')) { $real_prop = explode('[', rtrim($real_prop, ']')); - if (is_object($this->{$real_prop[0]})) { + if (\is_object($this->{$real_prop[0]})) { $value = $this->{$real_prop[0]}->{$real_prop[1]}; } else { $value = $this->{$real_prop[0]}[$real_prop[1]]; @@ -248,18 +248,18 @@ protected function customPropertyGet(mixed $prop): mixed */ protected function customPropertyIsset(mixed $prop): bool { - if (!empty($this->prop_aliases) && array_key_exists($prop, $this->prop_aliases)) { + if (!empty($this->prop_aliases) && \array_key_exists($prop, $this->prop_aliases)) { $real_prop = ltrim($this->prop_aliases[$prop], '!'); // A callable property is set if it returns a non-null value. - if (str_contains($real_prop, '::') && is_callable($real_prop)) { - return call_user_func($real_prop, $this) !== null; + if (str_contains($real_prop, '::') && \is_callable($real_prop)) { + return \call_user_func($real_prop, $this) !== null; } if (str_contains($real_prop, '[')) { $real_prop = explode('[', rtrim($real_prop, ']')); - if (is_object($this->{$real_prop[0]})) { + if (\is_object($this->{$real_prop[0]})) { return isset($this->{$real_prop[0]}->{$real_prop[1]}); } @@ -283,7 +283,7 @@ protected function customPropertyIsset(mixed $prop): bool */ protected function customPropertyUnset(mixed $prop): void { - if (!empty($this->prop_aliases) && array_key_exists($prop, $this->prop_aliases)) { + if (!empty($this->prop_aliases) && \array_key_exists($prop, $this->prop_aliases)) { // Can't unset a virtual property. return; } diff --git a/Sources/Editor.php b/Sources/Editor.php index 13aa836183..e04e54fb5d 100644 --- a/Sources/Editor.php +++ b/Sources/Editor.php @@ -543,7 +543,7 @@ protected function buildBbcToolbar(): void ]; if (empty(Config::$modSettings['disable_wysiwyg'])) { - self::$bbc_tags[count(self::$bbc_tags) - 1][] = [ + self::$bbc_tags[\count(self::$bbc_tags) - 1][] = [ 'code' => 'removeformat', 'description' => Lang::$editortxt['remove_formatting'], ]; @@ -613,7 +613,7 @@ protected function buildBbcToolbar(): void ]; if (empty(Config::$modSettings['disable_wysiwyg'])) { - self::$bbc_tags[count(self::$bbc_tags) - 1][] = [ + self::$bbc_tags[\count(self::$bbc_tags) - 1][] = [ 'code' => 'source', 'description' => Lang::$editortxt['view_source'], ]; @@ -752,11 +752,11 @@ protected function buildSmileysToolbar(): void foreach (self::$smileys_toolbar as $section => $smiley_rows) { foreach ($smiley_rows as $rowIndex => $smileys) { - self::$smileys_toolbar[$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; + self::$smileys_toolbar[$section][$rowIndex]['smileys'][\count($smileys['smileys']) - 1]['isLast'] = true; } if (!empty($smiley_rows)) { - self::$smileys_toolbar[$section][count($smiley_rows) - 1]['isLast'] = true; + self::$smileys_toolbar[$section][\count($smiley_rows) - 1]['isLast'] = true; } } @@ -811,7 +811,7 @@ protected function setSCEditorOptions(): void $this->sce_options['emoticons']['dropdown'] = []; $this->sce_options['emoticons']['popup'] = []; - $count_locations = count(self::$smileys_toolbar); + $count_locations = \count(self::$smileys_toolbar); foreach (self::$smileys_toolbar as $location => $smiley_rows) { $count_locations--; @@ -824,7 +824,7 @@ protected function setSCEditorOptions(): void $smiley_location = &$this->sce_options['emoticons']['popup']; } - $num_rows = count($smiley_rows); + $num_rows = \count($smiley_rows); // This is needed because otherwise the editor will remove all the duplicate (empty) keys and leave only 1 additional line $empty_placeholder = 0; @@ -850,7 +850,7 @@ protected function setSCEditorOptions(): void $this->sce_options['toolbar'] = ''; if (!empty(Config::$modSettings['enableBBC'])) { - $count_tags = count(self::$bbc_tags); + $count_tags = \count(self::$bbc_tags); foreach (self::$bbc_toolbar as $i => $buttonRow) { $this->sce_options['toolbar'] .= implode('|', $buttonRow); diff --git a/Sources/ErrorHandler.php b/Sources/ErrorHandler.php index b8de257e24..9a0986abad 100644 --- a/Sources/ErrorHandler.php +++ b/Sources/ErrorHandler.php @@ -58,7 +58,7 @@ public function __construct(int $error_level, string $error_string, string $file if (str_contains($file, 'eval()') && !empty(Theme::$current->settings['current_include_filename'])) { $array = debug_backtrace(); - $count = count($array); + $count = \count($array); for ($i = 0; $i < $count; $i++) { if ($array[$i]['function'] != 'SMF\\Theme::loadSubTemplate') { @@ -234,7 +234,7 @@ public static function log(string $error_message, string|bool $error_type = 'gen } // Make sure the category that was specified is a valid one - $error_type = in_array($error_type, $known_error_types) && $error_type !== true ? $error_type : 'general'; + $error_type = \in_array($error_type, $known_error_types) && $error_type !== true ? $error_type : 'general'; // Leave out the call to this method. array_splice($backtrace, 0, 1); @@ -531,7 +531,7 @@ protected static function logOnline(string $error, array $sprintf = []): void $url['error'] = $error; // Url field got a max length of 1024 in db - if (strlen($url['error']) > 500) { + if (\strlen($url['error']) > 500) { $url['error'] = substr($url['error'], 0, 500); } @@ -624,8 +624,8 @@ protected static function setupFatalContext(string $error_message, ?string $erro // If this is SSI, what do they want us to do? if (SMF == 'SSI') { - if (!empty(SSI::$on_error_method) && SSI::$on_error_method !== true && is_callable(SSI::$on_error_method)) { - call_user_func(SSI::$on_error_method); + if (!empty(SSI::$on_error_method) && SSI::$on_error_method !== true && \is_callable(SSI::$on_error_method)) { + \call_user_func(SSI::$on_error_method); } elseif (empty(SSI::$on_error_method) || SSI::$on_error_method !== true) { Theme::loadSubTemplate('fatal_error'); } @@ -638,7 +638,7 @@ protected static function setupFatalContext(string $error_message, ?string $erro // Alternatively from the cron call? elseif (SMF == 'BACKGROUND') { // We can't rely on even having language files available. - if (defined('FROM_CLI') && FROM_CLI) { + if (\defined('FROM_CLI') && FROM_CLI) { echo 'cron error: ', Utils::$context['error_message']; } else { echo 'An error occurred. More information may be available in your logs.'; @@ -684,7 +684,7 @@ protected static function logLastDatabaseError(): bool $written_bytes = file_put_contents(Config::$cachedir . '/db_last_error.php', $write_db_change, LOCK_EX); // survey says ... - if ($written_bytes !== strlen($write_db_change) && !$dberror_backup_fail) { + if ($written_bytes !== \strlen($write_db_change) && !$dberror_backup_fail) { // Oops. maybe we have no more disk space left, or some other troubles, troubles... // Copy the file back and run for your life! @copy(Config::$cachedir . '/db_last_error_bak.php', Config::$cachedir . '/db_last_error.php'); diff --git a/Sources/Forum.php b/Sources/Forum.php index d3b8a70d00..9ef2d7c8c3 100644 --- a/Sources/Forum.php +++ b/Sources/Forum.php @@ -226,7 +226,7 @@ public function __construct() // Check if compressed output is enabled, supported, and not already being done. if (!empty(Config::$modSettings['enableCompressedOutput']) && !headers_sent()) { // If zlib is being used, turn off output compression. - if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') { + if (\ini_get('zlib.output_compression') >= 1 || \ini_get('output_handler') == 'ob_gzhandler') { Config::$modSettings['enableCompressedOutput'] = '0'; } else { ob_end_clean(); @@ -261,7 +261,7 @@ public function __construct() public function execute(): void { // What function shall we execute? (done like this for memory's sake.) - call_user_func($this->main()); + \call_user_func($this->main()); // Call obExit specially; we're coming from the main area ;). Utils::obExit(null, null, true); @@ -360,7 +360,7 @@ protected function main(): array|string // Is the forum in maintenance mode? (doesn't apply to administrators.) if (!empty(Config::$maintenance) && !User::$me->allowedTo('admin_forum')) { // You can only login.... otherwise, you're getting the "maintenance mode" display. - if (isset($_REQUEST['action']) && (in_array($_REQUEST['action'], ['login2', 'logintfa', 'logout']))) { + if (isset($_REQUEST['action']) && (\in_array($_REQUEST['action'], ['login2', 'logintfa', 'logout']))) { return self::$actions[$_REQUEST['action']][1]; } @@ -369,7 +369,7 @@ protected function main(): array|string } // If guest access is off, a guest can only do one of the very few following actions. - if (empty(Config::$modSettings['allow_guestAccess']) && User::$me->is_guest && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], self::$guest_access_actions))) { + if (empty(Config::$modSettings['allow_guestAccess']) && User::$me->is_guest && (!isset($_REQUEST['action']) || !\in_array($_REQUEST['action'], self::$guest_access_actions))) { User::$me->kickIfGuest(null, false); } elseif (empty($_REQUEST['action'])) { // Action and board are both empty... BoardIndex! Unless someone else wants to do something different. diff --git a/Sources/Graphics/Gif/ColorTable.php b/Sources/Graphics/Gif/ColorTable.php index d1ea11d354..487a950ce8 100644 --- a/Sources/Graphics/Gif/ColorTable.php +++ b/Sources/Graphics/Gif/ColorTable.php @@ -41,11 +41,11 @@ public function load(string $lpData, int $num): bool for ($i = 0; $i < $num; $i++) { $rgb = substr($lpData, $i * 3, 3); - if (strlen($rgb) < 3) { + if (\strlen($rgb) < 3) { return false; } - $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]); + $this->m_arColors[] = (\ord($rgb[2]) << 16) + (\ord($rgb[1]) << 8) + \ord($rgb[0]); $this->m_nColors++; } @@ -58,9 +58,9 @@ public function toString(): string for ($i = 0; $i < $this->m_nColors; $i++) { $ret .= - chr(($this->m_arColors[$i] & 0x000000FF)) . // R - chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G - chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B + \chr(($this->m_arColors[$i] & 0x000000FF)) . // R + \chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G + \chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B } return $ret; @@ -69,7 +69,7 @@ public function toString(): string public function colorIndex(string $rgb): int { $dif = 0; - $rgb = intval($rgb) & 0xFFFFFF; + $rgb = \intval($rgb) & 0xFFFFFF; $r1 = ($rgb & 0x0000FF); $g1 = ($rgb & 0x00FF00) >> 8; $b1 = ($rgb & 0xFF0000) >> 16; diff --git a/Sources/Graphics/Gif/File.php b/Sources/Graphics/Gif/File.php index 782c1c1682..5e3424448b 100644 --- a/Sources/Graphics/Gif/File.php +++ b/Sources/Graphics/Gif/File.php @@ -124,7 +124,7 @@ public function get_png_data(string $background_color): string|bool } // Otherwise, this is background... else { - $bmp .= chr($background_color); + $bmp .= \chr($background_color); } } } @@ -160,7 +160,7 @@ public function get_png_data(string $background_color): string|bool } // Here's the data itself! - $out .= pack('N', strlen($bmp)); + $out .= pack('N', \strlen($bmp)); $tmp = 'IDAT' . $bmp; $out .= $tmp . pack('N', smf_crc32($tmp)); @@ -172,7 +172,7 @@ public function get_png_data(string $background_color): string|bool } // 64-bit only functions? -if (!function_exists('smf_crc32')) { +if (!\function_exists('smf_crc32')) { require_once Config::$sourcedir . '/Subs-Compat.php'; } diff --git a/Sources/Graphics/Gif/FileHeader.php b/Sources/Graphics/Gif/FileHeader.php index dfff50a375..add8daf83b 100644 --- a/Sources/Graphics/Gif/FileHeader.php +++ b/Sources/Graphics/Gif/FileHeader.php @@ -57,13 +57,13 @@ public function load(string $lpData, int &$hdrLen): bool return false; } - $b = ord(substr($lpData, 10, 1)); + $b = \ord(substr($lpData, 10, 1)); $this->m_bGlobalClr = ($b & 0x80) ? true : false; $this->m_nColorRes = ($b & 0x70) >> 4; $this->m_bSorted = ($b & 0x08) ? true : false; $this->m_nTableSize = 2 << ($b & 0x07); - $this->m_nBgColor = ord(substr($lpData, 11, 1)); - $this->m_nPixelRatio = ord(substr($lpData, 12, 1)); + $this->m_nBgColor = \ord(substr($lpData, 11, 1)); + $this->m_nPixelRatio = \ord(substr($lpData, 12, 1)); $hdrLen = 13; if ($this->m_bGlobalClr) { diff --git a/Sources/Graphics/Gif/Image.php b/Sources/Graphics/Gif/Image.php index e994666523..930fbf2a51 100644 --- a/Sources/Graphics/Gif/Image.php +++ b/Sources/Graphics/Gif/Image.php @@ -47,7 +47,7 @@ public function load(string $data, int &$datLen): bool $datLen = 0; while (true) { - $b = ord($data[0]); + $b = \ord($data[0]); $data = substr($data, 1); $datLen++; @@ -102,24 +102,24 @@ public function skipExt(string &$data, int &$extLen): bool { $extLen = 0; - $b = ord($data[0]); + $b = \ord($data[0]); $data = substr($data, 1); $extLen++; switch ($b) { // Graphic Control... case 0xF9: - $b = ord($data[1]); + $b = \ord($data[1]); $this->m_disp = ($b & 0x1C) >> 2; $this->m_bUser = ($b & 0x02) ? true : false; $this->m_bTrans = ($b & 0x01) ? true : false; list($this->m_nDelay) = array_values(unpack('v', substr($data, 2, 2))); - $this->m_nTrans = ord($data[4]); + $this->m_nTrans = \ord($data[4]); break; // Comment... case 0xFE: - $this->m_lpComm = substr($data, 1, ord($data[0])); + $this->m_lpComm = substr($data, 1, \ord($data[0])); break; // Plain text... @@ -132,14 +132,14 @@ public function skipExt(string &$data, int &$extLen): bool } // Skip default as defs may change. - $b = ord($data[0]); + $b = \ord($data[0]); $data = substr($data, 1); $extLen++; while ($b > 0) { $data = substr($data, $b); $extLen += $b; - $b = ord($data[0]); + $b = \ord($data[0]); $data = substr($data, 1); $extLen++; } diff --git a/Sources/Graphics/Gif/ImageHeader.php b/Sources/Graphics/Gif/ImageHeader.php index 4dab6510bb..6aa460604a 100644 --- a/Sources/Graphics/Gif/ImageHeader.php +++ b/Sources/Graphics/Gif/ImageHeader.php @@ -51,7 +51,7 @@ public function load(string $lpData, int &$hdrLen): bool return false; } - $b = ord($lpData[8]); + $b = \ord($lpData[8]); $this->m_bLocalClr = ($b & 0x80) ? true : false; $this->m_bInterlace = ($b & 0x40) ? true : false; $this->m_bSorted = ($b & 0x20) ? true : false; diff --git a/Sources/Graphics/Gif/LzwCompression.php b/Sources/Graphics/Gif/LzwCompression.php index 2ac564dcdd..cfd638f8ec 100644 --- a/Sources/Graphics/Gif/LzwCompression.php +++ b/Sources/Graphics/Gif/LzwCompression.php @@ -63,17 +63,17 @@ public function __construct() public function decompress(string $data, int &$datLen): string|bool { - $stLen = strlen($data); + $stLen = \strlen($data); $datLen = 0; $ret = ''; $this->LZWCommand($data, true); while (($iIndex = $this->LZWCommand($data, false)) >= 0) { - $ret .= chr($iIndex); + $ret .= \chr($iIndex); } - $datLen = $stLen - strlen($data); + $datLen = $stLen - \strlen($data); if ($iIndex != -2) { return false; @@ -85,7 +85,7 @@ public function decompress(string $data, int &$datLen): string|bool public function LZWCommand(string &$data, int|bool $bInit): int { if ($bInit) { - $this->SetCodeSize = ord($data[0]); + $this->SetCodeSize = \ord($data[0]); $data = substr($data, 1); $this->CodeSize = $this->SetCodeSize + 1; @@ -226,12 +226,12 @@ public function GetCode(string &$data, int $bInit): int $this->Buf[0] = $this->Buf[$this->LastByte - 2]; $this->Buf[1] = $this->Buf[$this->LastByte - 1]; - $count = ord($data[0]); + $count = \ord($data[0]); $data = substr($data, 1); if ($count) { for ($i = 0; $i < $count; $i++) { - $this->Buf[2 + $i] = ord($data[$i]); + $this->Buf[2 + $i] = \ord($data[$i]); } $data = substr($data, $count); @@ -247,7 +247,7 @@ public function GetCode(string &$data, int $bInit): int $iRet = 0; for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { - $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; + $iRet |= (($this->Buf[\intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; } $this->CurBit += $this->CodeSize; diff --git a/Sources/Graphics/Image.php b/Sources/Graphics/Image.php index 680c4967d4..85dcface60 100644 --- a/Sources/Graphics/Image.php +++ b/Sources/Graphics/Image.php @@ -24,8 +24,8 @@ use SMF\WebFetch\WebFetchApi; // IMAGETYPE_AVIF was added in PHP 8.1 -if (!defined('IMAGETYPE_AVIF')) { - define('IMAGETYPE_AVIF', 19); +if (!\defined('IMAGETYPE_AVIF')) { + \define('IMAGETYPE_AVIF', 19); } /** @@ -217,7 +217,7 @@ public function __construct(string $source, bool $strict = false) $this->original = $source; // Fetch the raw image data from the URL. On failure, bail out. - if (!is_string($source = WebFetchApi::fetch($source))) { + if (!\is_string($source = WebFetchApi::fetch($source))) { return; } } @@ -237,7 +237,7 @@ public function __construct(string $source, bool $strict = false) $mime_type = Utils::getMimeType($this->source, true); // Not an image? Error and bail out. - if (!is_string($mime_type) || strpos($mime_type, 'image/') !== 0) { + if (!\is_string($mime_type) || strpos($mime_type, 'image/') !== 0) { if ($this->is_temp) { @unlink($this->source); } @@ -313,7 +313,7 @@ public function createThumbnail(int $max_width, int $max_height): object|bool } // We don't need to create a thumbnail if one is already embedded. - if (function_exists('exif_thumbnail') && exif_thumbnail($this->source) !== false) { + if (\function_exists('exif_thumbnail') && exif_thumbnail($this->source) !== false) { return false; } @@ -373,7 +373,7 @@ public function reencode(int $preferred_type = 0): bool // If we're working on a temporary file, just replace it. // Otherwise, update the file extension. - $destination = empty($this->pathinfo['extension']) ? $source : substr($source, 0, -(strlen($this->pathinfo['extension']) + 1)) . image_type_to_extension($preferred_type); + $destination = empty($this->pathinfo['extension']) ? $source : substr($source, 0, -(\strlen($this->pathinfo['extension']) + 1)) . image_type_to_extension($preferred_type); if (!@rename($source . '.tmp', $destination)) { return false; @@ -414,12 +414,12 @@ public function reencode(int $preferred_type = 0): bool public function resize(string $destination, int $max_width, int $max_height, int &$preferred_type = 0): bool { // Check whether the destination directory exists. - if (!is_dir(dirname($destination))) { + if (!is_dir(\dirname($destination))) { return false; } // Ensure the destination is writable. - if (!Utils::makeWritable(file_exists($destination) ? $destination : dirname($destination))) { + if (!Utils::makeWritable(file_exists($destination) ? $destination : \dirname($destination))) { return false; } @@ -434,17 +434,17 @@ public function resize(string $destination, int $max_width, int $max_height, int } // Nothing to do without GD or Imagick. - if (!extension_loaded('gd') && !extension_loaded('imagick')) { + if (!\extension_loaded('gd') && !\extension_loaded('imagick')) { return false; } // Is this image currently in a supported format? - if (!in_array($this->type, self::getSupportedFormats())) { + if (!\in_array($this->type, self::getSupportedFormats())) { return false; } // What destination format do we want? - if ($preferred_type === 0 || !in_array($preferred_type, self::$supported)) { + if ($preferred_type === 0 || !\in_array($preferred_type, self::$supported)) { $preferred_type = $this->type ?? self::DEFAULT_IMAGETYPE; } @@ -452,11 +452,11 @@ public function resize(string $destination, int $max_width, int $max_height, int $max_height = (int) round($max_height); // Do the job using ImageMagick. - if (extension_loaded('imagick') && isset(self::IMAGETYPE_TO_IMAGICK[$preferred_type])) { + if (\extension_loaded('imagick') && isset(self::IMAGETYPE_TO_IMAGICK[$preferred_type])) { $success = $this->resizeUsingImagick($destination, $max_width, $max_height, $preferred_type); } // Do the job using GD. - elseif (extension_loaded('gd')) { + elseif (\extension_loaded('gd')) { $success = $this->resizeUsingGD($destination, $max_width, $max_height, $preferred_type); } @@ -535,13 +535,13 @@ public static function getSupportedFormats(): array if (!isset(self::$supported)) { self::$supported = []; - if (extension_loaded('imagick')) { + if (\extension_loaded('imagick')) { foreach (self::getImageTypes() as $name => $int) { if (isset(self::IMAGETYPE_TO_IMAGICK[$int])) { self::$supported[$name] = $int; } } - } elseif (extension_loaded('gd')) { + } elseif (\extension_loaded('gd')) { foreach (self::getImageTypes() as $name => $int) { if (imagetypes() & $int) { self::$supported[$name] = $int; @@ -634,7 +634,7 @@ public static function gifOutputAsPng(Gif\File $gif, string $lpszFileName, strin return false; } - @fwrite($fh, $fd, strlen($fd)); + @fwrite($fh, $fd, \strlen($fd)); @fflush($fh); @fclose($fh); @@ -779,14 +779,14 @@ protected function getImageType(): void } // First try exif_imagetype(). - if (function_exists('exif_imagetype') && ($type = exif_imagetype($this->source)) !== false) { + if (\function_exists('exif_imagetype') && ($type = exif_imagetype($this->source)) !== false) { $this->type = $type; return; } // Next try getimagesize(). - if (function_exists('getimagesize') && ($sizes = @getimagesize($this->source)) !== false) { + if (\function_exists('getimagesize') && ($sizes = @getimagesize($this->source)) !== false) { list($this->width, $this->height, $this->type) = $sizes; return; @@ -816,7 +816,7 @@ protected function getImageType(): void */ protected function checkForEmbeddedThumb(): void { - $this->embedded_thumb = $this->mime_type !== 'image/svg+xml' && function_exists('exif_read_data') && @exif_read_data($this->source, 'THUMBNAIL') !== false; + $this->embedded_thumb = $this->mime_type !== 'image/svg+xml' && \function_exists('exif_read_data') && @exif_read_data($this->source, 'THUMBNAIL') !== false; } /** @@ -832,7 +832,7 @@ protected function getDimensionsAndOrientation(): void } // First try exif_read_data(). - if (function_exists('exif_read_data') && ($exif_data = @exif_read_data($this->source)) !== false) { + if (\function_exists('exif_read_data') && ($exif_data = @exif_read_data($this->source)) !== false) { if (isset($exif_data['Orientation'])) { $this->orientation = $exif_data['Orientation']; } @@ -846,7 +846,7 @@ protected function getDimensionsAndOrientation(): void } // Next try ImageMagick. - if (extension_loaded('imagick')) { + if (\extension_loaded('imagick')) { $imagick = new \Imagick($this->source); try { @@ -864,7 +864,7 @@ protected function getDimensionsAndOrientation(): void } // Finally, try getimagesize(). This can't tell us orientation. - if (function_exists('getimagesize') && ($sizes = @getimagesize($this->source)) !== false) { + if (\function_exists('getimagesize') && ($sizes = @getimagesize($this->source)) !== false) { list($this->width, $this->height, $this->type) = $sizes; } } @@ -1122,7 +1122,7 @@ protected function resizeUsingGD(string $destination, int $max_width, int $max_h $imagesave = 'image' . strtolower(substr(array_search($preferred_type, self::$supported), 10)); // Do the functions exist? - if (!function_exists($imagecreatefrom) || !function_exists($imagesave)) { + if (!\function_exists($imagecreatefrom) || !\function_exists($imagesave)) { return false; } @@ -1157,7 +1157,7 @@ protected function resizeUsingGD(string $destination, int $max_width, int $max_h if ($preferred_type == IMAGETYPE_PNG) { imagealphablending($dst_img, false); - if (function_exists('imagesavealpha')) { + if (\function_exists('imagesavealpha')) { imagesavealpha($dst_img, true); } } @@ -1185,7 +1185,7 @@ protected function resizeUsingGD(string $destination, int $max_width, int $max_h break; } - if (in_array($this->orientation, [2, 4, 5, 7])) { + if (\in_array($this->orientation, [2, 4, 5, 7])) { imageflip($dst_img, IMG_FLIP_HORIZONTAL); } } @@ -1246,7 +1246,7 @@ protected function resizeUsingImagick(string $destination, int $max_width, int $ break; } - if (in_array($this->orientation, [2, 4, 5, 7])) { + if (\in_array($this->orientation, [2, 4, 5, 7])) { $imagick->flopImage(); } } diff --git a/Sources/Group.php b/Sources/Group.php index ac0cc8af2b..12214f8b63 100644 --- a/Sources/Group.php +++ b/Sources/Group.php @@ -365,7 +365,7 @@ public function __construct(int $id, array $props = []) self::$loaded[$this->id] = $this; // Some special cases. - if (in_array($this->id, [self::GUEST, self::REGULAR])) { + if (\in_array($this->id, [self::GUEST, self::REGULAR])) { if (empty($this->name)) { if ($this->id === self::GUEST || !isset(Lang::$txt['announce_regular_members'])) { Lang::load('Admin'); @@ -399,7 +399,7 @@ public function __construct(int $id, array $props = []) public function __set(string $prop, mixed $value): void { // Special handling for the icons. - if ($prop === 'icons' && is_string($value)) { + if ($prop === 'icons' && \is_string($value)) { $prop = 'raw_icons'; if (preg_match('/^\d+#/', $value)) { @@ -957,7 +957,7 @@ public function addMembers(int|array $members, string $type = 'auto', bool $perm } } - if (!in_array($type, ['auto', 'only_additional', 'only_primary', 'force_primary'])) { + if (!\in_array($type, ['auto', 'only_additional', 'only_primary', 'force_primary'])) { Lang::load('Errors'); trigger_error(Lang::getTxt('add_members_to_group_invalid_type', [$type]), E_USER_WARNING); } @@ -971,7 +971,7 @@ public function addMembers(int|array $members, string $type = 'auto', bool $perm } // Some groups just don't like explicitly having members. - if (in_array($this->id, [self::GUEST, self::REGULAR, self::MOD])) { + if (\in_array($this->id, [self::GUEST, self::REGULAR, self::MOD])) { return false; } @@ -1028,7 +1028,7 @@ public function addMembers(int|array $members, string $type = 'auto', bool $perm } } // They're already in this group. - elseif (in_array($this->id, User::$loaded[$id_member]->groups)) { + elseif (\in_array($this->id, User::$loaded[$id_member]->groups)) { continue; } // They have a different primary group. @@ -1157,7 +1157,7 @@ public function removeMembers(int|array $members, bool $perms_checked = false, b } } - if (in_array($this->id, [self::GUEST, self::REGULAR, self::MOD])) { + if (\in_array($this->id, [self::GUEST, self::REGULAR, self::MOD])) { return false; } @@ -1209,7 +1209,7 @@ public function removeMembers(int|array $members, bool $perms_checked = false, b $remove_primary[] = $member; } - if (in_array($this->id, User::$loaded[$member]->additional_groups)) { + if (\in_array($this->id, User::$loaded[$member]->additional_groups)) { $remove_additional[] = $member; } } @@ -1572,7 +1572,7 @@ public function updateBoardAccess(array $board_access): void $prop = $access == 'allow' ? 'member_groups' : 'deny_groups'; foreach (Board::$loaded as $board) { - if (in_array($board->id, $board_ids)) { + if (\in_array($board->id, $board_ids)) { $board->{$prop} = array_unique(array_merge($board->{$prop}, [$this->id])); } else { $board->{$prop} = array_diff($board->{$prop}, [$this->id]); @@ -1698,19 +1698,19 @@ public static function loadSimple(int $include = self::LOAD_NORMAL, array $exclu // If we are including normal groups, do we want guests and regular members? if ($include & self::LOAD_NORMAL) { // Do we want the guest group? - if (!in_array(self::GUEST, $exclude)) { + if (!\in_array(self::GUEST, $exclude)) { $loaded = array_merge($loaded, self::load(-1)); } // Do we want the regular members group? - if (!in_array(self::REGULAR, $exclude)) { + if (!\in_array(self::REGULAR, $exclude)) { $loaded = array_merge($loaded, self::load(0)); } } // Finally, exclude any groups we don't want. foreach ($exclude as $id) { - if (!is_int($id) || $id <= 0) { + if (!\is_int($id) || $id <= 0) { continue; } @@ -1826,7 +1826,7 @@ public static function loadModeratorsBatch(array $group_ids, bool $ignore_protec $group = self::$loaded[$row['id_group']]; $group->moderator_ids[] = $row['id_member']; - $group->can_moderate = $group->can_moderate || in_array(User::$me->id, $group->moderator_ids); + $group->can_moderate = $group->can_moderate || \in_array(User::$me->id, $group->moderator_ids); $mod_ids[] = $row['id_member']; } @@ -1892,7 +1892,7 @@ public static function countMembersBatch(array $group_ids, bool $recount = false if (!empty($moderator_group)) { // If we're in a board, only count the moderators for that board. if (isset(Board::$info)) { - self::$loaded[self::MOD]->num_members = count(Board::$info->moderators); + self::$loaded[self::MOD]->num_members = \count(Board::$info->moderators); } // Outside a board, count the moderators for all boards. else { @@ -2386,7 +2386,7 @@ protected static function isProtected(self $group): bool */ protected static function isModeratorGroup(self $group): bool { - return count($group->getBoardsCanModerate()) > 0; + return \count($group->getBoardsCanModerate()) > 0; } /** @@ -2507,7 +2507,7 @@ protected static function canSearch(self $group): bool */ protected static function canLeave(self $group): bool { - return $group->id !== self::ADMIN && !in_array($group->id, self::getUnassignable()); + return $group->id !== self::ADMIN && !\in_array($group->id, self::getUnassignable()); } /** diff --git a/Sources/IP.php b/Sources/IP.php index f37c239faa..9a77dfb55c 100644 --- a/Sources/IP.php +++ b/Sources/IP.php @@ -178,7 +178,7 @@ public function getHost(int $timeout = 1000): string // If we don't need to set a timeout, use PHP's native function. if (empty($timeout)) { - $host = \gethostbyaddr($this->ip); + $host = gethostbyaddr($this->ip); } // Try asking the operating system to look it up for us. @@ -339,7 +339,7 @@ public static function ip2range(string $addr): array $range[1] = [$ranged[1]]; } - while (filter_var(implode($mode, $range[0]), FILTER_VALIDATE_IP) === false && count($range[0]) < count($octets)) { + while (filter_var(implode($mode, $range[0]), FILTER_VALIDATE_IP) === false && \count($range[0]) < \count($octets)) { $range[0][] = $min; } @@ -370,13 +370,13 @@ public static function ip2range(string $addr): array // Finalize the strings. foreach ([0, 1] as $key) { // If it's too long, shorten it. - if (count($range[$key]) > $max_parts) { - $range[$key] = array_slice($range[$key], 0, $max_parts); + if (\count($range[$key]) > $max_parts) { + $range[$key] = \array_slice($range[$key], 0, $max_parts); } // If they're still too short, pad them out. - while (filter_var(implode($mode, $range[$key]), FILTER_VALIDATE_IP) === false && count($range[$key]) < $max_parts) { - if (in_array('*', $range[$key])) { + while (filter_var(implode($mode, $range[$key]), FILTER_VALIDATE_IP) === false && \count($range[$key]) < $max_parts) { + if (\in_array('*', $range[$key])) { $range[$key] = explode($mode, preg_replace('/\*(?!' . preg_quote($mode . '*') . ')/', '*' . $mode . '*', implode($mode, $range[$key]))); } else { $range[$key][] = '*'; @@ -445,7 +445,7 @@ public static function range2ip(string|IP $low, string|IP $high): string */ protected function hostLookup(int $timeout = 1000): string { - if (!function_exists('shell_exec')) { + if (!\function_exists('shell_exec')) { return ''; } @@ -580,7 +580,7 @@ protected function getReverseDnsQuery(): string // The interesting stuff. foreach ($parts as $part) { - $query .= chr(strlen($part)) . $part; + $query .= \chr(\strlen($part)) . $part; } // And the final bit of the request. diff --git a/Sources/IntegrationHook.php b/Sources/IntegrationHook.php index 2444db6f93..837ef36da0 100644 --- a/Sources/IntegrationHook.php +++ b/Sources/IntegrationHook.php @@ -114,8 +114,8 @@ public function execute(array $parameters = []): array // Loop through each callable. foreach ($this->callables as $func_string => $callable) { // Is it valid? - if (is_callable($callable)) { - $this->results[$func_string] = call_user_func_array($callable, $parameters); + if (\is_callable($callable)) { + $this->results[$func_string] = \call_user_func_array($callable, $parameters); } // This failed, but we want to do so silently. elseif ($this->ignore_errors) { @@ -195,7 +195,7 @@ public static function add(string $name, string $function, bool $permanent = tru } // Any files to load? - if (!empty($file) && is_string($file)) { + if (!empty($file) && \is_string($file)) { $function = $file . (!empty($function) ? '|' . $function : ''); } @@ -279,7 +279,7 @@ public static function remove(string $name, string $function, bool $permanent = } // Any files to load? - if (!empty($file) && is_string($file)) { + if (!empty($file) && \is_string($file)) { $function = $file . '|' . $function; } diff --git a/Sources/ItemList.php b/Sources/ItemList.php index 50d6785fae..700f4ef83e 100644 --- a/Sources/ItemList.php +++ b/Sources/ItemList.php @@ -243,7 +243,7 @@ public static function load(array $options): self protected function checkOptions(array $options): bool { $have_what_we_need = isset($options['id']); - $have_what_we_need &= isset($options['columns']) && is_array($options['columns']); + $have_what_we_need &= isset($options['columns']) && \is_array($options['columns']); $have_what_we_need &= empty($options['default_sort_col']) || isset($options['columns'][$options['default_sort_col']]); $have_what_we_need &= !isset($options['form']) || isset($options['form']['href']); @@ -265,7 +265,7 @@ protected function setBasics(): void } // We know the amount of columns, might be useful for the template. - $this->num_columns = count($this->options['columns']); + $this->num_columns = \count($this->options['columns']); if (!empty($this->options['width'])) { $this->width = $this->options['width']; @@ -328,7 +328,7 @@ protected function setStartAndItemsPerPage(): void } // First get an impression of how many items to expect. - if (isset($this->options['get_count']['value']) && (is_int($this->options['get_count']['value']) || ctype_digit($this->options['get_count']['value']))) { + if (isset($this->options['get_count']['value']) && (\is_int($this->options['get_count']['value']) || ctype_digit($this->options['get_count']['value']))) { $this->total_num_items = $this->options['get_count']['value']; } else { if (isset($this->options['get_count']['file'])) { @@ -339,7 +339,7 @@ protected function setStartAndItemsPerPage(): void $params = $this->options['get_count']['params'] ?? []; - $this->total_num_items = (int) call_user_func_array($call, array_values($params)); + $this->total_num_items = (int) \call_user_func_array($call, array_values($params)); } // Default the start to the beginning...sounds logical. @@ -426,7 +426,7 @@ protected function buildRows(): void } // The most flexible way probably is applying a custom function. elseif (isset($column['data']['function'])) { - $cur_data['value'] = call_user_func_array($column['data']['function'], [$list_item]); + $cur_data['value'] = \call_user_func_array($column['data']['function'], [$list_item]); } // A modified value (inject the database values). elseif (isset($column['data']['eval'])) { @@ -483,7 +483,7 @@ protected function buildRows(): void */ protected function getItems(): void { - if (!empty($this->options['get_items']['value']) && is_array($this->options['get_items']['value'])) { + if (!empty($this->options['get_items']['value']) && \is_array($this->options['get_items']['value'])) { $this->items = $this->options['get_items']['value']; } else { // Get the file with the function for the item list. @@ -493,7 +493,7 @@ protected function getItems(): void $call = Utils::getCallable($this->options['get_items']['function']); - $items = call_user_func_array($call, array_merge([$this->start, $this->items_per_page, $this->db_sort], empty($this->options['get_items']['params']) ? [] : $this->options['get_items']['params'])); + $items = \call_user_func_array($call, array_merge([$this->start, $this->items_per_page, $this->db_sort], empty($this->options['get_items']['params']) ? [] : $this->options['get_items']['params'])); $this->items = empty($items) ? [] : $items; } diff --git a/Sources/Lang.php b/Sources/Lang.php index 2c2af10e61..1f5d9ba785 100644 --- a/Sources/Lang.php +++ b/Sources/Lang.php @@ -251,7 +251,7 @@ public static function load(string $template_name, string $lang = '', bool $fata } // Fall back to English if none of the preferred languages can be found. - if (empty(Config::$modSettings['disable_language_fallback']) && !in_array('en_US', [$lang, self::$default])) { + if (empty(Config::$modSettings['disable_language_fallback']) && !\in_array('en_US', [$lang, self::$default])) { foreach (self::$dirs as $dir) { $attempts[] = [$dir, $template, 'en_US']; } @@ -527,12 +527,12 @@ public static function get(bool $use_cache = true): array public static function getTxt(string|array $txt_key, array $args = [], string $var = 'txt'): string { // Validate $var. - if (!in_array($var, ['txt', 'tztxt', 'editortxt', 'helptxt', 'txtBirthdayEmails'])) { + if (!\in_array($var, ['txt', 'tztxt', 'editortxt', 'helptxt', 'txtBirthdayEmails'])) { throw new \ValueError(); } // Don't waste time when getting a simple string. - if ($args === [] && is_string($txt_key)) { + if ($args === [] && \is_string($txt_key)) { return self::${$var}[$txt_key] ?? ''; } @@ -551,7 +551,7 @@ public static function getTxt(string|array $txt_key, array $args = [], string $v } } - if (!is_scalar($target)) { + if (!\is_scalar($target)) { throw new \ValueError(); } @@ -562,8 +562,8 @@ public static function getTxt(string|array $txt_key, array $args = [], string $v // Workaround for a CrowdIn limitation that won't allow translators to // change offset values in strings. if ( - count($txt_key) === 0 - && in_array($txt_key[0], ['ordinal_last', 'ordinal_spellout_last']) + \count($txt_key) === 0 + && \in_array($txt_key[0], ['ordinal_last', 'ordinal_spellout_last']) && isset(self::$txt['ordinal_last_offset']) ) { $target = str_replace( @@ -592,7 +592,7 @@ public static function censorText(string &$text, bool $force = false): string { static $censor_vulgar = null, $censor_proper; - if ((!empty(Theme::$current->options['show_no_censored']) && !empty(Config::$modSettings['allow_no_censored']) && !$force) || empty(Config::$modSettings['censor_vulgar']) || !is_string($text) || trim($text) === '') { + if ((!empty(Theme::$current->options['show_no_censored']) && !empty(Config::$modSettings['allow_no_censored']) && !$force) || empty(Config::$modSettings['censor_vulgar']) || !\is_string($text) || trim($text) === '') { return $text; } @@ -712,7 +712,7 @@ public static function sentenceList(array $list, string $type = 'and'): string } // If we have a pattern for this exact number of items, use it. - $args = array_merge(['list_pattern_part' => count($list)], $list); + $args = array_merge(['list_pattern_part' => \count($list)], $list); $sentence_list = self::formatText(self::$txt['sentence_list_pattern'][$type], $args); // Otherwise, build the list normally. @@ -722,7 +722,7 @@ public static function sentenceList(array $list, string $type = 'and'): string $sentence_list = self::formatText(self::$txt['sentence_list_pattern'][$type], $args); // Then iteratively prepend items using the "middle" pattern. - while (count($list) > 1) { + while (\count($list) > 1) { $args = ['list_pattern_part' => 'middle', array_pop($list), $sentence_list]; $sentence_list = self::formatText(self::$txt['sentence_list_pattern'][$type], $args); } @@ -752,7 +752,7 @@ public static function numberFormat(int|float|string $number, ?int $decimals = n throw new \ValueError(); } - if (is_string($number)) { + if (\is_string($number)) { $number = $number + 0; } @@ -770,7 +770,7 @@ public static function numberFormat(int|float|string $number, ?int $decimals = n } } - $skeleton = is_int($number) ? 'integer' : ':: .' . str_repeat('0', $decimals ?? 2); + $skeleton = \is_int($number) ? 'integer' : ':: .' . str_repeat('0', $decimals ?? 2); return MessageFormatter::formatMessage('{0, number, ' . $skeleton . '}', [$number]); } @@ -820,7 +820,7 @@ public static function getLocaleFromLanguageName(string $lang): ?string // Already a locale? // Note: we can't just do in_array($lang, self::LANG_TO_LOCALE) because // new language packs added after 2.1 won't be in self::LANG_TO_LOCALE. - if (strlen($lang) === 2 || substr($lang, 2, 1) === '_') { + if (\strlen($lang) === 2 || substr($lang, 2, 1) === '_') { return $lang; } @@ -885,7 +885,7 @@ public static function loadOld(array $attempts): bool } // Export properties to global namespace for backward compatibility. -if (is_callable([Lang::class, 'exportStatic'])) { +if (\is_callable([Lang::class, 'exportStatic'])) { Lang::exportStatic(); } diff --git a/Sources/Localization/MessageFormatter.php b/Sources/Localization/MessageFormatter.php index 0cc159204e..a849c89801 100644 --- a/Sources/Localization/MessageFormatter.php +++ b/Sources/Localization/MessageFormatter.php @@ -112,7 +112,7 @@ public static function formatMessage(string $message, array $args = []): string ]; foreach ($args as $arg => $value) { - if (!is_string($value)) { + if (!\is_string($value)) { continue; } @@ -230,7 +230,7 @@ public static function formatMessage(string $message, array $args = []): string break; default: - $skeleton = is_int($args[$arg_name] + 0) ? '' : '.000'; + $skeleton = \is_int($args[$arg_name] + 0) ? '' : '.000'; $final .= self::applyNumberSkeleton($args[$arg_name] ?? 0, $skeleton); break; } @@ -247,7 +247,7 @@ public static function formatMessage(string $message, array $args = []): string $args[$arg_name] = Time::createFromInterface($args[$arg_name]); } elseif (is_numeric($args[$arg_name])) { $args[$arg_name] = new Time('@' . $args[$arg_name], User::getTimezone()); - } elseif (is_string($args[$arg_name])) { + } elseif (\is_string($args[$arg_name])) { $args[$arg_name] = date_create($args[$arg_name]); if ($args[$arg_name] === false) { @@ -288,7 +288,7 @@ public static function formatMessage(string $message, array $args = []): string $args[$arg_name] = Time::createFromInterface($args[$arg_name]); } elseif (is_numeric($args[$arg_name])) { $args[$arg_name] = new Time('@' . $args[$arg_name], User::getTimezone()); - } elseif (is_string($args[$arg_name])) { + } elseif (\is_string($args[$arg_name])) { $args[$arg_name] = date_create($args[$arg_name]); if ($args[$arg_name] === false) { @@ -339,7 +339,7 @@ public static function formatMessage(string $message, array $args = []): string if (str_starts_with($rest, 'offset:')) { preg_match('/^offset:(\d+)/', $rest, $offset_matches); $offset = $offset_matches[1]; - $rest = trim(substr($rest, strlen($offset_matches[0]))); + $rest = trim(substr($rest, \strlen($offset_matches[0]))); } else { $offset = 0; } @@ -369,7 +369,7 @@ public static function formatMessage(string $message, array $args = []): string if (str_starts_with($rest, 'offset:')) { preg_match('/^offset:(\d+)/', $rest, $offset_matches); $offset = $offset_matches[1]; - $rest = trim(substr($rest, strlen($offset_matches[0]))); + $rest = trim(substr($rest, \strlen($offset_matches[0]))); } else { $offset = 0; } @@ -410,7 +410,7 @@ public static function formatMessage(string $message, array $args = []): string break; default: - if (is_scalar($args[$arg_name]) || $args[$arg_name] instanceof \Stringable) { + if (\is_scalar($args[$arg_name]) || $args[$arg_name] instanceof \Stringable) { $final .= (string) $args[$arg_name]; } else { $final .= $part; @@ -441,12 +441,12 @@ protected static function getPluralizationCategory(int|float|string $num, string throw new \ValueError(); } - if (!in_array($type, ['cardinal', 'ordinal'])) { + if (!\in_array($type, ['cardinal', 'ordinal'])) { throw new \ValueError(); } // CLDR pluralization rules use the operands 'n', 'i', 'v', 'w', 'f', 't', and 'c'. - if (is_string($num) && (str_contains($num, 'e') || str_contains($num, 'E'))) { + if (\is_string($num) && (str_contains($num, 'e') || str_contains($num, 'E'))) { $c = substr(strtolower($num), strpos($num, 'e') + 1); $num = (float) $num; } else { @@ -457,8 +457,8 @@ protected static function getPluralizationCategory(int|float|string $num, string $i = (int) $num; $f = substr((string) $num, strpos((string) $num, '.') + 1); $t = rtrim($f, '0'); - $w = strlen($t); - $v = strlen($f); + $w = \strlen($t); + $v = \strlen($f); // Ensure we have our pluralization rules. if (empty(self::$plural_rules)) { @@ -537,8 +537,8 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ break; } - if (strlen($matches[3]) > 1) { - $long_form .= '/*' . str_repeat('e', strlen($matches[3])); + if (\strlen($matches[3]) > 1) { + $long_form .= '/*' . str_repeat('e', \strlen($matches[3])); } }, '/(?<=\s|^)0+(?=\s|$)/' => fn ($matches) => 'integer-width/*' . $matches[0], @@ -627,15 +627,15 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ // Float precision format. if (str_starts_with($stem, '.')) { - $significant_integers = strlen(strval(intval($number + 0))); - $significant_decimals = (int) strpos(strrev(strval($number)), '.'); + $significant_integers = \strlen(\strval(\intval($number + 0))); + $significant_decimals = (int) strpos(strrev(\strval($number)), '.'); preg_match('/\.(0*)(#*)(\*?)/', $stem, $matches); if (!empty($matches[3])) { $precision = $significant_decimals; } else { - $precision = min(max($significant_decimals, strlen($matches[1] ?? '')), strlen($matches[1] ?? '') + strlen($matches[2] ?? '')); + $precision = min(max($significant_decimals, \strlen($matches[1] ?? '')), \strlen($matches[1] ?? '') + \strlen($matches[2] ?? '')); } if (!empty($options)) { @@ -654,7 +654,7 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ preg_match('/(@+)(#*)([*rs]?)/', $option, $matches); if (!empty($matches[1]) && (!empty($matches[1]) || !empty($matches[3]))) { - $min_sig = strlen($matches[1]); + $min_sig = \strlen($matches[1]); if (empty($matches[2])) { if ($matches[3] === '*') { @@ -672,22 +672,22 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ $number = sprintf("%{$flags}.{$precision}F", $round($number, $precision)); - if (!empty($options) && in_array('w', $options) && $number == (int) $number) { - $number = strval(intval($number)); + if (!empty($options) && \in_array('w', $options) && $number == (int) $number) { + $number = \strval(\intval($number)); } } // Significant digits format. elseif (str_starts_with($stem, '@')) { - $significant_integers = strlen(strval(intval($number + 0))); - $significant_decimals = (int) strpos(strrev(strval($number)), '.'); + $significant_integers = \strlen(\strval(\intval($number + 0))); + $significant_decimals = (int) strpos(strrev(\strval($number)), '.'); preg_match('/(@+)(#*)(\*?)/', $stem, $matches); if (!empty($matches[3])) { - $precision = max($significant_decimals, strlen($matches[1]) - $significant_integers); + $precision = max($significant_decimals, \strlen($matches[1]) - $significant_integers); $number = sprintf("%{$flags}.{$precision}F", $round($number, $precision)); } elseif (!empty($matches[2])) { - $precision = min(max($significant_decimals, strlen($matches[1]) - $significant_integers), strlen($matches[1]) + strlen($matches[2]) - $significant_integers); + $precision = min(max($significant_decimals, \strlen($matches[1]) - $significant_integers), \strlen($matches[1]) + \strlen($matches[2]) - $significant_integers); if ($precision >= 0) { $number = sprintf("%{$flags}.{$precision}F", $round($number, $precision)); @@ -695,13 +695,13 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ $number = (string) $round($number, $precision); } } else { - $precision = min(max($significant_decimals, strlen($matches[1]) - $significant_integers), strlen($matches[1]) - $significant_integers); + $precision = min(max($significant_decimals, \strlen($matches[1]) - $significant_integers), \strlen($matches[1]) - $significant_integers); $number = sprintf("%{$flags}.{$precision}F", $round($number, $precision)); } - if (!empty($options) && in_array('w', $options) && $number == (int) $number) { - $number = strval(intval($number)); + if (!empty($options) && \in_array('w', $options) && $number == (int) $number) { + $number = \strval(\intval($number)); } } else { switch ($stem) { @@ -757,8 +757,8 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ $number = $round($number); $number *= $options[0]; - if (is_float($number)) { - $precision = is_float($options[0] + 0) ? strlen($options[0]) - strlen(strval(intval($options[0] + 0))) - 1 : 0; + if (\is_float($number)) { + $precision = \is_float($options[0] + 0) ? \strlen($options[0]) - \strlen(\strval(\intval($options[0] + 0))) - 1 : 0; $number = sprintf("%0.{$precision}F", $number); } @@ -768,17 +768,17 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ case 'integer-width': preg_match('/(\*?)(#*)(0*)/', $options[0], $matches); - $min = strlen($matches[3] ?? ''); - $max = !empty($matches[1]) ? PHP_INT_MAX : strlen($matches[2] ?? '') + strlen($matches[3] ?? ''); + $min = \strlen($matches[3] ?? ''); + $max = !empty($matches[1]) ? PHP_INT_MAX : \strlen($matches[2] ?? '') + \strlen($matches[3] ?? ''); - $number = explode('.', rtrim(sprintf('%' . (is_float($number + 0) ? 'F' : 'd'), $number), '0')); + $number = explode('.', rtrim(sprintf('%' . (\is_float($number + 0) ? 'F' : 'd'), $number), '0')); $number[0] = substr(sprintf("%{$flags}{$min}d", $number[0]), -$max); $number = implode('.', $number); break; case 'integer-width-trunc': - $number = rtrim(sprintf('%' . (is_float($number + 0) ? 'F' : 'd'), $number), '0'); + $number = rtrim(sprintf('%' . (\is_float($number + 0) ? 'F' : 'd'), $number), '0'); $number = str_contains($number, '.') ? substr($number, strpos($number, '.')) : '0'; break; @@ -802,12 +802,12 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ $currency = $currencies[$options[0]]; if ($currency['digits'] === 0) { - $number = strval(intval($number)); + $number = \strval(\intval($number)); } else { $number = sprintf('%0.' . $currency['digits'] . 'F', $number); } - $post_processing[] = fn ($number) => (in_array(substr($number, 0, 1), ['-', '+']) ? substr($number, 0, 1) : '') . strtr(Lang::$txt['currency_format'], ['{0}' => in_array(substr($number, 0, 1), ['-', '+']) ? substr($number, 1) : $number, '¤' => self::CURRENCY_SYMBOLS[$options[0]] ?? ($options[0] === 'DEFAULT' ? '¤' : $options[0] . "\u{A0}")]); + $post_processing[] = fn ($number) => (\in_array(substr($number, 0, 1), ['-', '+']) ? substr($number, 0, 1) : '') . strtr(Lang::$txt['currency_format'], ['{0}' => \in_array(substr($number, 0, 1), ['-', '+']) ? substr($number, 1) : $number, '¤' => self::CURRENCY_SYMBOLS[$options[0]] ?? ($options[0] === 'DEFAULT' ? '¤' : $options[0] . "\u{A0}")]); break; @@ -866,10 +866,10 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ } // Ensure $number is a string. - if (is_float($number)) { - $precision = (int) strpos(strrev(strval($number)), '.'); + if (\is_float($number)) { + $precision = (int) strpos(strrev(\strval($number)), '.'); $number = sprintf("%{$flags}.{$precision}F", $number); - } elseif (is_int($number)) { + } elseif (\is_int($number)) { $number = sprintf("%{$flags}d", $number); } @@ -890,7 +890,7 @@ protected static function applyNumberSkeleton(int|float|string $number, string $ $prefix = substr($number[0], 0, strcspn($number[0], '1234567890')); $number[0] = substr($number[0], strcspn($number[0], '1234567890')); - while (strlen($number[0]) % 3 !== 0) { + while (\strlen($number[0]) % 3 !== 0) { $number[0] = ' ' . $number[0]; } diff --git a/Sources/Logging.php b/Sources/Logging.php index 6cc52a09eb..72269b3bfe 100644 --- a/Sources/Logging.php +++ b/Sources/Logging.php @@ -94,11 +94,11 @@ public static function logActions(array $logs): int IntegrationHook::call('integrate_log_types', [&$log_types, &$always_log]); foreach ($logs as $log) { - if (!isset($log_types[$log['log_type']]) && (empty(Config::$modSettings[$log['log_type'] . 'log_enabled']) || !in_array($log['action'], $always_log))) { + if (!isset($log_types[$log['log_type']]) && (empty(Config::$modSettings[$log['log_type'] . 'log_enabled']) || !\in_array($log['action'], $always_log))) { continue; } - if (!is_array($log['extra'])) { + if (!\is_array($log['extra'])) { Lang::load('Errors'); trigger_error(Lang::getTxt('logActions_not_array', [$log['action']]), E_USER_NOTICE); } @@ -128,7 +128,7 @@ public static function logActions(array $logs): int // @todo cache this? // Is there an associated report on this? - if (in_array($log['action'], ['move', 'remove', 'split', 'merge'])) { + if (\in_array($log['action'], ['move', 'remove', 'split', 'merge'])) { $request = Db::$db->query( '', 'SELECT id_report @@ -387,7 +387,7 @@ public static function updateStats(string $type, mixed $parameter1 = null, mixed case 'postgroups': // Parameter two is the updated columns: we should check to see if we base groups off any of these. - if ($parameter2 !== null && !in_array('posts', $parameter2)) { + if ($parameter2 !== null && !\in_array('posts', $parameter2)) { return; } @@ -433,7 +433,7 @@ public static function updateStats(string $type, mixed $parameter1 = null, mixed SET id_post_group = CASE ' . $conditions . ' ELSE 0 END' . ($parameter1 != null ? ' - WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''), + WHERE ' . (\is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''), [ 'members' => $parameter1, ], @@ -616,7 +616,7 @@ public static function getMembersOnlineStats(array $membersOnlineOptions): array } // Not allowed sort method? Bang! Error! - elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) { + elseif (!\in_array($membersOnlineOptions['sort'], $allowed_sort_options)) { Lang::load('Errors'); trigger_error(Lang::$txt['get_members_online_stats_invalid_sort'], E_USER_NOTICE); } @@ -692,7 +692,7 @@ public static function getMembersOnlineStats(array $membersOnlineOptions): array } // Buddies get counted and highlighted. - $is_buddy = in_array($row['id_member'], User::$me->buddies); + $is_buddy = \in_array($row['id_member'], User::$me->buddies); if ($is_buddy) { $membersOnlineStats['num_buddies']++; @@ -770,7 +770,7 @@ public static function getMembersOnlineStats(array $membersOnlineOptions): array ksort($membersOnlineStats['online_groups']); // Hidden and non-hidden members make up all online members. - $membersOnlineStats['num_users_online'] = count($membersOnlineStats['users_online']) + $membersOnlineStats['num_users_hidden'] - (isset(Config::$modSettings['show_spider_online']) && Config::$modSettings['show_spider_online'] > 1 ? count($spider_finds) : 0); + $membersOnlineStats['num_users_online'] = \count($membersOnlineStats['users_online']) + $membersOnlineStats['num_users_hidden'] - (isset(Config::$modSettings['show_spider_online']) && Config::$modSettings['show_spider_online'] > 1 ? \count($spider_finds) : 0); IntegrationHook::call('integrate_online_stats', [&$membersOnlineStats]); @@ -802,7 +802,7 @@ public static function displayDebug(): void $files = get_included_files(); $total_size = 0; - for ($i = 0, $n = count($files); $i < $n; $i++) { + for ($i = 0, $n = \count($files); $i < $n; $i++) { if (file_exists($files[$i])) { $total_size += filesize($files[$i]); } @@ -815,7 +815,7 @@ public static function displayDebug(): void if (!empty(Db::$cache)) { foreach (Db::$cache as $q => $query_data) { if (!empty($query_data['w'])) { - $warnings += count($query_data['w']); + $warnings += \count($query_data['w']); } } @@ -837,49 +837,49 @@ public static function displayDebug(): void Lang::getTxt( 'debug_templates', [ - 'num' => count(Utils::$context['debug']['templates']), + 'num' => \count(Utils::$context['debug']['templates']), 'additional_info' => '(' . implode(', ', Utils::$context['debug']['templates']) . ')', ], ), Lang::getTxt( 'debug_subtemplates', [ - 'num' => count(Utils::$context['debug']['sub_templates']), + 'num' => \count(Utils::$context['debug']['sub_templates']), 'additional_info' => '(' . implode(', ', Utils::$context['debug']['sub_templates']) . ')', ], ), Lang::getTxt( 'debug_language_files', [ - 'num' => count(Utils::$context['debug']['language_files']), + 'num' => \count(Utils::$context['debug']['language_files']), 'additional_info' => '(' . implode(', ', Utils::$context['debug']['language_files']) . ')', ], ), Lang::getTxt( 'debug_stylesheets', [ - 'num' => count(Utils::$context['debug']['sheets']), + 'num' => \count(Utils::$context['debug']['sheets']), 'additional_info' => '(' . implode(', ', Utils::$context['debug']['sheets']) . ')', ], ), Lang::getTxt( 'debug_hooks', [ - 'num' => count(Utils::$context['debug']['hooks'] ?? []), + 'num' => \count(Utils::$context['debug']['hooks'] ?? []), 'additional_info' => '(' . Lang::$txt['debug_show'] . '' . implode(', ', Utils::$context['debug']['hooks']) . ')', ], ), Lang::getTxt( 'debug_files_included', [ - 'num' => count($files), + 'num' => \count($files), 'size' => round($total_size / 1024), 'additional_info' => '(' . Lang::$txt['debug_show'] . '' . implode(', ', $files) . ')', ], ), ]; - if (function_exists('memory_get_peak_usage')) { + if (\function_exists('memory_get_peak_usage')) { $debug_info[] = Lang::getTxt('debug_memory_use', ['size' => ceil(memory_get_peak_usage() / 1024)]); } diff --git a/Sources/Mail.php b/Sources/Mail.php index c0c57b1c07..1950d7a256 100644 --- a/Sources/Mail.php +++ b/Sources/Mail.php @@ -64,7 +64,7 @@ public static function send( $mail_result = true; // If the recipient list isn't an array, make it one. - $to_array = is_array($to) ? $to : [$to]; + $to_array = \is_array($to) ? $to : [$to]; // Make sure we actually have email addresses to send this to foreach ($to_array as $k => $v) { @@ -132,7 +132,7 @@ public static function send( $headers .= 'X-Mailer: SMF' . $line_break; // Pass this to the integration before we start modifying the output -- it'll make it easier later. - if (in_array(false, IntegrationHook::call('integrate_outgoing_email', [&$subject, &$message, &$headers, &$to_array]), true)) { + if (\in_array(false, IntegrationHook::call('integrate_outgoing_email', [&$subject, &$message, &$headers, &$to_array]), true)) { return false; } @@ -318,7 +318,7 @@ public static function addToQueue( foreach ($to_array as $to) { // Will this insert go over MySQL's limit? - $this_insert_len = strlen($to) + strlen($message) + strlen($headers) + 700; + $this_insert_len = \strlen($to) + \strlen($message) + \strlen($headers) + 700; // Insert limit of 1M (just under the safety) is reached? if ($this_insert_len + $cur_insert_len > 1000000) { @@ -474,7 +474,7 @@ public static function reduceQueue(bool|int $number = false, bool $override_limi } // Don't believe we have any left? - if (count($ids) < $number) { + if (\count($ids) < $number) { // Only update the setting if no-one else has beaten us to it. Db::$db->query( '', @@ -646,13 +646,13 @@ public static function mimespecialchars(string $string, bool $with_charset = tru $string = preg_replace_callback( '~(\d{3,8});~', function ($m) { - return chr((int) "{$m[1]}"); + return \chr((int) "{$m[1]}"); }, $string, ); } else { // Try to convert the string to UTF-8. - if (!Utils::$context['utf8'] && function_exists('iconv')) { + if (!Utils::$context['utf8'] && \function_exists('iconv')) { $newstring = @iconv(Utils::$context['character_set'], 'UTF-8', $string); if ($newstring) { @@ -668,8 +668,8 @@ function ($m) { } // Convert all special characters to HTML entities...just for Hotmail :-\ - if ($hotmail_fix && (Utils::$context['utf8'] || function_exists('iconv') || Utils::$context['character_set'] === 'ISO-8859-1')) { - if (!Utils::$context['utf8'] && function_exists('iconv')) { + if ($hotmail_fix && (Utils::$context['utf8'] || \function_exists('iconv') || Utils::$context['character_set'] === 'ISO-8859-1')) { + if (!Utils::$context['utf8'] && \function_exists('iconv')) { $newstring = @iconv(Utils::$context['character_set'], 'UTF-8', $string); if ($newstring) { @@ -680,20 +680,20 @@ function ($m) { $entityConvert = function ($m) { $c = $m[1]; - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { + if (\strlen($c) === 1 && \ord($c[0]) <= 0x7F) { return $c; } - if (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { - return '' . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ';'; + if (\strlen($c) === 2 && \ord($c[0]) >= 0xC0 && \ord($c[0]) <= 0xDF) { + return '' . (((\ord($c[0]) ^ 0xC0) << 6) + (\ord($c[1]) ^ 0x80)) . ';'; } - if (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { - return '' . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ';'; + if (\strlen($c) === 3 && \ord($c[0]) >= 0xE0 && \ord($c[0]) <= 0xEF) { + return '' . (((\ord($c[0]) ^ 0xE0) << 12) + ((\ord($c[1]) ^ 0x80) << 6) + (\ord($c[2]) ^ 0x80)) . ';'; } - if (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { - return '' . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ';'; + if (\strlen($c) === 4 && \ord($c[0]) >= 0xF0 && \ord($c[0]) <= 0xF7) { + return '' . (((\ord($c[0]) ^ 0xF0) << 18) + ((\ord($c[1]) ^ 0x80) << 12) + ((\ord($c[2]) ^ 0x80) << 6) + (\ord($c[3]) ^ 0x80)) . ';'; } return ''; @@ -794,9 +794,9 @@ public static function sendSmtp(array $mail_to_array, string $subject, string $m // Can't rely on $_SERVER['SERVER_NAME'] because it can be spoofed on Apache if (empty($helo)) { // See if we can get the domain name from the host itself - if (function_exists('gethostname')) { + if (\function_exists('gethostname')) { $helo = gethostname(); - } elseif (function_exists('php_uname')) { + } elseif (\function_exists('php_uname')) { $helo = php_uname('n'); } @@ -819,7 +819,7 @@ public static function sendSmtp(array $mail_to_array, string $subject, string $m $helo = substr($helo, 4); } - if (!function_exists('idn_to_ascii')) { + if (!\function_exists('idn_to_ascii')) { require_once Config::$sourcedir . '/Subs-Compat.php'; } @@ -827,7 +827,7 @@ public static function sendSmtp(array $mail_to_array, string $subject, string $m } // SMTP = 1, SMTP - STARTTLS = 2 - if (in_array(Config::$modSettings['mail_type'], [1, 2]) && Config::$modSettings['smtp_username'] != '' && Config::$modSettings['smtp_password'] != '') { + if (\in_array(Config::$modSettings['mail_type'], [1, 2]) && Config::$modSettings['smtp_username'] != '' && Config::$modSettings['smtp_password'] != '') { // EHLO could be understood to mean encrypted hello... if (self::serverParse('EHLO ' . $helo, $socket, null, $response) == '250') { // Are we using STARTTLS and does the server support STARTTLS? @@ -840,7 +840,7 @@ public static function sendSmtp(array $mail_to_array, string $subject, string $m // php 5.6+ fix $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; - if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { + if (\defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; } @@ -906,7 +906,7 @@ public static function sendSmtp(array $mail_to_array, string $subject, string $m } fputs($socket, 'Subject: ' . $subject . "\r\n"); - if (strlen($mail_to) > 0) { + if (\strlen($mail_to) > 0) { fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); } fputs($socket, $headers . "\r\n\r\n"); @@ -973,7 +973,7 @@ public static function serverParse(?string $message, mixed $socket, ?string $cod * 450 - DNS Routing issues * 451 - cPanel "Temporary local problem - please try later" */ - if ($response_code < 500 && !in_array($response_code, [450, 451])) { + if ($response_code < 500 && !\in_array($response_code, [450, 451])) { ErrorHandler::log(Lang::getTxt('smtp_error', [$server_response])); } @@ -1005,7 +1005,7 @@ public static function sendNotifications(int|array $topics, string $type, array // It must be an array - it must! // @TODO: $topics = (array) $topics; - if (!is_array($topics)) { + if (!\is_array($topics)) { $topics = [$topics]; } diff --git a/Sources/Mentions.php b/Sources/Mentions.php index c91effd860..d3873d8c93 100644 --- a/Sources/Mentions.php +++ b/Sources/Mentions.php @@ -214,7 +214,7 @@ public static function getMentionedMembers(string $body): array [ 'ids' => array_keys($existing_mentions), 'names' => $possible_names, - 'count' => count($possible_names), + 'count' => \count($possible_names), ], ); $members = []; @@ -287,12 +287,12 @@ protected static function getPossibleMentions(string $body): array } for ($i = $depth; $i > 0; $i--) { - if (count($matches[count($matches) - $i]) > 60) { + if (\count($matches[\count($matches) - $i]) > 60) { $depth--; continue; } - $matches[count($matches) - $i][] = $char; + $matches[\count($matches) - $i][] = $char; } } @@ -307,10 +307,10 @@ protected static function getPossibleMentions(string $body): array foreach ($matches as $match) { // '[^\p{L}\p{M}\p{N}_]' is the Unicode equivalent of '[^\w]' $match = preg_split('/([^\p{L}\p{M}\p{N}_])/u', $match, -1, PREG_SPLIT_DELIM_CAPTURE); - $count = count($match); + $count = \count($match); for ($i = 1; $i <= $count; $i++) { - $names[] = Utils::htmlspecialchars(Utils::htmlTrim(implode('', array_slice($match, 0, $i)))); + $names[] = Utils::htmlspecialchars(Utils::htmlTrim(implode('', \array_slice($match, 0, $i)))); } } @@ -440,7 +440,7 @@ public static function getQuotedMembers(string $body, int $poster_id): array LIMIT {int:count}', [ 'msgs' => array_unique($id_msgs), - 'count' => count(array_unique($id_msgs)), + 'count' => \count(array_unique($id_msgs)), ], ); @@ -470,7 +470,7 @@ protected static function setExcludedBbcRegex(): void // Exclude everything with unparsed content. foreach (BBCodeParser::getCodes() as $code) { - if (!empty($code['type']) && in_array($code['type'], ['unparsed_content', 'unparsed_commas_content', 'unparsed_equals_content'])) { + if (!empty($code['type']) && \in_array($code['type'], ['unparsed_content', 'unparsed_commas_content', 'unparsed_equals_content'])) { $excluded_bbc[] = $code['tag']; } } diff --git a/Sources/Menu.php b/Sources/Menu.php index b66b392a14..ea853a0fd9 100644 --- a/Sources/Menu.php +++ b/Sources/Menu.php @@ -397,7 +397,7 @@ public static function destroy(int|string $id = 'last'): void $id = self::$max_id; } - if (!is_int($id)) { + if (!\is_int($id)) { $to_delete = $id; } else { foreach (self::$loaded as $action => $menu) { diff --git a/Sources/Msg.php b/Sources/Msg.php index 0c2bf33e76..991b0d092d 100644 --- a/Sources/Msg.php +++ b/Sources/Msg.php @@ -308,7 +308,7 @@ public function format(int $counter = 0, array $format_options = []): array 'body' => $this->body ?? '', 'new' => empty($this->is_read), 'first_new' => isset(Utils::$context['start_from']) && Utils::$context['start_from'] == $counter, - 'is_ignored' => !empty(Config::$modSettings['enable_buddylist']) && !empty(Theme::$current->options['posts_apply_ignore_list']) && in_array($this->id_member, User::$me->ignoreusers), + 'is_ignored' => !empty(Config::$modSettings['enable_buddylist']) && !empty(Theme::$current->options['posts_apply_ignore_list']) && \in_array($this->id_member, User::$me->ignoreusers), ]; // Are we showing the icon? @@ -472,7 +472,7 @@ public function format(int $counter = 0, array $format_options = []): array if (!empty(Config::$modSettings['enable_likes'])) { $this->formatted['likes'] = [ 'count' => $this->likes, - 'you' => in_array($this->id, Utils::$context['my_likes'] ?? []), + 'you' => \in_array($this->id, Utils::$context['my_likes'] ?? []), ]; if ($format_options['do_permissions']) { @@ -705,7 +705,7 @@ function ($a) { // Replace code BBC with placeholders. We'll restore them at the end. $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. if ($i % 4 == 2) { $code_tag = $parts[$i - 1] . $parts[$i] . $parts[$i + 1]; @@ -873,7 +873,7 @@ function ($m) { $tags = []; foreach (BBCodeParser::getCodes() as $code) { - if (!in_array($code['tag'], $allowed_empty)) { + if (!\in_array($code['tag'], $allowed_empty)) { $tags[] = $code['tag']; } } @@ -918,7 +918,7 @@ public static function un_preparsecode(string $message): string $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); // We're going to unparse only the stuff outside [code]... - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { // If $i is a multiple of four (0, 4, 8, ...) then it's not a code section... if ($i % 4 == 2) { $code_tag = $parts[$i - 1] . $parts[$i] . $parts[$i + 1]; @@ -1094,7 +1094,7 @@ public static function fixTag(string &$message, string $myTag, array $protocols, $found = false; foreach ($protocols as $protocol) { - $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; + $found = strncasecmp($replace, $protocol . '://', \strlen($protocol) + 3) === 0; if ($found) { break; @@ -1103,7 +1103,7 @@ public static function fixTag(string &$message, string $myTag, array $protocols, $current_protocol = strtolower(Url::create($replace)->scheme ?? ''); - if (in_array($current_protocol, $forbidden_protocols)) { + if (\in_array($current_protocol, $forbidden_protocols)) { $replace = 'about:invalid'; } elseif (!$found && $protocols[0] == 'http') { // A path @@ -1740,7 +1740,7 @@ public static function modify(array &$msgOptions, array &$topicOptions, array &$ IntegrationHook::call('integrate_modify_post', [&$messages_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions, &$messageInts]); foreach ($messages_columns as $var => $val) { - $messages_columns[$var] = $var . ' = {' . (in_array($var, $messageInts) ? 'int' : 'string') . ':var_' . $var . '}'; + $messages_columns[$var] = $var . ' = {' . (\in_array($var, $messageInts) ? 'int' : 'string') . ':var_' . $var . '}'; $update_parameters['var_' . $var] = $val; } @@ -1885,7 +1885,7 @@ public static function modify(array &$msgOptions, array &$topicOptions, array &$ public static function approve(array|int $msgs, bool $approve = true, bool $notify = true): bool { // @TODO: $msgs = (array) $msgs; - if (!is_array($msgs)) { + if (!\is_array($msgs)) { $msgs = [$msgs]; } @@ -2179,7 +2179,7 @@ public static function approve(array|int $msgs, bool $approve = true, bool $noti public static function clearApprovalAlerts(array $content_ids, string $content_action): void { // Some data hygiene... - if (!is_array($content_ids)) { + if (!\is_array($content_ids)) { return; } @@ -2189,7 +2189,7 @@ public static function clearApprovalAlerts(array $content_ids, string $content_a return; } - if (!in_array($content_action, ['unapproved_post', 'unapproved_topic'])) { + if (!\in_array($content_action, ['unapproved_post', 'unapproved_topic'])) { return; } @@ -2231,7 +2231,7 @@ public static function updateLastMessages(int|array $setboards, int $id_msg = 0) } // @TODO: $setboards = (array) $setboards; - if (!is_array($setboards)) { + if (!\is_array($setboards)) { $setboards = [$setboards]; } @@ -2402,11 +2402,11 @@ public static function remove(int $message, bool $decreasePostCount = true): boo if (empty(Board::$info->id) || $row['id_board'] != Board::$info->id) { $delete_any = User::$me->boardsAllowedTo('delete_any'); - if (!in_array(0, $delete_any) && !in_array($row['id_board'], $delete_any)) { + if (!\in_array(0, $delete_any) && !\in_array($row['id_board'], $delete_any)) { $delete_own = User::$me->boardsAllowedTo('delete_own'); - $delete_own = in_array(0, $delete_own) || in_array($row['id_board'], $delete_own); + $delete_own = \in_array(0, $delete_own) || \in_array($row['id_board'], $delete_own); $delete_replies = User::$me->boardsAllowedTo('delete_replies'); - $delete_replies = in_array(0, $delete_replies) || in_array($row['id_board'], $delete_replies); + $delete_replies = \in_array(0, $delete_replies) || \in_array($row['id_board'], $delete_replies); if ($row['id_member'] == User::$me->id) { if (!$delete_own) { @@ -2430,10 +2430,10 @@ public static function remove(int $message, bool $decreasePostCount = true): boo } // Can't delete an unapproved message, if you can't see it! - if (Config::$modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != User::$me->id && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any))) { + if (Config::$modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != User::$me->id && !(\in_array(0, $delete_any) || \in_array($row['id_board'], $delete_any))) { $approve_posts = User::$me->boardsAllowedTo('approve_posts'); - if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) { + if (!\in_array(0, $approve_posts) && !\in_array($row['id_board'], $approve_posts)) { return false; } } @@ -2464,11 +2464,11 @@ public static function remove(int $message, bool $decreasePostCount = true): boo if ($row['id_first_msg'] == $message) { if (empty(Board::$info->id) || $row['id_board'] != Board::$info->id) { $remove_any = User::$me->boardsAllowedTo('remove_any'); - $remove_any = in_array(0, $remove_any) || in_array($row['id_board'], $remove_any); + $remove_any = \in_array(0, $remove_any) || \in_array($row['id_board'], $remove_any); if (!$remove_any) { $remove_own = User::$me->boardsAllowedTo('remove_own'); - $remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own); + $remove_own = \in_array(0, $remove_own) || \in_array($row['id_board'], $remove_own); } if ($row['id_member'] != User::$me->id && !$remove_any) { diff --git a/Sources/PackageManager/FtpConnection.php b/Sources/PackageManager/FtpConnection.php index c6758fbee8..a474af6abd 100644 --- a/Sources/PackageManager/FtpConnection.php +++ b/Sources/PackageManager/FtpConnection.php @@ -144,7 +144,7 @@ public function connect( */ public function chdir(string $ftp_path): bool { - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { return false; } @@ -173,7 +173,7 @@ public function chdir(string $ftp_path): bool */ public function chmod(string $ftp_file, int|string $chmod): bool { - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { return false; } @@ -216,7 +216,7 @@ public function chmod(string $ftp_file, int|string $chmod): bool public function unlink(string $ftp_file): bool { // We are actually connected, right? - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { return false; } @@ -253,7 +253,7 @@ public function check_response(int|string|array $desired): bool } while ((strlen($this->last_message) < 4 || str_starts_with($this->last_message, ' ') || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); // Was the desired response returned? - return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; + return \is_array($desired) ? \in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; } /** @@ -264,7 +264,7 @@ public function check_response(int|string|array $desired): bool public function passive(): bool { // We can't create a passive data connection without a primary one first being there. - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { $this->error = 'no_connection'; return false; @@ -307,7 +307,7 @@ public function passive(): bool public function create_file(string $ftp_file): bool { // First, we have to be connected... very important. - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { return false; } @@ -351,7 +351,7 @@ public function create_file(string $ftp_file): bool public function list_dir(string $ftp_path = '', bool $search = false): string|bool { // Are we even connected...? - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { return false; } @@ -419,16 +419,16 @@ public function locate(string $file, ?string $listing = null): string|bool $current_dir = ''; } - for ($i = 0, $n = count($listing); $i < $n; $i++) { + for ($i = 0, $n = \count($listing); $i < $n; $i++) { if (trim($listing[$i]) == '' && isset($listing[$i + 1])) { $current_dir = substr(trim($listing[++$i]), 0, -1); $i++; } // Okay, this file's name is: - $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); + $listing[$i] = $current_dir . '/' . trim(\strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { + if ($file[0] == '*' && substr($listing[$i], -(\strlen($file) - 1)) == substr($file, 1)) { return $listing[$i]; } @@ -453,7 +453,7 @@ public function locate(string $file, ?string $listing = null): string|bool public function create_dir(string $ftp_dir): bool { // We must be connected to the server to do something. - if (!is_resource($this->connection)) { + if (!\is_resource($this->connection)) { return false; } @@ -490,8 +490,8 @@ public function detect_path(string $filesystem_path, ?string $lookup_file = null $path = substr($path, 0, -1); } - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { - $path .= dirname($_SERVER['PHP_SELF']); + if (\strlen(\dirname($_SERVER['PHP_SELF'])) > 1) { + $path .= \dirname($_SERVER['PHP_SELF']); } } elseif (str_starts_with($filesystem_path, '/var/www/')) { $path = substr($filesystem_path, 8); @@ -502,23 +502,23 @@ public function detect_path(string $filesystem_path, ?string $lookup_file = null $path = ''; } - if (is_resource($this->connection) && $this->list_dir($path) == '') { + if (\is_resource($this->connection) && $this->list_dir($path) == '') { $data = $this->list_dir('', true); if ($lookup_file === null) { $lookup_file = $_SERVER['PHP_SELF']; } - $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); + $found_path = \dirname($this->locate('*' . basename(\dirname($lookup_file)) . '/' . basename($lookup_file), $data)); if ($found_path == false) { - $found_path = dirname($this->locate(basename($lookup_file))); + $found_path = \dirname($this->locate(basename($lookup_file))); } if ($found_path != false) { $path = $found_path; } - } elseif (is_resource($this->connection)) { + } elseif (\is_resource($this->connection)) { $found_path = true; } diff --git a/Sources/PackageManager/PackageManager.php b/Sources/PackageManager/PackageManager.php index 7dc26f85d1..00343ff069 100644 --- a/Sources/PackageManager/PackageManager.php +++ b/Sources/PackageManager/PackageManager.php @@ -169,18 +169,18 @@ public function execute(): void } // We need to force the "Download" tab as selected. - if (in_array(Utils::$context['sub_action'], $this->packageget_subactions)) { + if (\in_array(Utils::$context['sub_action'], $this->packageget_subactions)) { Utils::$context['menu_data_' . Utils::$context['admin_menu_id']]['current_subsection'] = 'packageget'; } // Call the function we're handing control to. if (method_exists($this, $this->subactions[Utils::$context['sub_action']])) { - call_user_func([$this, $this->subactions[Utils::$context['sub_action']]]); + \call_user_func([$this, $this->subactions[Utils::$context['sub_action']]]); } else { $call = Utils::getCallable($this->subactions[Utils::$context['sub_action']]); if (!empty($call)) { - call_user_func($call); + \call_user_func($call); } } } @@ -225,7 +225,7 @@ public function installTest(): void Utils::$context['uninstalling'] = $_REQUEST['sa'] == 'uninstall'; // Change our last link tree item for more information on this Packages area. - Utils::$context['linktree'][count(Utils::$context['linktree']) - 1] = [ + Utils::$context['linktree'][\count(Utils::$context['linktree']) - 1] = [ 'url' => Config::$scripturl . '?action=admin;area=packages;sa=browse', 'name' => Utils::$context['uninstalling'] ? Lang::$txt['package_uninstall_actions'] : Lang::$txt['install_actions'], ]; @@ -245,7 +245,7 @@ public function installTest(): void if (Utils::$context['extracted_files'] && !file_exists(Config::$packagesdir . '/temp/package-info.xml')) { foreach (Utils::$context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { - Utils::$context['base_path'] = dirname($file['filename']) . '/'; + Utils::$context['base_path'] = \dirname($file['filename']) . '/'; break; } } @@ -286,7 +286,7 @@ public function installTest(): void // Get the package info... $packageInfo = SubsPackage::getPackageInfo(Utils::$context['filename']); - if (!is_array($packageInfo)) { + if (!\is_array($packageInfo)) { ErrorHandler::fatalLang($packageInfo); } @@ -367,7 +367,7 @@ public function installTest(): void // Only let them uninstall themes it was installed into. foreach ($theme_paths as $id => $data) { - if ($id != 1 && !in_array($id, $old_themes)) { + if ($id != 1 && !\in_array($id, $old_themes)) { unset($theme_paths[$id]); } } @@ -381,7 +381,7 @@ public function installTest(): void } else { // Otherwise they can only upgrade themes from the first time around. foreach ($theme_paths as $id => $data) { - if ($id != 1 && !in_array($id, $old_themes)) { + if ($id != 1 && !\in_array($id, $old_themes)) { unset($theme_paths[$id]); } } @@ -472,7 +472,7 @@ public function installTest(): void $mod_actions = SubsPackage::parseModification(@file_get_contents(Config::$packagesdir . '/temp/' . Utils::$context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); } - if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') { + if (\count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') { $mod_actions[0]['filename'] = $action['filename']; } @@ -560,7 +560,7 @@ public function installTest(): void } // We just need it for actual parse changes. - if (!in_array($mod_action['type'], ['error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'])) { + if (!\in_array($mod_action['type'], ['error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'])) { if (empty($mod_action['is_custom'])) { Utils::$context['actions'][$actual_filename]['operations'][] = [ 'type' => Lang::$txt['execute_modification'], @@ -602,7 +602,7 @@ public function installTest(): void 'type' => Lang::$txt['execute_database_changes'], 'action' => Utils::htmlspecialchars($action['filename']), ]; - } elseif (in_array($action['type'], ['create-dir', 'create-file'])) { + } elseif (\in_array($action['type'], ['create-dir', 'create-file'])) { $thisAction = [ 'type' => $action['type'] == 'create-dir' ? Lang::$txt['package_create_tree'] : Lang::$txt['package_create_file'], 'action' => Utils::htmlspecialchars(strtr($action['destination'], [Config::$boarddir => '.'])), @@ -664,7 +664,7 @@ public function installTest(): void 'type' => Lang::$txt['package_requires'], 'action' => Lang::getTxt('package_check_for', ['requirement' => $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '' . $action['version'] . '')) : '')]), ]; - } elseif (in_array($action['type'], ['require-dir', 'require-file'])) { + } elseif (\in_array($action['type'], ['require-dir', 'require-file'])) { // Do this one... $thisAction = [ 'type' => $action['type'] == 'require-dir' ? Lang::$txt['package_extract_tree'] : Lang::$txt['package_extract_file'], @@ -674,10 +674,10 @@ public function installTest(): void // Could this be theme related? if (!empty($action['unparsed_destination']) && preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir|themes_dir)~i', $action['unparsed_destination'], $matches)) { // Is the action already stated? - $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], ['no', 'yes', 'auto']) ? $action['theme_action'] : 'auto'; + $theme_action = !empty($action['theme_action']) && \in_array($action['theme_action'], ['no', 'yes', 'auto']) ? $action['theme_action'] : 'auto'; // If it's not auto do we think we have something we can act upon? - if ($theme_action != 'auto' && !in_array($matches[1], ['languagedir', 'languages_dir', 'imagesdir', 'themedir'])) { + if ($theme_action != 'auto' && !\in_array($matches[1], ['languagedir', 'languages_dir', 'imagesdir', 'themedir'])) { $theme_action = ''; } // ... or if it's auto do we even want to do anything? @@ -694,12 +694,12 @@ public function installTest(): void $themeFinds['other_themes'][] = strtolower(strtr(SubsPackage::parse_path($action['unparsed_destination']), ['\\' => '/']) . '/' . basename($action['filename'])); } } - } elseif (in_array($action['type'], ['move-dir', 'move-file'])) { + } elseif (\in_array($action['type'], ['move-dir', 'move-file'])) { $thisAction = [ 'type' => $action['type'] == 'move-dir' ? Lang::$txt['package_move_tree'] : Lang::$txt['package_move_file'], 'action' => Utils::htmlspecialchars(strtr($action['source'], [Config::$boarddir => '.'])) . ' => ' . Utils::htmlspecialchars(strtr($action['destination'], [Config::$boarddir => '.'])), ]; - } elseif (in_array($action['type'], ['remove-dir', 'remove-file'])) { + } elseif (\in_array($action['type'], ['remove-dir', 'remove-file'])) { $thisAction = [ 'type' => $action['type'] == 'remove-dir' ? Lang::$txt['package_delete_tree'] : Lang::$txt['package_delete_file'], 'action' => Utils::htmlspecialchars(strtr($action['filename'], [Config::$boarddir => '.'])), @@ -708,11 +708,11 @@ public function installTest(): void // Could this be theme related? if (!empty($action['unparsed_filename']) && preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir|themes_dir)~i', $action['unparsed_filename'], $matches)) { // Is the action already stated? - $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], ['no', 'yes', 'auto']) ? $action['theme_action'] : 'auto'; + $theme_action = !empty($action['theme_action']) && \in_array($action['theme_action'], ['no', 'yes', 'auto']) ? $action['theme_action'] : 'auto'; $action['unparsed_destination'] = $action['unparsed_filename']; // If it's not auto do we think we have something we can act upon? - if ($theme_action != 'auto' && !in_array($matches[1], ['languagedir', 'languages_dir', 'imagesdir', 'themedir'])) { + if ($theme_action != 'auto' && !\in_array($matches[1], ['languagedir', 'languages_dir', 'imagesdir', 'themedir'])) { $theme_action = ''; } // ... or if it's auto do we even want to do anything? @@ -735,16 +735,16 @@ public function installTest(): void continue; } - if (!in_array($action['type'], ['hook', 'credits'])) { + if (!\in_array($action['type'], ['hook', 'credits'])) { if (Utils::$context['uninstalling']) { - $file = in_array($action['type'], ['remove-dir', 'remove-file']) ? $action['filename'] : Config::$packagesdir . '/temp/' . Utils::$context['base_path'] . $action['filename']; + $file = \in_array($action['type'], ['remove-dir', 'remove-file']) ? $action['filename'] : Config::$packagesdir . '/temp/' . Utils::$context['base_path'] . $action['filename']; } else { $file = Config::$packagesdir . '/temp/' . Utils::$context['base_path'] . $action['filename']; } } // Don't fail if a file/directory we're trying to create doesn't exist... - if (isset($action['filename']) && !file_exists($file) && !in_array($action['type'], ['create-dir', 'create-file'])) { + if (isset($action['filename']) && !file_exists($file) && !\in_array($action['type'], ['create-dir', 'create-file'])) { Utils::$context['has_failure'] = true; $thisAction += [ @@ -789,18 +789,18 @@ public function installTest(): void $real_path = $theme_data['theme_dir'] . $path; // Confirm that we don't already have this dealt with by another entry. - if (!in_array(strtolower(strtr($real_path, ['\\' => '/'])), $themeFinds['other_themes'])) { + if (!\in_array(strtolower(strtr($real_path, ['\\' => '/'])), $themeFinds['other_themes'])) { // Check if we will need to chmod this. - if (!SubsPackage::mktree(dirname($real_path), false)) { - $temp = dirname($real_path); + if (!SubsPackage::mktree(\dirname($real_path), false)) { + $temp = \dirname($real_path); - while (!file_exists($temp) && strlen($temp) > 1) { - $temp = dirname($temp); + while (!file_exists($temp) && \strlen($temp) > 1) { + $temp = \dirname($temp); } $chmod_files[] = $temp; } - if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) { + if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(\dirname($real_path)))) { $chmod_files[] = $real_path; } @@ -873,7 +873,7 @@ public function install(): void Utils::$context['uninstalling'] = $_REQUEST['sa'] == 'uninstall2'; // Set up the linktree for other. - Utils::$context['linktree'][count(Utils::$context['linktree']) - 1] = [ + Utils::$context['linktree'][\count(Utils::$context['linktree']) - 1] = [ 'url' => Config::$scripturl . '?action=admin;area=packages;sa=browse', 'name' => Utils::$context['uninstalling'] ? Lang::$txt['uninstall'] : Lang::$txt['extracting'], ]; @@ -902,7 +902,7 @@ public function install(): void if (!file_exists(Config::$packagesdir . '/temp/package-info.xml')) { foreach (Utils::$context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { - Utils::$context['base_path'] = dirname($file['filename']) . '/'; + Utils::$context['base_path'] = \dirname($file['filename']) . '/'; break; } } @@ -925,7 +925,7 @@ public function install(): void if (!empty($_POST['custom_theme'])) { foreach ($_POST['custom_theme'] as $tid) { - if (in_array($tid, $known_themes)) { + if (\in_array($tid, $known_themes)) { $custom_themes[] = (int) $tid; } } @@ -978,7 +978,7 @@ public function install(): void // Get the package info... $packageInfo = SubsPackage::getPackageInfo(Utils::$context['filename']); - if (!is_array($packageInfo)) { + if (!\is_array($packageInfo)) { ErrorHandler::fatalLang($packageInfo); } @@ -1044,7 +1044,7 @@ public function install(): void // They can only uninstall from what it was originally installed into. foreach ($theme_paths as $id => $data) { - if ($id != 1 && !in_array($id, $old_themes)) { + if ($id != 1 && !\in_array($id, $old_themes)) { unset($theme_paths[$id]); } } @@ -1061,7 +1061,7 @@ public function install(): void } else { // Upgrade previous themes only! foreach ($theme_paths as $id => $data) { - if ($id != 1 && !in_array($id, $old_themes)) { + if ($id != 1 && !\in_array($id, $old_themes)) { unset($theme_paths[$id]); } } @@ -1304,7 +1304,7 @@ public function install(): void foreach (Db::$package_log as $k => $log) { if ($log[0] == 'remove_table') { $tables[] = $log[1]; - } elseif (in_array($log[1], $tables)) { + } elseif (\in_array($log[1], $tables)) { unset(Db::$package_log[$k]); } } @@ -1514,7 +1514,7 @@ public function examineFile(): void Utils::obExit(false); } - Utils::$context['linktree'][count(Utils::$context['linktree']) - 1] = [ + Utils::$context['linktree'][\count(Utils::$context['linktree']) - 1] = [ 'url' => Config::$scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'], 'name' => Lang::$txt['package_examine_file'], ]; @@ -1711,7 +1711,7 @@ public function browse(): void // Current SMF version, which is selected by default Utils::$context['default_version'] = SMF_VERSION; - if (!in_array(Utils::$context['default_version'], Utils::$context['emulation_versions'])) { + if (!\in_array(Utils::$context['default_version'], Utils::$context['emulation_versions'])) { Utils::$context['emulation_versions'][] = Utils::$context['default_version']; } @@ -1786,7 +1786,7 @@ public function showOperations(): void if (Utils::$context['extracted_files'] && !file_exists(Config::$packagesdir . '/temp/package-info.xml')) { foreach (Utils::$context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { - Utils::$context['base_path'] = dirname($file['filename']) . '/'; + Utils::$context['base_path'] = \dirname($file['filename']) . '/'; break; } } @@ -1844,7 +1844,7 @@ public function showOperations(): void $old_themes = explode(',', $old_themes); foreach ($theme_paths as $id => $data) { - if ($id != 1 && !in_array($id, $old_themes)) { + if ($id != 1 && !\in_array($id, $old_themes)) { unset($theme_paths[$id]); } } @@ -2033,7 +2033,7 @@ public function permissions(): void if (!empty(Config::$modSettings['currentAttachmentUploadDir'])) { unset(Utils::$context['file_tree'][strtr(Config::$boarddir, ['\\' => '/'])]['contents']['attachments']); - if (!is_array(Config::$modSettings['attachmentUploadDir'])) { + if (!\is_array(Config::$modSettings['attachmentUploadDir'])) { Config::$modSettings['attachmentUploadDir'] = Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); } @@ -2093,8 +2093,8 @@ public function permissions(): void ); while ($row = Db::$db->fetch_assoc($request)) { - if (substr(strtolower(strtr($row['value'], ['\\' => '/'])), 0, strlen(Config::$boarddir) + 7) == strtolower(strtr(Config::$boarddir, ['\\' => '/']) . '/Themes')) { - Utils::$context['file_tree'][strtr(Config::$boarddir, ['\\' => '/'])]['contents']['Themes']['contents'][substr($row['value'], strlen(Config::$boarddir) + 8)] = [ + if (substr(strtolower(strtr($row['value'], ['\\' => '/'])), 0, \strlen(Config::$boarddir) + 7) == strtolower(strtr(Config::$boarddir, ['\\' => '/']) . '/Themes')) { + Utils::$context['file_tree'][strtr(Config::$boarddir, ['\\' => '/'])]['contents']['Themes']['contents'][substr($row['value'], \strlen(Config::$boarddir) + 8)] = [ 'type' => 'dir_recursive', 'list_contents' => true, 'contents' => [ @@ -2153,7 +2153,7 @@ public function permissions(): void Utils::$context['only_find'] = array_merge(Utils::$context['only_find'], $_POST['back_look']); } - Utils::$context['back_look_data'] = base64_encode(Utils::jsonEncode(array_slice(Utils::$context['look_for'], 0, 15))); + Utils::$context['back_look_data'] = base64_encode(Utils::jsonEncode(\array_slice(Utils::$context['look_for'], 0, 15))); // Are we finding more files than first thought? Utils::$context['file_offset'] = !empty($_REQUEST['fileoffset']) ? (int) $_REQUEST['fileoffset'] : 0; @@ -2264,7 +2264,7 @@ public function PackagePermissionsAction(): ?bool // Now add it. Utils::$context['to_process'][$path] = $status; } - Utils::$context['total_items'] = isset($_POST['totalItems']) ? (int) $_POST['totalItems'] : count(Utils::$context['to_process']); + Utils::$context['total_items'] = isset($_POST['totalItems']) ? (int) $_POST['totalItems'] : \count(Utils::$context['to_process']); // Make sure the chmod status is valid? if ($validate_custom) { @@ -2288,7 +2288,7 @@ public function PackagePermissionsAction(): ?bool // Start processing items. foreach (Utils::$context['to_process'] as $path => $status) { - if (in_array($status, ['execute', 'writable', 'read'])) { + if (\in_array($status, ['execute', 'writable', 'read'])) { SubsPackage::package_chmod($path, $status); } elseif ($status == 'custom' && !empty($custom_value)) { // Use FTP if we have it. @@ -2719,11 +2719,11 @@ public function serverBrowse(): void 'type' => $thisPackage->name(), ]; - if (in_array($package['type'], ['title', 'text'])) { + if (\in_array($package['type'], ['title', 'text'])) { Utils::$context['package_list'][$packageSection][$package['type']] = Utils::htmlspecialchars($thisPackage->fetch('.')); } // It's a Title, Heading, Rule or Text. - elseif (in_array($package['type'], ['heading', 'rule'])) { + elseif (\in_array($package['type'], ['heading', 'rule'])) { $package['name'] = Utils::htmlspecialchars($thisPackage->fetch('.')); } // It's a Remote link. @@ -2795,7 +2795,7 @@ public function serverBrowse(): void } $already_exists = SubsPackage::getPackageInfo(basename($package['filename'])); - $package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version']; + $package['download_conflict'] = \is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version']; $package['href'] = $url . '/' . $package['filename']; $package['link'] = '' . $package['name'] . ''; @@ -2851,10 +2851,10 @@ public function serverBrowse(): void $package['is_text'] = $package['type'] == 'text'; $package['is_line'] = $package['type'] == 'rule'; - $packageNum = in_array($package['type'], ['title', 'heading', 'text', 'remote', 'rule']) ? 0 : $packageNum + 1; + $packageNum = \in_array($package['type'], ['title', 'heading', 'text', 'remote', 'rule']) ? 0 : $packageNum + 1; $package['count'] = $packageNum; - if (!in_array($package['type'], ['title', 'text'])) { + if (!\in_array($package['type'], ['title', 'text'])) { Utils::$context['package_list'][$packageSection]['items'][] = $package; } @@ -2879,7 +2879,7 @@ public function serverBrowse(): void $packageInfo = SubsPackage::getPackageInfo($url . '/' . $package['filename']); - if (is_array($packageInfo) && $packageInfo['xml']->exists('install')) { + if (\is_array($packageInfo) && $packageInfo['xml']->exists('install')) { $installs = $packageInfo['xml']->set('install'); foreach ($installs as $install) { @@ -3001,7 +3001,7 @@ public function download(): void Utils::$context['package'] = SubsPackage::getPackageInfo($package_name); - if (!is_array(Utils::$context['package'])) { + if (!\is_array(Utils::$context['package'])) { ErrorHandler::fatalLang('package_cant_download', false); } @@ -3035,7 +3035,7 @@ public function upload(): void // Check the file was even sent! if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') { ErrorHandler::fatalLang('package_upload_error_nofile', false); - } elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) { + } elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (\ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) { ErrorHandler::fatalLang('package_upload_error_failed', false); } @@ -3049,7 +3049,7 @@ public function upload(): void } // We only need the filename... - $packageName = substr($_FILES['package']['name'], 0, -strlen($match[0])); + $packageName = substr($_FILES['package']['name'], 0, -\strlen($match[0])); $packageFileName = SubsPackage::package_unique_filename(Config::$packagesdir, $packageName, $match[1]) . $match[0]; // Setup the destination and throw an error if the file is already there! @@ -3068,7 +3068,7 @@ public function upload(): void Utils::$context['package_server'] = ''; // Not really a package, you lazy bum! - if (!is_array(Utils::$context['package'])) { + if (!\is_array(Utils::$context['package'])) { @unlink($destination); Lang::load('Errors'); Lang::$txt[Utils::$context['package']] = str_replace('{MANAGETHEMEURL}', Config::$scripturl . '?action=admin;area=theme;sa=admin;' . Utils::$context['session_var'] . '=' . Utils::$context['session_id'] . '#theme_install', Lang::$txt[Utils::$context['package']]); @@ -3083,7 +3083,7 @@ public function upload(): void $packageInfo = SubsPackage::getPackageInfo($package); - if (!is_array($packageInfo)) { + if (!\is_array($packageInfo)) { continue; } @@ -3253,7 +3253,7 @@ public function list_getPackages(int $start, int $items_per_page, string $sort, // Skip directories or files that are named the same. if (is_dir(Config::$packagesdir . '/' . $package)) { - if (in_array($package, $dirs)) { + if (\in_array($package, $dirs)) { continue; } $dirs[] = $package; @@ -3271,7 +3271,7 @@ public function list_getPackages(int $start, int $items_per_page, string $sort, $packageInfo = SubsPackage::getPackageInfo($package); - if (!is_array($packageInfo)) { + if (!\is_array($packageInfo)) { continue; } @@ -3381,7 +3381,7 @@ public function list_getPackages(int $start, int $items_per_page, string $sort, } closedir($dir); } - Utils::$context['available_packages'] += count($packages); + Utils::$context['available_packages'] += \count($packages); array_multisort( $column, isset($_GET['desc']) ? SORT_DESC : SORT_ASC, @@ -3408,7 +3408,7 @@ protected function __construct() $_REQUEST['sa'] = 'servers'; } - if (in_array($_REQUEST['sa'], ['add', 'remove', 'browse'])) { + if (\in_array($_REQUEST['sa'], ['add', 'remove', 'browse'])) { $_REQUEST['sa'] = 'server' . $_REQUEST['sa']; } diff --git a/Sources/PackageManager/SubsPackage.php b/Sources/PackageManager/SubsPackage.php index 7ed12b1e6d..1d83c0e478 100644 --- a/Sources/PackageManager/SubsPackage.php +++ b/Sources/PackageManager/SubsPackage.php @@ -82,7 +82,7 @@ public static function read_tgz_file(string $gzfilename, ?string $destination, b } // Too short for magic numbers? No fortune cookie for you! - if (strlen($data) < 2) { + if (\strlen($data) < 2) { return false; } @@ -130,7 +130,7 @@ public static function read_tgz_data(string $data, ?string $destination, bool $s Lang::load('Packages'); // This function sorta needs gzinflate! - if (!function_exists('gzinflate')) { + if (!\function_exists('gzinflate')) { ErrorHandler::fatalLang('package_no_lib', 'critical', ['package_no_zlib', 'package_no_package_manager']); } @@ -163,15 +163,15 @@ public static function read_tgz_data(string $data, ?string $destination, bool $s } } - $crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8)); - $data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset)); + $crc = unpack('Vcrc32/Visize', substr($data, \strlen($data) - 8, 8)); + $data = @gzinflate(substr($data, $offset, \strlen($data) - 8 - $offset)); // smf_crc32 and crc32 may not return the same results, so we accept either. if ($crc['crc32'] != self::smf_crc32($data) && $crc['crc32'] != crc32($data)) { return false; } - $blocks = strlen($data) / 512 - 1; + $blocks = \strlen($data) / 512 - 1; $offset = 0; $return = []; @@ -188,7 +188,7 @@ public static function read_tgz_data(string $data, ?string $destination, bool $s } foreach ($current as $k => $v) { - if (in_array($k, $octdec)) { + if (\in_array($k, $octdec)) { $current[$k] = octdec(trim($v)); } else { $current[$k] = trim($v); @@ -202,11 +202,11 @@ public static function read_tgz_data(string $data, ?string $destination, bool $s $checksum = 256; for ($i = 0; $i < 148; $i++) { - $checksum += ord($header[$i]); + $checksum += \ord($header[$i]); } for ($i = 156; $i < 512; $i++) { - $checksum += ord($header[$i]); + $checksum += \ord($header[$i]); } if ($current['checksum'] != $checksum) { @@ -258,7 +258,7 @@ public static function read_tgz_data(string $data, ?string $destination, bool $s } // Looking for restricted files? - if ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) { + if ($files_to_extract !== null && !\in_array($current['filename'], $files_to_extract)) { continue; } @@ -416,7 +416,7 @@ public static function read_zip_data(string $data, ?string $destination, bool $s } // Oh, another file? Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. - if ($single_file || ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract))) { + if ($single_file || ($files_to_extract !== null && !\in_array($file_info['filename'], $files_to_extract))) { continue; } @@ -502,7 +502,7 @@ public static function loadInstalledPackages(): array while ($row = Db::$db->fetch_assoc($request)) { // Already found this? If so don't add it twice! - if (in_array($row['package_id'], $found)) { + if (\in_array($row['package_id'], $found)) { continue; } @@ -743,7 +743,7 @@ public static function create_chmod_control(array $chmodFiles = [], array $chmod $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path'])); } - if (!in_array($_POST['ftp_path'], ['', '/'])) { + if (!\in_array($_POST['ftp_path'], ['', '/'])) { $ftp_root = strtr(Config::$boarddir, [$_POST['ftp_path'] => '']); if (str_ends_with($ftp_root, '/') && ($_POST['ftp_path'] == '' || str_starts_with($_POST['ftp_path'], '/'))) { @@ -860,7 +860,7 @@ public static function list_restoreFiles(mixed $dummy1, mixed $dummy2, mixed $du } // Are we wanting to change the permission? - if ($do_change && isset($_POST['restore_files']) && in_array($file, $_POST['restore_files'])) { + if ($do_change && isset($_POST['restore_files']) && \in_array($file, $_POST['restore_files'])) { // Use FTP if we have it. if (!empty(self::$package_ftp)) { $ftp_file = strtr($file, [$_SESSION['pack_ftp']['root'] => '']); @@ -908,7 +908,7 @@ public static function packageRequireFTP(string $destination_url, ?array $files foreach ($files as $k => $file) { // If this file doesn't exist, then we actually want to look at the directory, no? if (!file_exists($file)) { - $file = dirname($file); + $file = \dirname($file); } Utils::makeWritable($file); @@ -941,7 +941,7 @@ public static function packageRequireFTP(string $destination_url, ?array $files foreach ($files as $k => $file) { // This looks odd, but it's an attempt to work around PHP suExec. if (!file_exists($file)) { - self::mktree(dirname($file), 0755); + self::mktree(\dirname($file), 0755); @touch($file); } @@ -965,7 +965,7 @@ public static function packageRequireFTP(string $destination_url, ?array $files // This looks odd, but it's an attempt to work around PHP suExec. if (!file_exists($file)) { - self::mktree(dirname($file), 0755); + self::mktree(\dirname($file), 0755); self::$package_ftp->create_file($ftp_file); self::$package_ftp->chmod($ftp_file, 0755); } @@ -974,8 +974,8 @@ public static function packageRequireFTP(string $destination_url, ?array $files self::$package_ftp->chmod($ftp_file, 0777); } - if (!@is_writable(dirname($file))) { - self::$package_ftp->chmod(dirname($ftp_file), 0777); + if (!@is_writable(\dirname($file))) { + self::$package_ftp->chmod(\dirname($ftp_file), 0777); } if (@is_writable($file)) { @@ -1043,7 +1043,7 @@ public static function packageRequireFTP(string $destination_url, ?array $files Utils::$context['sub_template'] = 'ftp_required'; Utils::obExit(); } else { - if (!in_array($_POST['ftp_path'], ['', '/'])) { + if (!\in_array($_POST['ftp_path'], ['', '/'])) { $ftp_root = strtr(Config::$boarddir, [$_POST['ftp_path'] => '']); if (str_ends_with($ftp_root, '/') && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) { @@ -1161,7 +1161,7 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl foreach ($actions as $action) { $actionType = $action->name(); - if (in_array($actionType, ['readme', 'code', 'database', 'modification', 'redirect', 'license'])) { + if (\in_array($actionType, ['readme', 'code', 'database', 'modification', 'redirect', 'license'])) { // Allow for translated readme and license files. if ($actionType == 'readme' || $actionType == 'license') { $type = $actionType . 's'; @@ -1197,7 +1197,7 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl // @todo Make sure the file actually exists? Might not work when testing? if ($action->exists('@type') && $action->fetch('@type') == 'inline') { - $filename = self::$temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, ['readme', 'redirect', 'license']) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); + $filename = self::$temp_path . '$auto_' . $temp_auto++ . (\in_array($actionType, ['readme', 'redirect', 'license']) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); self::package_put_contents($filename, $action->fetch('.')); $filename = strtr($filename, [self::$temp_path => '']); } else { @@ -1272,7 +1272,7 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl $return[] = [ 'type' => 'error', ]; - } elseif (in_array($actionType, ['require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'])) { + } elseif (\in_array($actionType, ['require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'])) { $this_action = &$return[]; $this_action = [ 'type' => $actionType, @@ -1303,8 +1303,8 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl if (!self::mktree($this_action['destination'], false)) { $temp = $this_action['destination']; - while (!file_exists($temp) && strlen($temp) > 1) { - $temp = dirname($temp); + while (!file_exists($temp) && \strlen($temp) > 1) { + $temp = \dirname($temp); } $return[] = [ @@ -1313,11 +1313,11 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl ]; } } elseif ($actionType == 'create-file') { - if (!self::mktree(dirname($this_action['destination']), false)) { - $temp = dirname($this_action['destination']); + if (!self::mktree(\dirname($this_action['destination']), false)) { + $temp = \dirname($this_action['destination']); - while (!file_exists($temp) && strlen($temp) > 1) { - $temp = dirname($temp); + while (!file_exists($temp) && \strlen($temp) > 1) { + $temp = \dirname($temp); } $return[] = [ @@ -1326,7 +1326,7 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl ]; } - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(\dirname($this_action['destination'])))) { $return[] = [ 'type' => 'chmod', 'filename' => $this_action['destination'], @@ -1336,8 +1336,8 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl if (!self::mktree($this_action['destination'], false)) { $temp = $this_action['destination']; - while (!file_exists($temp) && strlen($temp) > 1) { - $temp = dirname($temp); + while (!file_exists($temp) && \strlen($temp) > 1) { + $temp = \dirname($temp); } $return[] = [ @@ -1350,11 +1350,11 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl $this_action['theme_action'] = $action->fetch('@theme'); } - if (!self::mktree(dirname($this_action['destination']), false)) { - $temp = dirname($this_action['destination']); + if (!self::mktree(\dirname($this_action['destination']), false)) { + $temp = \dirname($this_action['destination']); - while (!file_exists($temp) && strlen($temp) > 1) { - $temp = dirname($temp); + while (!file_exists($temp) && \strlen($temp) > 1) { + $temp = \dirname($temp); } $return[] = [ @@ -1363,18 +1363,18 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl ]; } - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(\dirname($this_action['destination'])))) { $return[] = [ 'type' => 'chmod', 'filename' => $this_action['destination'], ]; } } elseif ($actionType == 'move-dir' || $actionType == 'move-file') { - if (!self::mktree(dirname($this_action['destination']), false)) { - $temp = dirname($this_action['destination']); + if (!self::mktree(\dirname($this_action['destination']), false)) { + $temp = \dirname($this_action['destination']); - while (!file_exists($temp) && strlen($temp) > 1) { - $temp = dirname($temp); + while (!file_exists($temp) && \strlen($temp) > 1) { + $temp = \dirname($temp); } $return[] = [ @@ -1383,7 +1383,7 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl ]; } - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(\dirname($this_action['destination'])))) { $return[] = [ 'type' => 'chmod', 'filename' => $this_action['destination'], @@ -1428,7 +1428,7 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl $not_done = [['type' => '!']]; foreach ($return as $action) { - if (in_array($action['type'], ['modification', 'code', 'database', 'redirect', 'hook', 'credits'])) { + if (\in_array($action['type'], ['modification', 'code', 'database', 'redirect', 'hook', 'credits'])) { $not_done[] = $action; } @@ -1437,8 +1437,8 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl $failure |= !self::mktree($action['destination'], 0777); } } elseif ($action['type'] == 'create-file') { - if (!self::mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { - $failure |= !self::mktree(dirname($action['destination']), 0777); + if (!self::mktree(\dirname($action['destination']), 0755) || !is_writable(\dirname($action['destination']))) { + $failure |= !self::mktree(\dirname($action['destination']), 0777); } // Create an empty file. @@ -1457,8 +1457,8 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl } } } elseif ($action['type'] == 'require-file') { - if (!self::mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { - $failure |= !self::mktree(dirname($action['destination']), 0777); + if (!self::mktree(\dirname($action['destination']), 0755) || !is_writable(\dirname($action['destination']))) { + $failure |= !self::mktree(\dirname($action['destination']), 0777); } self::package_put_contents($action['destination'], self::package_get_contents($action['source']), $testing_only); @@ -1468,8 +1468,8 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl // Any other theme files? if (!empty(Utils::$context['theme_copies']) && !empty(Utils::$context['theme_copies'][$action['type']][$action['destination']])) { foreach (Utils::$context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) { - if (!self::mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination))) { - $failure |= !self::mktree(dirname($theme_destination), 0777); + if (!self::mktree(\dirname($theme_destination), 0755) || !is_writable(\dirname($theme_destination))) { + $failure |= !self::mktree(\dirname($theme_destination), 0777); } self::package_put_contents($theme_destination, self::package_get_contents($action['source']), $testing_only); @@ -1478,8 +1478,8 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl } } } elseif ($action['type'] == 'move-file') { - if (!self::mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { - $failure |= !self::mktree(dirname($action['destination']), 0777); + if (!self::mktree(\dirname($action['destination']), 0755) || !is_writable(\dirname($action['destination']))) { + $failure |= !self::mktree(\dirname($action['destination']), 0777); } $failure |= !rename($action['source'], $action['destination']); @@ -1586,7 +1586,7 @@ public static function matchPackageVersion(string $version, string $versions): b $versions = explode(',', str_replace([' ', '2.0rc1-1'], ['', '2.0rc1.1'], strtolower($versions))); // Perhaps we do accept anything? - if (in_array('all', $versions)) { + if (\in_array('all', $versions)) { return true; } @@ -1709,7 +1709,7 @@ public static function parse_path(string $path): string $dirs['$package'] = self::$temp_path; } - if (strlen($path) == 0) { + if (\strlen($path) == 0) { Lang::load('Errors'); trigger_error(Lang::$txt['parse_path_filename_required'], E_USER_ERROR); } @@ -1746,7 +1746,7 @@ public static function deltree(string $dir, bool $delete_dir = true): void } while ($entryname = readdir($current_dir)) { - if (in_array($entryname, ['.', '..'])) { + if (\in_array($entryname, ['.', '..'])) { continue; } @@ -1817,15 +1817,15 @@ public static function mktree(string $strPath, int $mode): bool } // Is this an invalid path and/or we can't make the directory? - if ($strPath == dirname($strPath) || !self::mktree(dirname($strPath), $mode)) { + if ($strPath == \dirname($strPath) || !self::mktree(\dirname($strPath), $mode)) { return false; } - if (!is_writable(dirname($strPath)) && $mode !== false) { + if (!is_writable(\dirname($strPath)) && $mode !== false) { if (isset(self::$package_ftp)) { - self::$package_ftp->chmod(dirname(strtr($strPath, [$_SESSION['pack_ftp']['root'] => ''])), $mode); + self::$package_ftp->chmod(\dirname(strtr($strPath, [$_SESSION['pack_ftp']['root'] => ''])), $mode); } else { - Utils::makeWritable(dirname($strPath), $mode); + Utils::makeWritable(\dirname($strPath), $mode); } } @@ -1834,7 +1834,7 @@ public static function mktree(string $strPath, int $mode): bool } if ($mode === false) { - $test = @opendir(dirname($strPath)); + $test = @opendir(\dirname($strPath)); if ($test) { closedir($test); @@ -1881,7 +1881,7 @@ public static function copytree(string $source, string $destination): void } while ($entryname = readdir($current_dir)) { - if (in_array($entryname, ['.', '..'])) { + if (\in_array($entryname, ['.', '..'])) { continue; } @@ -2017,7 +2017,7 @@ public static function parseModification(string $file, bool $testing = true, boo // For every template, do we want it? Yea, no, maybe? foreach ($template_changes[1] as $index => $template_file) { // What, it exists and we haven't already got it?! Lordy, get it in! - if (file_exists($theme['theme_dir'] . '/' . $template_file) && (!isset($template_changes[$id]) || !in_array($template_file, $template_changes[$id]))) { + if (file_exists($theme['theme_dir'] . '/' . $template_file) && (!isset($template_changes[$id]) || !\in_array($template_file, $template_changes[$id]))) { // Now let's add it to the "todo" list. $custom_themes_add[$long_changes[1][$index]][$id] = $theme['theme_dir'] . '/' . $template_file; } @@ -2046,7 +2046,7 @@ public static function parseModification(string $file, bool $testing = true, boo } // Doesn't exist - give an error or what? - if (!file_exists($working_file) && (!$file->exists('@error') || !in_array(trim($file->fetch('@error')), ['ignore', 'skip']))) { + if (!file_exists($working_file) && (!$file->exists('@error') || !\in_array(trim($file->fetch('@error')), ['ignore', 'skip']))) { $actions[] = [ 'type' => 'missing', 'filename' => $working_file, @@ -2088,7 +2088,7 @@ public static function parseModification(string $file, bool $testing = true, boo // Convert operation to an array. $actual_operation = [ 'searches' => [], - 'error' => $operation->exists('@error') && in_array(trim($operation->fetch('@error')), ['ignore', 'fatal', 'required']) ? trim($operation->fetch('@error')) : 'fatal', + 'error' => $operation->exists('@error') && \in_array(trim($operation->fetch('@error')), ['ignore', 'fatal', 'required']) ? trim($operation->fetch('@error')) : 'fatal', ]; // The 'add' parameter is used for all searches in this operation. @@ -2099,7 +2099,7 @@ public static function parseModification(string $file, bool $testing = true, boo foreach ($searches as $i => $search) { $actual_operation['searches'][] = [ - 'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), ['before', 'after', 'replace', 'end']) ? trim($search->fetch('@position')) : 'replace', + 'position' => $search->exists('@position') && \in_array(trim($search->fetch('@position')), ['before', 'after', 'replace', 'end']) ? trim($search->fetch('@position')) : 'replace', 'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true', 'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose', 'search' => $search->fetch('.'), @@ -2160,7 +2160,7 @@ public static function parseModification(string $file, bool $testing = true, boo } // Sort the search list so the replaces come before the add before/after's. - if (count($actual_operation['searches']) !== 1) { + if (\count($actual_operation['searches']) !== 1) { $replacements = []; foreach ($actual_operation['searches'] as $i => $search) { @@ -2279,7 +2279,7 @@ public static function parseModification(string $file, bool $testing = true, boo self::package_chmod($working_file); - if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) { + if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(\dirname($working_file)))) { $actions[] = [ 'type' => 'chmod', 'filename' => $working_file, @@ -2293,7 +2293,7 @@ public static function parseModification(string $file, bool $testing = true, boo if (!$testing && !empty(Config::$modSettings['package_make_backups']) && file_exists($working_file)) { // No, no, not Settings.php! if (basename($working_file) == basename(SMF_SETTINGS_FILE)) { - @copy($working_file, dirname($working_file) . '/' . basename(SMF_SETTINGS_BACKUP_FILE)); + @copy($working_file, \dirname($working_file) . '/' . basename(SMF_SETTINGS_BACKUP_FILE)); } else { @copy($working_file, $working_file . '~'); } @@ -2354,7 +2354,7 @@ public static function parseBoardMod(string $file, bool $testing = true, bool $u $counter++; // Get rid of the old stuff. - $temp_file = substr_replace($temp_file, '', strpos($temp_file, $code_match[0]), strlen($code_match[0])); + $temp_file = substr_replace($temp_file, '', strpos($temp_file, $code_match[0]), \strlen($code_match[0])); // No interest to us? if ($code_match[1] != 'edit file' && $code_match[1] != 'file') { @@ -2402,12 +2402,12 @@ public static function parseBoardMod(string $file, bool $testing = true, bool $u // Now, for each file do we need to edit it? foreach ($template_changes[1] as $pos => $template_file) { // It does? Add it to the list darlin'. - if (file_exists($theme['theme_dir'] . '/' . $template_file) && (!isset($template_changes[$id][$pos]) || !in_array($template_file, (array) $template_changes[$id][$pos]))) { + if (file_exists($theme['theme_dir'] . '/' . $template_file) && (!isset($template_changes[$id][$pos]) || !\in_array($template_file, (array) $template_changes[$id][$pos]))) { // Actually add it to the mod file too, so we can see that it will work ;) if (!empty($temp_changes[$pos]['changes'])) { $file .= "\n\n" . '' . "\n" . $theme['theme_dir'] . '/' . $template_file . "\n" . '' . "\n\n" . implode("\n\n", $temp_changes[$pos]['changes']); $theme_id_ref[$counter] = $id; - $counter += 1 + count($temp_changes[$pos]['changes']); + $counter += 1 + \count($temp_changes[$pos]['changes']); } } } @@ -2441,7 +2441,7 @@ public static function parseBoardMod(string $file, bool $testing = true, bool $u if (!$testing && !empty(Config::$modSettings['package_make_backups']) && file_exists($working_file)) { if (basename($working_file) == basename(SMF_SETTINGS_FILE)) { - @copy($working_file, dirname($working_file) . '/' . basename(SMF_SETTINGS_BACKUP_FILE)); + @copy($working_file, \dirname($working_file) . '/' . basename(SMF_SETTINGS_BACKUP_FILE)); } else { @copy($working_file, $working_file . '~'); } @@ -2578,7 +2578,7 @@ public static function parseBoardMod(string $file, bool $testing = true, bool $u } // Get rid of the old tag. - $file = substr_replace($file, '', strpos($file, $code_match[0]), strlen($code_match[0])); + $file = substr_replace($file, '', strpos($file, $code_match[0]), \strlen($code_match[0])); } // Backup the old file. @@ -2594,7 +2594,7 @@ public static function parseBoardMod(string $file, bool $testing = true, bool $u if (!$testing && !empty(Config::$modSettings['package_make_backups']) && file_exists($working_file)) { if (basename($working_file) == basename(SMF_SETTINGS_FILE)) { - @copy($working_file, dirname($working_file) . '/' . basename(SMF_SETTINGS_BACKUP_FILE)); + @copy($working_file, \dirname($working_file) . '/' . basename(SMF_SETTINGS_BACKUP_FILE)); } else { @copy($working_file, $working_file . '~'); } @@ -2707,7 +2707,7 @@ public static function package_put_contents(string $filename, string $data, bool fclose($fp); } - return strlen($data); + return \strlen($data); } /** @@ -2764,7 +2764,7 @@ public static function package_flush_cache(bool $trash = false): void // Bypass directories when doing so - no data to write & the fopen will crash. foreach (self::$package_cache as $filename => $data) { if (!is_dir($filename)) { - $fp = fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); + $fp = fopen($filename, \in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); fwrite($fp, $data); fclose($fp); } @@ -2798,7 +2798,7 @@ public static function package_chmod(string $filename, string $perm_state = 'wri $subTraverseLimit = 2; while (!file_exists($chmod_file) && $subTraverseLimit) { - $chmod_file = dirname($chmod_file); + $chmod_file = \dirname($chmod_file); $subTraverseLimit--; } @@ -2807,9 +2807,9 @@ public static function package_chmod(string $filename, string $perm_state = 'wri } else { // This looks odd, but it's an attempt to work around PHP suExec. if (!file_exists($chmod_file) && $perm_state == 'writable') { - $file_permissions = @fileperms(dirname($chmod_file)); + $file_permissions = @fileperms(\dirname($chmod_file)); - self::mktree(dirname($chmod_file), 0755); + self::mktree(\dirname($chmod_file), 0755); @touch($chmod_file); Utils::makeWritable($chmod_file, 0755); } else { @@ -2852,9 +2852,9 @@ public static function package_chmod(string $filename, string $perm_state = 'wri // This looks odd, but it's an attempt to work around PHP suExec. if (!file_exists($filename) && $perm_state == 'writable') { - $file_permissions = @fileperms(dirname($filename)); + $file_permissions = @fileperms(\dirname($filename)); - self::mktree(dirname($filename), 0755); + self::mktree(\dirname($filename), 0755); self::$package_ftp->create_file($ftp_file); self::$package_ftp->chmod($ftp_file, 0755); } else { @@ -2868,8 +2868,8 @@ public static function package_chmod(string $filename, string $perm_state = 'wri self::$package_ftp->chmod($ftp_file, 0777); } - if (!@is_writable(dirname($filename))) { - self::$package_ftp->chmod(dirname($ftp_file), 0777); + if (!@is_writable(\dirname($filename))) { + self::$package_ftp->chmod(\dirname($ftp_file), 0777); } } @@ -2900,16 +2900,16 @@ public static function package_crypt( #[\SensitiveParameter] string $pass, ): string { - $n = strlen($pass); + $n = \strlen($pass); $salt = session_id(); - while (strlen($salt) < $n) { + while (\strlen($salt) < $n) { $salt .= session_id(); } for ($i = 0; $i < $n; $i++) { - $pass[$i] = chr(ord($pass[$i]) ^ (ord($salt[$i]) - 32)); + $pass[$i] = \chr(\ord($pass[$i]) ^ (\ord($salt[$i]) - 32)); } return $pass; @@ -3170,7 +3170,7 @@ public static function package_validate_send(array $sendData): array $parsed_data = Utils::jsonDecode($results, true); - if (is_array($parsed_data) && isset($parsed_data['data']) && is_array($parsed_data['data'])) { + if (\is_array($parsed_data) && isset($parsed_data['data']) && \is_array($parsed_data['data'])) { foreach ($parsed_data['data'] as $sha256_hash => $status) { if ((string) $status === 'blacklist') { Utils::$context['package_blacklist_found'] = true; @@ -3472,7 +3472,7 @@ private static function smf_crc32(string $number): string { require_once Config::$sourcedir . '/Subs-Compat.php'; - return \smf_crc32($number); + return smf_crc32($number); } } diff --git a/Sources/PackageManager/XmlArray.php b/Sources/PackageManager/XmlArray.php index 94d83a7e7b..e91235b074 100644 --- a/Sources/PackageManager/XmlArray.php +++ b/Sources/PackageManager/XmlArray.php @@ -68,7 +68,7 @@ public function __construct(string|array $data, bool $auto_trim = false, ?int $l } // Is the input an array? (ie. passed from file()?) - if (is_array($data)) { + if (\is_array($data)) { $data = implode('', $data); } @@ -112,13 +112,13 @@ public function fetch(string $path, bool $get_elements = false): string|bool } // Getting elements into this is a bit complicated... - if ($get_elements && !is_string($array)) { + if ($get_elements && !\is_string($array)) { $temp = ''; // Use the _xml() function to get the xml data. foreach ($array->array as $val) { // Skip the name and any attributes. - if (is_array($val)) { + if (\is_array($val)) { $temp .= $this->_xml($val, null); } } @@ -128,7 +128,7 @@ public function fetch(string $path, bool $get_elements = false): string|bool } // Return the value - taking care to pick out all the text values. - return is_string($array) ? $array : $this->_fetch($array->array); + return \is_string($array) ? $array : $this->_fetch($array->array); } /** Get an element, returns a new XmlArray. @@ -167,7 +167,7 @@ public function path(string $path, bool $return_full = false): XmlArray|string|f $trace = debug_backtrace(); $i = 0; - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { + while ($i < \count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == \get_class($this)) { $i++; } $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; @@ -193,7 +193,7 @@ public function path(string $path, bool $return_full = false): XmlArray|string|f } // Create the right type of class... - $newClass = get_class($this); + $newClass = \get_class($this); // Return a new XmlArray for the result. return $array === false ? false : new $newClass($array, $this->trim, $this->debug_level, true); @@ -258,7 +258,7 @@ public function count(string $path): int $i = 0; foreach ($temp->array as $item) { - if (is_array($item)) { + if (\is_array($item)) { $i++; } } @@ -284,12 +284,12 @@ public function set(string $path): array foreach ($xml->array as $val) { // Skip these, they aren't elements. - if (!is_array($val) || $val['name'] == '!') { + if (!\is_array($val) || $val['name'] == '!') { continue; } // Create the right type of class... - $newClass = get_class($this); + $newClass = \get_class($this); // Create a new XmlArray and stick it in the array. $array[] = new $newClass($val, $this->trim, $this->debug_level, true); @@ -471,7 +471,7 @@ protected function _parse(string $data): array // Parse the insides. $inner_match = substr($data, 0, $last_tag_end); // Data now starts from where this section ends. - $data = substr($data, $last_tag_end + strlen('' . $match[1] . '>')); + $data = substr($data, $last_tag_end + \strlen('' . $match[1] . '>')); if (!empty($inner_match)) { // Parse the inner data. @@ -519,7 +519,7 @@ protected function _xml(array $array, ?int $indent): string ' . str_repeat(' ', $indent) : ''; // This is a set of elements, with no name... - if (is_array($array) && !isset($array['name'])) { + if (\is_array($array) && !isset($array['name'])) { $temp = ''; foreach ($array as $val) { @@ -548,7 +548,7 @@ protected function _xml(array $array, ?int $indent): string foreach ($array as $k => $v) { if (str_starts_with($k, '@')) { $output .= ' ' . substr($k, 1) . '="' . $v . '"'; - } elseif (is_array($v)) { + } elseif (\is_array($v)) { $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); $inside_elements = true; } @@ -576,7 +576,7 @@ protected function _array(array $array): string|array $text = ''; foreach ($array as $value) { - if (!is_array($value) || !isset($value['name'])) { + if (!\is_array($value) || !isset($value['name'])) { continue; } @@ -653,7 +653,7 @@ protected function _from_cdata(string $data): string preg_replace_callback( '~(\d{1,4});~', function ($m) { - return chr("{$m[1]}"); + return \chr("{$m[1]}"); }, $data, ), @@ -672,7 +672,7 @@ function ($m) { protected function _fetch(null|array|string $array): string { // Don't return anything if this is just a string. - if (is_string($array)) { + if (\is_string($array)) { return ''; } @@ -710,7 +710,7 @@ protected function _fetch(null|array|string $array): string protected function _path(array $array, string $path, ?int $level, bool $no_error = false): string|array { // Is $array even an array? It might be false! - if (!is_array($array)) { + if (!\is_array($array)) { return false; } @@ -721,17 +721,17 @@ protected function _path(array $array, string $path, ?int $level, bool $no_error $paths = explode('|', $path); // A * means all elements of any name. - $show_all = in_array('*', $paths); + $show_all = \in_array('*', $paths); $results = []; // Check each element. foreach ($array as $value) { - if (!is_array($value) || $value['name'] === '!') { + if (!\is_array($value) || $value['name'] === '!') { continue; } - if ($show_all || in_array($value['name'], $paths)) { + if ($show_all || \in_array($value['name'], $paths)) { // Skip elements before "the one". if ($level !== null && $level > 0) { $level--; @@ -746,7 +746,7 @@ protected function _path(array $array, string $path, ?int $level, bool $no_error $trace = debug_backtrace(); $i = 0; - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { + while ($i < \count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == \get_class($this)) { $i++; } $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; @@ -761,7 +761,7 @@ protected function _path(array $array, string $path, ?int $level, bool $no_error } // Only one result. - if (count($results) == 1 || $level !== null) { + if (\count($results) == 1 || $level !== null) { return $results[0]; } diff --git a/Sources/PersonalMessage/DraftPM.php b/Sources/PersonalMessage/DraftPM.php index 19b6337e66..f63e81c141 100644 --- a/Sources/PersonalMessage/DraftPM.php +++ b/Sources/PersonalMessage/DraftPM.php @@ -300,7 +300,7 @@ public static function showInProfile(int $memID = -1): void ); while ($result = Db::$db->fetch_assoc($request_2)) { - $recipientType = in_array($result['id_member'], $recipient_ids['bcc']) ? 'bcc' : 'to'; + $recipientType = \in_array($result['id_member'], $recipient_ids['bcc']) ? 'bcc' : 'to'; $recipients[$recipientType][] = $result['real_name']; } Db::$db->free_result($request_2); diff --git a/Sources/PersonalMessage/Folder.php b/Sources/PersonalMessage/Folder.php index 37e3668c82..a8c6752e43 100644 --- a/Sources/PersonalMessage/Folder.php +++ b/Sources/PersonalMessage/Folder.php @@ -485,7 +485,7 @@ protected function showConversation(): array // Get the PMs. $query_customizations = [ 'order' => ['pm.id_pm' . ($this->descending ? ' DESC' : ' ASC')], - 'limit' => count(array_keys($conversation->pms)), + 'limit' => \count(array_keys($conversation->pms)), ]; if (!$this->is_inbox) { diff --git a/Sources/PersonalMessage/Label.php b/Sources/PersonalMessage/Label.php index 19e4851826..9b2e390479 100644 --- a/Sources/PersonalMessage/Label.php +++ b/Sources/PersonalMessage/Label.php @@ -265,7 +265,7 @@ public static function manage(): void // Deleting an existing label? elseif (isset($_POST['delete'], $_POST['delete_label'])) { foreach ($_POST['delete_label'] as $label => $dummy) { - if (array_key_exists($label, $the_labels)) { + if (\array_key_exists($label, $the_labels)) { unset($the_labels[$label]); $labels_to_remove[] = $label; } @@ -381,7 +381,7 @@ public static function manage(): void // Move these back to the inbox if necessary. if (!empty($stranded_messages)) { // We now have more messages in the inbox. - Label::$loaded[-1]['messages'] += count($stranded_messages); + Label::$loaded[-1]['messages'] += \count($stranded_messages); Db::$db->query( '', 'UPDATE {db_prefix}pm_recipients @@ -400,7 +400,7 @@ public static function manage(): void foreach (Rule::$loaded as $k => $rule) { // Each action... foreach ($rule->actions as $k2 => $action) { - if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) { + if ($action['t'] != 'lab' || !\in_array($action['v'], $labels_to_remove)) { continue; } diff --git a/Sources/PersonalMessage/PM.php b/Sources/PersonalMessage/PM.php index a04c66b502..fc7a038ca4 100644 --- a/Sources/PersonalMessage/PM.php +++ b/Sources/PersonalMessage/PM.php @@ -327,9 +327,9 @@ public function format(int $counter = 0, array $format_options = []): array $label_ids = array_diff(array_keys($labels), [-1]); - $href = Config::$scripturl . '?action=pm;f=' . $this->folder . (Utils::$context['current_label_id'] != -1 && !empty($label_ids) && in_array(Utils::$context['current_label_id'], $label_ids) ? ';l=' . Utils::$context['current_label_id'] : '') . ';pmid=' . $this->id . '#msg' . $this->id; + $href = Config::$scripturl . '?action=pm;f=' . $this->folder . (Utils::$context['current_label_id'] != -1 && !empty($label_ids) && \in_array(Utils::$context['current_label_id'], $label_ids) ? ';l=' . Utils::$context['current_label_id'] : '') . ';pmid=' . $this->id . '#msg' . $this->id; - $number_recipients = count($recipients['to']); + $number_recipients = \count($recipients['to']); $this->formatted = [ 'id' => $this->id, @@ -342,10 +342,10 @@ public function format(int $counter = 0, array $format_options = []): array 'recipients' => $recipients, 'number_recipients' => $number_recipients, 'labels' => $labels, - 'fully_labeled' => count($labels) == count(Label::$loaded), + 'fully_labeled' => \count($labels) == \count(Label::$loaded), 'is_replied_to' => $is_replied_to, 'is_unread' => $is_unread, - 'is_selected' => !empty($temp_pm_selected) && in_array($this->id, $temp_pm_selected), + 'is_selected' => !empty($temp_pm_selected) && \in_array($this->id, $temp_pm_selected), 'is_message_author' => $this->member_from == User::$me->id, 'is_head' => $this->id === $this->head, 'href' => $href, @@ -509,7 +509,7 @@ public static function get(int|array $ids, array $query_customizations = []): \G Received::loadByPm($ids); // Asked for single PM that has already been loaded? Just yield and return. - if (count($ids) === 1 && isset(self::$loaded[reset($ids)])) { + if (\count($ids) === 1 && isset(self::$loaded[reset($ids)])) { yield self::$loaded[reset($ids)]; return; @@ -527,7 +527,7 @@ public static function get(int|array $ids, array $query_customizations = []): \G $order = $query_customizations['order'] ?? []; $group = $query_customizations['group'] ?? []; - $limit = $query_customizations['limit'] ?? count($ids); + $limit = $query_customizations['limit'] ?? \count($ids); $params = $query_customizations['params'] ?? []; // There will never be an ID 0, but SMF doesn't like empty arrays when you tell it to expect an array of integers... @@ -702,7 +702,7 @@ public static function compose(): void } if (isset($pm)) { - if ($pm->member_from != User::$me->id && ($_REQUEST['u'] == 'all' || in_array($pm->member_from, $_REQUEST['u']))) { + if ($pm->member_from != User::$me->id && ($_REQUEST['u'] == 'all' || \in_array($pm->member_from, $_REQUEST['u']))) { Utils::$context['recipients']['to'][$pm->member_from] = [ 'id' => $pm->member_from, 'name' => Utils::htmlspecialchars($pm->from_name), @@ -742,7 +742,7 @@ public static function compose(): void LIMIT {int:limit}', [ 'member_list' => $_REQUEST['u'], - 'limit' => count($_REQUEST['u']), + 'limit' => \count($_REQUEST['u']), ], ); @@ -898,7 +898,7 @@ public static function compose2(): bool // First, let's see if there's user ID's given. $recipientList[$recipientType] = []; - if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType])) { + if (!empty($_POST['recipient_' . $recipientType]) && \is_array($_POST['recipient_' . $recipientType])) { foreach ($_POST['recipient_' . $recipientType] as $recipient) { $recipientList[$recipientType][] = (int) $recipient; } @@ -914,7 +914,7 @@ public static function compose2(): bool $namedRecipientList[$recipientType] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $recipientString)))); foreach ($namedRecipientList[$recipientType] as $index => $recipient) { - if (strlen(trim($recipient)) > 0) { + if (\strlen(trim($recipient)) > 0) { $namedRecipientList[$recipientType][$index] = Utils::htmlspecialchars(Utils::strtolower(trim($recipient))); } else { unset($namedRecipientList[$recipientType][$index]); @@ -934,7 +934,7 @@ public static function compose2(): bool Utils::strtolower($member['email']), ]; - if (count(array_intersect($testNames, $namedRecipientList[$recipientType])) !== 0) { + if (\count(array_intersect($testNames, $namedRecipientList[$recipientType])) !== 0) { $recipientList[$recipientType][] = $member['id']; // Get rid of this username, since we found it. @@ -1071,7 +1071,7 @@ public static function compose2(): bool } // Before we send the PM, let's make sure we don't have an abuse of numbers. - if (!empty(Config::$modSettings['max_pm_recipients']) && count($recipientList['to']) + count($recipientList['bcc']) > Config::$modSettings['max_pm_recipients'] && !User::$me->allowedTo(['moderate_forum', 'send_mail', 'admin_forum'])) { + if (!empty(Config::$modSettings['max_pm_recipients']) && \count($recipientList['to']) + \count($recipientList['bcc']) > Config::$modSettings['max_pm_recipients'] && !User::$me->allowedTo(['moderate_forum', 'send_mail', 'admin_forum'])) { Utils::$context['send_log'] = [ 'sent' => [], 'failed' => [Lang::getTxt('pm_too_many_recipients', [Config::$modSettings['max_pm_recipients']])], @@ -1174,7 +1174,7 @@ public static function send(array $recipients, string $subject, string $message, } // Make sure is an array - if (!is_array($recipients)) { + if (!\is_array($recipients)) { $recipients = [$recipients]; } @@ -1268,7 +1268,7 @@ public static function send(array $recipients, string $subject, string $message, ) || ( $criterium['t'] == 'gid' - && in_array($criterium['v'], User::$me->groups) + && \in_array($criterium['v'], User::$me->groups) ) || ( $criterium['t'] == 'sub' @@ -1331,7 +1331,7 @@ public static function send(array $recipients, string $subject, string $message, 'buddies_only' => 2, 'admins_only' => 3, 'recipients' => $all_to, - 'count_recipients' => count($all_to), + 'count_recipients' => \count($all_to), 'from_id' => $from['id'], ], ); @@ -1358,7 +1358,7 @@ public static function send(array $recipients, string $subject, string $message, $message_limit = -1; // For each group see whether they've gone over their limit - assuming they're not an admin. - if (!in_array(1, $groups)) { + if (!\in_array(1, $groups)) { foreach ($groups as $id) { if (isset(self::$message_limit_cache[$id]) && $message_limit != 0 && $message_limit < self::$message_limit_cache[$id]) { $message_limit = self::$message_limit_cache[$id]; @@ -1374,7 +1374,7 @@ public static function send(array $recipients, string $subject, string $message, } // Do they have any of the allowed groups? - if (count(array_intersect($pmReadGroups['allowed'], $groups)) == 0 || count(array_intersect($pmReadGroups['denied'], $groups)) != 0) { + if (\count(array_intersect($pmReadGroups['allowed'], $groups)) == 0 || \count(array_intersect($pmReadGroups['denied'], $groups)) != 0) { $log['failed'][$row['id_member']] = Lang::getTxt('pm_error_user_cannot_read', ['member' => $row['real_name']]); unset($all_to[array_search($row['id_member'], $all_to)]); @@ -1501,9 +1501,9 @@ public static function send(array $recipients, string $subject, string $message, $to_list = []; foreach ($all_to as $to) { - $insertRows[] = [$id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1]; + $insertRows[] = [$id_pm, $to, \in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1]; - if (!in_array($to, $recipients['bcc'])) { + if (!\in_array($to, $recipients['bcc'])) { $to_list[] = $to; } } @@ -1521,7 +1521,7 @@ public static function send(array $recipients, string $subject, string $message, $to_names = []; - if (count($to_list) > 1) { + if (\count($to_list) > 1) { $request = Db::$db->query( '', 'SELECT real_name @@ -1621,12 +1621,12 @@ public static function delete(int|array|null $personal_messages, ?string $folder $owner = [User::$me->id]; } elseif (empty($owner)) { return; - } elseif (!is_array($owner)) { + } elseif (!\is_array($owner)) { $owner = [$owner]; } if ($personal_messages !== null) { - if (empty($personal_messages) || !is_array($personal_messages)) { + if (empty($personal_messages) || !\is_array($personal_messages)) { return; } @@ -2058,7 +2058,7 @@ public static function reportErrors(array $error_types, array $named_recipients, ); while ($row = Db::$db->fetch_assoc($request)) { - $recipientType = in_array($row['id_member'], $recipient_ids['bcc']) ? 'bcc' : 'to'; + $recipientType = \in_array($row['id_member'], $recipient_ids['bcc']) ? 'bcc' : 'to'; Utils::$context['recipients'][$recipientType][] = [ 'id' => $row['id_member'], @@ -2157,7 +2157,7 @@ public static function reportErrors(array $error_types, array $named_recipients, } // If it's not a minor error flag it as such. - if (!in_array($error_type, ['new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'])) { + if (!\in_array($error_type, ['new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'])) { Utils::$context['error_type'] = 'serious'; } } diff --git a/Sources/PersonalMessage/Popup.php b/Sources/PersonalMessage/Popup.php index d75f34f4f5..41ed36fe8a 100644 --- a/Sources/PersonalMessage/Popup.php +++ b/Sources/PersonalMessage/Popup.php @@ -59,11 +59,11 @@ public function show(): void if (!empty($pms)) { // Just quickly, it's possible that the number of PMs can get out of sync. - $count_unread = count($pms); + $count_unread = \count($pms); if ($count_unread != User::$me->unread_messages) { User::updateMemberData(User::$me->id, ['unread_messages' => $count_unread]); - User::$me->unread_messages = count($pms); + User::$me->unread_messages = \count($pms); } // Now, actually fetch me some PMs. diff --git a/Sources/PersonalMessage/Received.php b/Sources/PersonalMessage/Received.php index 86a0663f22..7543c4450a 100644 --- a/Sources/PersonalMessage/Received.php +++ b/Sources/PersonalMessage/Received.php @@ -215,7 +215,7 @@ public function removeLabel(int $label_id): void $this->labels = array_diff($this->labels, [$label_id]); // If it has no labels, put it back in the inbox. - if (empty($this->labels) || in_array(-1, $this->labels)) { + if (empty($this->labels) || \in_array(-1, $this->labels)) { $this->in_inbox = true; $this->labels[] = -1; } @@ -236,7 +236,7 @@ public function save(): void $this->labels = array_map('intval', $this->labels); - if (empty($this->labels) || in_array(-1, $this->labels)) { + if (empty($this->labels) || \in_array(-1, $this->labels)) { $this->in_inbox = true; } @@ -608,12 +608,12 @@ protected function getLabels(): void } foreach (Label::load() as $label) { - if (in_array($this->id, $label->pms)) { + if (\in_array($this->id, $label->pms)) { $this->labels[] = $label->id; } } - if (empty($this->labels) || in_array(-1, $this->labels)) { + if (empty($this->labels) || \in_array(-1, $this->labels)) { $this->in_inbox = true; } diff --git a/Sources/PersonalMessage/Rule.php b/Sources/PersonalMessage/Rule.php index 05cff101ff..aff3901ca7 100644 --- a/Sources/PersonalMessage/Rule.php +++ b/Sources/PersonalMessage/Rule.php @@ -367,7 +367,7 @@ public static function apply(bool $all_messages = false): void $realLabels = []; foreach (Utils::$context['labels'] as $label) { - if (in_array($label['id'], $labels)) { + if (\in_array($label['id'], $labels)) { $realLabels[] = $label['id']; } } @@ -594,7 +594,7 @@ public static function manage(): void 't' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind], ]; - } elseif (in_array($type, ['sub', 'msg']) && trim($_POST['ruledef'][$ind]) != '') { + } elseif (\in_array($type, ['sub', 'msg']) && trim($_POST['ruledef'][$ind]) != '') { $rule->criteria[] = [ 't' => $type, 'v' => Utils::htmlspecialchars(trim($_POST['ruledef'][$ind])), diff --git a/Sources/PersonalMessage/Search.php b/Sources/PersonalMessage/Search.php index 1d6357ecda..6c83266227 100644 --- a/Sources/PersonalMessage/Search.php +++ b/Sources/PersonalMessage/Search.php @@ -213,12 +213,12 @@ public function showForm(): void Utils::$context['search_labels'][] = [ 'id' => $label['id'], 'name' => $label['name'], - 'checked' => !empty($searchedLabels) ? in_array($label['id'], $searchedLabels) : true, + 'checked' => !empty($searchedLabels) ? \in_array($label['id'], $searchedLabels) : true, ]; } // Are all the labels checked? - Utils::$context['check_all'] = empty($searchedLabels) || count(Utils::$context['search_labels']) == count($searchedLabels); + Utils::$context['check_all'] = empty($searchedLabels) || \count(Utils::$context['search_labels']) == \count($searchedLabels); // Load the error text strings if there were errors in the search. if (!empty(Utils::$context['search_errors'])) { @@ -313,9 +313,9 @@ public function performSearch(): void } Db::$db->free_result($request); - Utils::$context['num_results'] = count($pms); - Utils::$context['messages'] = array_slice($pms, $this->start, $this->per_page); - Utils::$context['posters'] = array_slice($posters, $this->start, $this->per_page); + Utils::$context['num_results'] = \count($pms); + Utils::$context['messages'] = \array_slice($pms, $this->start, $this->per_page); + Utils::$context['posters'] = \array_slice($posters, $this->start, $this->per_page); // Load the users... User::load(Utils::$context['posters']); @@ -397,7 +397,7 @@ protected function setParams(): void list($this->params['sort'], $this->params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); } - $this->params['sort'] = !empty($this->params['sort']) && in_array($this->params['sort'], $this->sort_columns) ? $this->params['sort'] : 'pm.id_pm'; + $this->params['sort'] = !empty($this->params['sort']) && \in_array($this->params['sort'], $this->sort_columns) ? $this->params['sort'] : 'pm.id_pm'; $this->params['sort_dir'] = !empty($this->params['sort_dir']) && $this->params['sort_dir'] == 'asc' ? 'asc' : 'desc'; } @@ -455,10 +455,10 @@ protected function setUserQuery(): void $possible_users = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $userString))); - for ($k = 0, $n = count($possible_users); $k < $n; $k++) { + for ($k = 0, $n = \count($possible_users); $k < $n; $k++) { $possible_users[$k] = trim($possible_users[$k]); - if (strlen($possible_users[$k]) == 0) { + if (\strlen($possible_users[$k]) == 0) { unset($possible_users[$k]); } } @@ -534,7 +534,7 @@ protected function setLabelQuery(): void } // Assuming we have some labels - make them all integers. - if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel'])) { + if (!empty($_REQUEST['searchlabel']) && \is_array($_REQUEST['searchlabel'])) { $_REQUEST['searchlabel'] = array_map('intval', $_REQUEST['searchlabel']); } else { $_REQUEST['searchlabel'] = []; @@ -548,9 +548,9 @@ protected function setLabelQuery(): void Utils::$context['search_errors']['no_labels_selected'] = true; } // Otherwise prepare the query! - elseif (count($_REQUEST['searchlabel']) != count(Label::$loaded)) { + elseif (\count($_REQUEST['searchlabel']) != \count(Label::$loaded)) { // Special case here... "inbox" isn't a real label... - if (in_array(-1, $_REQUEST['searchlabel'])) { + if (\in_array(-1, $_REQUEST['searchlabel'])) { Utils::$context['search_in'][] = Label::$loaded[-1]['name']; $this->label_query = ' AND pmr.in_inbox = {int:in_inbox}'; @@ -625,7 +625,7 @@ protected function setSearchQuery(): void if ($word == '-') { $word = Utils::strtolower(trim($searchArray[$index])); - if (strlen($word) > 0) { + if (\strlen($word) > 0) { $excludedWords[] = $word; } @@ -638,7 +638,7 @@ protected function setSearchQuery(): void if (str_starts_with(trim($word), '-')) { $word = substr(Utils::strtolower($word), 1); - if (strlen($word) > 0) { + if (\strlen($word) > 0) { $excludedWords[] = $word; } @@ -682,9 +682,9 @@ protected function setSearchQuery(): void } if ($this->params['subject_only']) { - $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; + $andQueryParts[] = 'pm.subject' . (\in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; } else { - $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; + $andQueryParts[] = '(pm.subject' . (\in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (\in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; } $this->searchq_parameters['search_' . $index] = '%' . strtr($word, ['_' => '\\_', '%' => '\\%']) . '%'; diff --git a/Sources/Poll.php b/Sources/Poll.php index a1eb446408..ca000deca0 100644 --- a/Sources/Poll.php +++ b/Sources/Poll.php @@ -379,7 +379,7 @@ public function format(array $format_options = []): array 'lock' => $this->permissions['allow_lock_poll'], 'edit' => $this->permissions['allow_edit_poll'], 'remove' => $this->permissions['can_remove_poll'], - 'allowed_warning' => $this->max_votes > 1 ? Lang::getTxt('poll_options_limit', [min(count($this->choices), $this->max_votes)]) : '', + 'allowed_warning' => $this->max_votes > 1 ? Lang::getTxt('poll_options_limit', [min(\count($this->choices), $this->max_votes)]) : '', 'is_expired' => !empty($this->expire_time) && $this->expire_time < time(), 'expire_time' => !empty($this->expire_time) ? Time::create('@' . $this->expire_time)->format() : 0, 'expiration' => empty($this->expire_time) ? '' : ceil($this->expire_time <= time() ? -1 : ($this->expire_time - time()) / (3600 * 24)), @@ -536,7 +536,7 @@ public function addChoice(array $choice_props, bool $allow_empty = false): void unset($choice_props['id_poll']); } - $choice_props['id'] = (int) ($choice_props['id'] ?? count($this->choices)); + $choice_props['id'] = (int) ($choice_props['id'] ?? \count($this->choices)); $choice_props['poll'] = (int) ($choice_props['poll'] ?? ($this->id ?? 0)); $choice_props['votes'] = (int) ($choice_props['votes'] ?? 0); $choice_props['new'] = !empty($choice_props['new']); @@ -730,11 +730,11 @@ public function __set(string $prop, $value): void return; } - settype($value, gettype($this->{$prop})); + settype($value, \gettype($this->{$prop})); $this->{$prop} = $value; - } elseif (array_key_exists($prop, $this->prop_aliases)) { + } elseif (\array_key_exists($prop, $this->prop_aliases)) { // Can't unset a virtual property. - if (is_null($value)) { + if (\is_null($value)) { return; } @@ -761,7 +761,7 @@ public function __set(string $prop, $value): void if ($real_prop == 'id') { $this->{$real_prop} = (int) $value; } else { - settype($value, gettype($this->{$real_prop})); + settype($value, \gettype($this->{$real_prop})); $this->{$real_prop} = $value; } } @@ -1014,7 +1014,7 @@ public static function vote(): void } // Too many options checked! - if (count($_REQUEST['options']) > $poll->max_votes) { + if (\count($_REQUEST['options']) > $poll->max_votes) { ErrorHandler::fatalLang('poll_too_many_votes', false, [$poll->max_votes]); } @@ -1029,7 +1029,7 @@ public static function vote(): void } // If it's a guest don't let them vote again. - if (User::$me->is_guest && count($choices) > 0) { + if (User::$me->is_guest && \count($choices) > 0) { // Time is stored in case the poll is reset later, plus what they voted for. $_COOKIE['guest_poll_vote'] = empty($_COOKIE['guest_poll_vote']) ? '' : $_COOKIE['guest_poll_vote']; @@ -1175,11 +1175,11 @@ public static function edit(): void do { $poll->addChoice([ 'id' => empty($poll->choices) ? 0 : max(array_keys($poll->choices)) + 1, - 'number' => count($poll->choices), + 'number' => \count($poll->choices), 'label' => '', 'votes' => -1, ], true); - } while (count($poll->choices) < 2); + } while (\count($poll->choices) < 2); } // Basic theme info... @@ -1614,11 +1614,11 @@ protected function getVoters(): void Db::$db->free_result($request); $this->voters = array_unique(array_column($votes, 'id_member')); - $this->total_voters = count($this->voters) + $this->num_guest_voters; + $this->total_voters = \count($this->voters) + $this->num_guest_voters; // Did you vote, and what did you vote for? if (!User::$me->is_guest) { - $this->has_voted = in_array(User::$me->id, $this->voters); + $this->has_voted = \in_array(User::$me->id, $this->voters); foreach ($votes as $vote) { if ($vote['id_member'] != User::$me->id) { @@ -1658,7 +1658,7 @@ protected function getVoters(): void unset($guestvoted[0], $guestvoted[1]); foreach ($this->choices as $choice => $details) { - $details->voted_this = in_array($choice, $guestvoted); + $details->voted_this = \in_array($choice, $guestvoted); $this->has_voted |= $details->voted_this; } } @@ -1689,7 +1689,7 @@ protected function checkAccess(int $options): void $this->params['is_approved'] = 1; } - if ($options & self::CHECK_ACCESS && !in_array(0, ($boardsAllowed = User::$me->boardsAllowedTo('poll_view')))) { + if ($options & self::CHECK_ACCESS && !\in_array(0, ($boardsAllowed = User::$me->boardsAllowedTo('poll_view')))) { $this->where[] = 't.id_board IN ({array_int:boards_allowed_see})'; $this->params['boards_allowed_see'] = $boardsAllowed; } @@ -1835,7 +1835,7 @@ protected static function canGuestsVote(): bool if (isset(Board::$info->id)) { $groupsAllowedVote = User::groupsAllowedTo('poll_vote', Board::$info->id); - self::$guest_vote_enabled = in_array(-1, $groupsAllowedVote['allowed']); + self::$guest_vote_enabled = \in_array(-1, $groupsAllowedVote['allowed']); } return self::$guest_vote_enabled; @@ -1860,9 +1860,9 @@ protected static function sanitizeInput(array &$errors): void } // What are you going to vote between with one choice?!? - if (count($_POST['options']) < 2) { + if (\count($_POST['options']) < 2) { $errors[] = 'poll_few'; - } elseif (count($_POST['options']) > 256) { + } elseif (\count($_POST['options']) > 256) { $errors[] = 'poll_many'; } @@ -1871,7 +1871,7 @@ protected static function sanitizeInput(array &$errors): void } // Make sure these things are all sane. - $_POST['poll_max_votes'] = min(max((int) ($_POST['poll_max_votes'] ?? 1), 1), count($_POST['options'] ?? [])); + $_POST['poll_max_votes'] = min(max((int) ($_POST['poll_max_votes'] ?? 1), 1), \count($_POST['options'] ?? [])); $_POST['poll_expire'] = min(max((int) ($_POST['poll_expire'] ?? 0), 0), 9999); $_POST['poll_hide'] = (int) ($_POST['poll_hide'] ?? 0); $_POST['poll_change_vote'] = (int) !empty($_POST['poll_change_vote']); diff --git a/Sources/Profile.php b/Sources/Profile.php index 1d1b85ed1a..d3d6f6c704 100644 --- a/Sources/Profile.php +++ b/Sources/Profile.php @@ -412,7 +412,7 @@ public function loadStandardFields(bool $force_reload = false) ], 'date_registered' => [ 'type' => 'date', - 'value' => empty($this->date_registered) || !is_int($this->date_registered) ? Lang::$txt['not_applicable'] : Time::strftime('%Y-%m-%d', $this->date_registered), + 'value' => empty($this->date_registered) || !\is_int($this->date_registered) ? Lang::$txt['not_applicable'] : Time::strftime('%Y-%m-%d', $this->date_registered), 'label' => Lang::$txt['date_registered'], 'log_change' => true, 'permission' => 'moderate_forum', @@ -828,7 +828,7 @@ public function loadStandardFields(bool $force_reload = false) 'input_validate' => function (&$value) { $smiley_sets = explode(',', Config::$modSettings['smiley_sets_known']); - if (!in_array($value, $smiley_sets) && $value != 'none') { + if (!\in_array($value, $smiley_sets) && $value != 'none') { $value = ''; } @@ -995,7 +995,7 @@ public function loadStandardFields(bool $force_reload = false) } // Is it specifically disabled? - if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) { + if (\in_array($key, $disabled_fields) || (isset($field['link_with']) && \in_array($field['link_with'], $disabled_fields))) { unset($this->standard_fields[$key]); } } @@ -1019,7 +1019,7 @@ public function loadCustomFields(string $area = 'summary'): void } // Skip custom fields that don't belong in the area we are viewing. - if (!in_array($area, ['summary', $cf_def['show_profile']])) { + if (!\in_array($area, ['summary', $cf_def['show_profile']])) { continue; } @@ -1060,7 +1060,7 @@ public function loadCustomFields(string $area = 'summary'): void if (isset($_POST['customfield'], $_POST['customfield'][$cf_def['col_name']])) { $value = Utils::htmlspecialchars($_POST['customfield'][$cf_def['col_name']]); - if (in_array($cf_def['field_type'], ['select', 'radio'])) { + if (\in_array($cf_def['field_type'], ['select', 'radio'])) { $value = $cf_def['field_options'][$value] ?? ''; } } @@ -1169,7 +1169,7 @@ public function loadThemeOptions(bool $defaultSettings = false) Utils::$context['member']['options'] = $this->data['options'] ?? []; - if (isset($_POST['options']) && is_array($_POST['options'])) { + if (isset($_POST['options']) && \is_array($_POST['options'])) { foreach ($_POST['options'] as $k => $v) { Utils::$context['member']['options'][$k] = $v; } @@ -1384,7 +1384,7 @@ public function loadAssignableGroups(): bool } $group->is_primary = $this->data['id_group'] == $group->id; - $group->is_additional = in_array($group->id, $this->additional_groups); + $group->is_additional = \in_array($group->id, $this->additional_groups); } // For the templates. @@ -1425,7 +1425,7 @@ public function setupContext(array $fields): void // First check for any linked sets. foreach ($this->standard_fields as $key => $field) { - if (isset($field['link_with']) && in_array($field['link_with'], $fields)) { + if (isset($field['link_with']) && \in_array($field['link_with'], $fields)) { $fields[] = $key; } } @@ -1439,7 +1439,7 @@ public function setupContext(array $fields): void $cur_field = &$this->standard_fields[$field]; // Does it have a preload and does that preload succeed? - if (isset($cur_field['preload']) && !call_user_func(...((array) $cur_field['preload']))) { + if (isset($cur_field['preload']) && !\call_user_func(...((array) $cur_field['preload']))) { continue; } @@ -1536,7 +1536,7 @@ public function save(): void // This allows variables to call activities when they save. Utils::$context['profile_execute_on_save'] = []; - if (User::$me->is_owner && in_array(Menu::$loaded['profile']->current_area, ['account', 'forumprofile', 'theme'])) { + if (User::$me->is_owner && \in_array(Menu::$loaded['profile']->current_area, ['account', 'forumprofile', 'theme'])) { Utils::$context['profile_execute_on_save']['reload_user'] = [__CLASS__ . '::reloadUser', Profile::$member->id]; } @@ -1638,7 +1638,7 @@ public function save(): void // Do we have any post save functions to execute? if (!empty(Utils::$context['profile_execute_on_save'])) { foreach (Utils::$context['profile_execute_on_save'] as $saveFunc) { - call_user_func(...((array) $saveFunc)); + \call_user_func(...((array) $saveFunc)); } } @@ -1703,7 +1703,7 @@ public function validateGroups(int &$value, array $additional_groups = []): bool $unassignable = Group::getUnassignable(); // The account page allows you to change your id_group - but not to a protected group! - if (!empty($unassignable) && in_array($value, $unassignable) && !in_array($value, $this->groups)) { + if (!empty($unassignable) && \in_array($value, $unassignable) && !\in_array($value, $this->groups)) { $value = $this->data['id_group']; } @@ -1725,7 +1725,7 @@ public function validateGroups(int &$value, array $additional_groups = []): bool // Make sure there is always an admin. if ($this->is_admin) { - $stillAdmin = $value == 1 || in_array(1, $additional_groups); + $stillAdmin = $value == 1 || \in_array(1, $additional_groups); // If they would no longer be an admin, look for another... if (!$stillAdmin) { @@ -1806,7 +1806,7 @@ public function validateAvatarData(string &$value): bool|string break; } - if (is_string($result)) { + if (\is_string($result)) { return $result; } @@ -2022,7 +2022,7 @@ public static function validateSignature(string &$value): bool|string if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) { $sizes = Image::getSizeExternal($matches[7][$key]); - if (is_array($sizes)) { + if (\is_array($sizes)) { // Too wide? if ($sizes[0] > $sig_limits[5] && $sig_limits[5]) { $width = $sig_limits[5]; @@ -2066,7 +2066,7 @@ public static function validateSignature(string &$value): bool|string Lang::$txt['profile_error_signature_disabled_bbc'] = Lang::getTxt( 'profile_error_signature_disabled_bbc', [ - 'num_disabled_tags' => count($disabledTags), + 'num_disabled_tags' => \count($disabledTags), 'list_disabled_tags' => Lang::sentenceList($disabledTags), ], ); @@ -2141,7 +2141,7 @@ protected function prepareToSaveStandardFields(): void } // Make sure there are no evil characters in the input. - $_POST[$key] = Utils::sanitizeChars(Utils::normalize($_POST[$key]), in_array($key, ['member_name', 'real_name']) ? 1 : 0); + $_POST[$key] = Utils::sanitizeChars(Utils::normalize($_POST[$key]), \in_array($key, ['member_name', 'real_name']) ? 1 : 0); // What gets updated? $db_key = $field['save_key'] ?? $key; @@ -2272,7 +2272,7 @@ protected function prepareToSaveIgnoreBoards(): void $_POST['brd'] = []; } - if (!is_array($_POST['brd'])) { + if (!\is_array($_POST['brd'])) { $_POST['brd'] = [$_POST['brd']]; } @@ -2333,7 +2333,7 @@ protected function prepareToSaveCustomFields(?string $area = null): void } // Owners can only modify levels 0 and 2. - if (!in_array($cf_def['private'], [0, 2])) { + if (!\in_array($cf_def['private'], [0, 2])) { continue; } } @@ -2408,7 +2408,7 @@ protected function prepareToSaveCustomFields(?string $area = null): void } // If they tried to set a bad value, report the error. - if (is_string($mask_error)) { + if (\is_string($mask_error)) { $this->cf_save_errors[] = $mask_error; } // Did it change? @@ -2464,7 +2464,7 @@ protected function prepareToSaveCustomFields(?string $area = null): void // Now that the hook is done, we can set deletes to just the value we need. $this->new_cf_data['deletes'] = array_map(fn ($del) => $del['variable'], $deletes); - if (!empty($hook_errors) && is_array($hook_errors)) { + if (!empty($hook_errors) && \is_array($hook_errors)) { $this->cf_save_errors = array_merge($this->cf_save_errors, $hook_errors); } @@ -2488,7 +2488,7 @@ protected function prepareToSaveOptions(): void continue; } - if (count(array_intersect(array_keys($_POST[$key]), self::RESERVED_VARS)) != 0) { + if (\count(array_intersect(array_keys($_POST[$key]), self::RESERVED_VARS)) != 0) { ErrorHandler::fatalLang('no_access', false); } } @@ -2496,7 +2496,7 @@ protected function prepareToSaveOptions(): void self::loadCustomFieldDefinitions(); // These are the theme changes... - if (isset($_POST['options']) && is_array($_POST['options'])) { + if (isset($_POST['options']) && \is_array($_POST['options'])) { foreach ($_POST['options'] as $opt => $val) { if (isset(self::$custom_field_definitions[$opt])) { continue; @@ -2515,13 +2515,13 @@ protected function prepareToSaveOptions(): void $this->new_options['updates'][] = [ $id_theme, $opt, - is_array($val) ? implode(',', $val) : $val, + \is_array($val) ? implode(',', $val) : $val, $this->id, ]; } } - if (isset($_POST['default_options']) && is_array($_POST['default_options'])) { + if (isset($_POST['default_options']) && \is_array($_POST['default_options'])) { foreach ($_POST['default_options'] as $opt => $val) { if (isset(self::$custom_field_definitions[$opt])) { continue; @@ -2540,7 +2540,7 @@ protected function prepareToSaveOptions(): void $this->new_options['updates'][] = [ 1, $opt, - is_array($val) ? implode(',', $val) : $val, + \is_array($val) ? implode(',', $val) : $val, $this->id, ]; @@ -2572,7 +2572,7 @@ protected function getAvatars(string $directory, int $level = 0): array } while ($line = $dir->read()) { - if (in_array($line, ['.', '..', 'blank.png', 'index.php'])) { + if (\in_array($line, ['.', '..', 'blank.png', 'index.php'])) { continue; } @@ -2591,7 +2591,7 @@ protected function getAvatars(string $directory, int $level = 0): array if ($level == 0) { $result[] = [ 'filename' => 'blank.png', - 'checked' => in_array(Utils::$context['member']['avatar']['server_pic'], ['', 'blank.png']), + 'checked' => \in_array(Utils::$context['member']['avatar']['server_pic'], ['', 'blank.png']), 'name' => Lang::$txt['no_pic'], 'is_dir' => false, ]; @@ -2614,7 +2614,7 @@ protected function getAvatars(string $directory, int $level = 0): array } foreach ($files as $line) { - $filename = substr($line, 0, (strlen($line) - strlen(strrchr($line, '.')))); + $filename = substr($line, 0, (\strlen($line) - \strlen(strrchr($line, '.')))); $extension = substr(strrchr($line, '.'), 1); // Make sure it is an image. @@ -2720,7 +2720,7 @@ protected function setAvatarExternal(string $url): ?string $url = str_replace(' ', '%20', $url); // External URL is too long. - if (strlen($url) > 255) { + if (\strlen($url) > 255) { return 'bad_avatar_url_too_long'; } @@ -3030,7 +3030,7 @@ protected static function reloadUser(int $memID): void } // Export properties to global namespace for backward compatibility. -if (is_callable([Profile::class, 'exportStatic'])) { +if (\is_callable([Profile::class, 'exportStatic'])) { Profile::exportStatic(); } diff --git a/Sources/ProxyServer.php b/Sources/ProxyServer.php index ccbbd9408c..d288e3d85b 100644 --- a/Sources/ProxyServer.php +++ b/Sources/ProxyServer.php @@ -114,7 +114,7 @@ public function checkRequest(): bool // Try to create the image cache directory if it doesn't exist if (!file_exists($this->cache)) { - if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php')) { + if (!mkdir($this->cache) || !copy(\dirname($this->cache) . '/index.php', $this->cache . '/index.php')) { return false; } } @@ -132,7 +132,7 @@ public function checkRequest(): bool } // Ensure any non-ASCII characters in the URL are encoded correctly - $request = strval($request->toAscii()); + $request = \strval($request->toAscii()); if (hash_hmac('sha1', $request, $this->secret) != $_GET['hash']) { return false; @@ -274,7 +274,7 @@ protected function cacheImage(string $request): bool } // Validate the filesize - $size = strlen($image); + $size = \strlen($image); if ($size > ($this->maxSize * 1024)) { $this->redirectexit($request); @@ -316,7 +316,7 @@ public function housekeeping(): void if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { - if (is_file($path . $file) && !in_array($file, ['index.php', '.htaccess']) && time() - filemtime($path . $file) > $this->maxDays * 86400) { + if (is_file($path . $file) && !\in_array($file, ['index.php', '.htaccess']) && time() - filemtime($path . $file) > $this->maxDays * 86400) { unlink($path . $file); } } diff --git a/Sources/Punycode.php b/Sources/Punycode.php index 8000411a39..6e057879ba 100755 --- a/Sources/Punycode.php +++ b/Sources/Punycode.php @@ -187,7 +187,7 @@ public function encode(string $input): string|bool break; case self::IDNA_ERROR_EMPTY_LABEL: - $parts_count = count($parts); + $parts_count = \count($parts); if ($parts_count === 1 || $p !== $parts_count - 1) { return false; @@ -202,7 +202,7 @@ public function encode(string $input): string|bool $output = implode('.', $parts); // IDNA_ERROR_DOMAIN_NAME_TOO_LONG - if (strlen(rtrim($output, '.')) > 253) { + if (\strlen(rtrim($output, '.')) > 253) { return false; } @@ -222,7 +222,7 @@ protected function encodePart(string $input): string $n = static::INITIAL_N; $bias = static::INITIAL_BIAS; $delta = 0; - $h = $b = count($codePoints['basic']); + $h = $b = \count($codePoints['basic']); $output = ''; @@ -304,7 +304,7 @@ public function decode(string $input): string|bool foreach ($parts as $p => &$part) { if (str_starts_with($part, static::PREFIX)) { - $part = substr($part, strlen(static::PREFIX)); + $part = substr($part, \strlen(static::PREFIX)); $part = $this->decodePart($part); if ($part === false) { @@ -314,7 +314,7 @@ public function decode(string $input): string|bool if ($this->validateLabel($part, false) !== 0) { if ($part === '') { - $parts_count = count($parts); + $parts_count = \count($parts); if ($parts_count === 1 || $p !== $parts_count - 1) { return false; @@ -350,8 +350,8 @@ protected function decodePart(string $input): string|bool $pos = 0; } - $outputLength = strlen($output); - $inputLength = strlen($input); + $outputLength = \strlen($output); + $inputLength = \strlen($input); while ($pos < $inputLength) { $oldi = $i; @@ -470,21 +470,21 @@ protected function listCodePoints(string $input): array */ protected function charToCodePoint(string $char): int { - $code = ord($char[0]); + $code = \ord($char[0]); if ($code < 128) { return $code; } if ($code < 224) { - return (($code - 192) * 64) + (ord($char[1]) - 128); + return (($code - 192) * 64) + (\ord($char[1]) - 128); } if ($code < 240) { - return (($code - 224) * 4096) + ((ord($char[1]) - 128) * 64) + (ord($char[2]) - 128); + return (($code - 224) * 4096) + ((\ord($char[1]) - 128) * 64) + (\ord($char[2]) - 128); } - return (($code - 240) * 262144) + ((ord($char[1]) - 128) * 4096) + ((ord($char[2]) - 128) * 64) + (ord($char[3]) - 128); + return (($code - 240) * 262144) + ((\ord($char[1]) - 128) * 4096) + ((\ord($char[2]) - 128) * 64) + (\ord($char[3]) - 128); } /** @@ -496,18 +496,18 @@ protected function charToCodePoint(string $char): int protected function codePointToChar(int $code): string { if ($code <= 0x7F) { - return chr($code); + return \chr($code); } if ($code <= 0x7FF) { - return chr(($code >> 6) + 192) . chr(($code & 63) + 128); + return \chr(($code >> 6) + 192) . \chr(($code & 63) + 128); } if ($code <= 0xFFFF) { - return chr(($code >> 12) + 224) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128); + return \chr(($code >> 12) + 224) . \chr((($code >> 6) & 63) + 128) . \chr(($code & 63) + 128); } - return chr(($code >> 18) + 240) . chr((($code >> 12) & 63) + 128) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128); + return \chr(($code >> 18) + 240) . \chr((($code >> 12) & 63) + 128) . \chr((($code >> 6) & 63) + 128) . \chr(($code & 63) + 128); } /** @@ -554,7 +554,7 @@ protected function preprocess(string $domain, array &$errors = []): string */ protected function validateLabel(string $label, bool $toPunycode = true): int { - $length = strlen($label); + $length = \strlen($label); if ($length === 0) { return self::IDNA_ERROR_EMPTY_LABEL; diff --git a/Sources/QueryString.php b/Sources/QueryString.php index afd1e1612f..c519a3b824 100644 --- a/Sources/QueryString.php +++ b/Sources/QueryString.php @@ -90,7 +90,7 @@ public static function cleanRequest(): void $temp = explode(';', $v); $_GET[$k] = $temp[0]; - for ($i = 1, $n = count($temp); $i < $n; $i++) { + for ($i = 1, $n = \count($temp); $i < $n; $i++) { @list($key, $val) = @explode('=', $temp[$i], 2); if (!isset($_GET[$key])) { @@ -385,9 +385,9 @@ public static function isFilteredRequest(array $value_list, string $var): bool $matched = false; if (isset($_REQUEST[$var], $value_list[$_REQUEST[$var]])) { - if (is_array($value_list[$_REQUEST[$var]])) { + if (\is_array($value_list[$_REQUEST[$var]])) { foreach ($value_list[$_REQUEST[$var]] as $subvar => $subvalues) { - $matched |= isset($_REQUEST[$subvar]) && in_array($_REQUEST[$subvar], $subvalues); + $matched |= isset($_REQUEST[$subvar]) && \in_array($_REQUEST[$subvar], $subvalues); } } else { $matched = true; @@ -415,7 +415,7 @@ public static function isFilteredRequest(array $value_list, string $var): bool public static function ob_sessrewrite(string $buffer): string { // If Config::$scripturl is set to nothing, or the SID is not defined (SSI?) just quit. - if (Config::$scripturl == '' || !defined('SID')) { + if (Config::$scripturl == '' || !\defined('SID')) { return $buffer; } @@ -433,7 +433,7 @@ public static function ob_sessrewrite(string $buffer): string !empty(Config::$modSettings['queryless_urls']) && ( !Sapi::isCGI() - || ini_get('cgi.fix_pathinfo') == 1 + || \ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1 ) && ( @@ -441,7 +441,7 @@ public static function ob_sessrewrite(string $buffer): string ) ) { // Let's do something special for session ids! - if (defined('SID') && SID != '') { + if (\defined('SID') && SID != '') { $buffer = preg_replace_callback( '~"' . preg_quote(Config::$scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m) { diff --git a/Sources/Sapi.php b/Sources/Sapi.php index 9b57730490..569dbd9ccb 100644 --- a/Sources/Sapi.php +++ b/Sources/Sapi.php @@ -155,7 +155,7 @@ public static function isCLI(): bool */ public static function supportsIsoCaseFolding(): bool { - return ord(strtolower(chr(138))) === 154; + return \ord(strtolower(\chr(138))) === 154; } /** @@ -226,7 +226,7 @@ public static function getTempDir(): string public static function setMemoryLimit(string $needed, bool $in_use = false): bool { // Everything in bytes. - $memory_current = self::memoryReturnBytes(ini_get('memory_limit')); + $memory_current = self::memoryReturnBytes(\ini_get('memory_limit')); $memory_needed = self::memoryReturnBytes($needed); // Should we account for how much is currently being used? @@ -237,7 +237,7 @@ public static function setMemoryLimit(string $needed, bool $in_use = false): boo // If more is needed, request it. if ($memory_current < $memory_needed) { @ini_set('memory_limit', ceil($memory_needed / 1048576) . 'M'); - $memory_current = self::memoryReturnBytes(ini_get('memory_limit')); + $memory_current = self::memoryReturnBytes(\ini_get('memory_limit')); } $memory_current = max($memory_current, self::memoryReturnBytes(get_cfg_var('memory_limit'))); @@ -254,13 +254,13 @@ public static function setMemoryLimit(string $needed, bool $in_use = false): boo */ public static function memoryReturnBytes(string $val): int { - if (is_integer($val)) { + if (\is_integer($val)) { return (int) $val; } // Separate the number from the designator. $val = trim($val); - $num = intval(substr($val, 0, strlen($val) - 1)); + $num = \intval(substr($val, 0, \strlen($val) - 1)); $last = strtolower(substr($val, -1)); // Convert to bytes. @@ -310,7 +310,7 @@ public static function setTimeLimit(int $limit = 600) */ public static function resetTimeout() { - if (self::isSoftware(self::SERVER_APACHE) && function_exists('apache_reset_timeout')) { + if (self::isSoftware(self::SERVER_APACHE) && \function_exists('apache_reset_timeout')) { try { apache_reset_timeout(); } catch (\Exception $e) { diff --git a/Sources/Search/APIs/Custom.php b/Sources/Search/APIs/Custom.php index 72fa584401..7d921fa34a 100644 --- a/Sources/Search/APIs/Custom.php +++ b/Sources/Search/APIs/Custom.php @@ -89,7 +89,7 @@ class Custom extends SearchApi implements SearchApiInterface public function __construct() { // Is this database supported? - if (!in_array(Config::$db_type, $this->supported_databases)) { + if (!\in_array(Config::$db_type, $this->supported_databases)) { $this->is_supported = false; return; @@ -225,8 +225,8 @@ public function getSize(): int */ public function searchSort(string $a, string $b): int { - $x = strlen($a) - (in_array($a, $this->excludedWords) ? 1000 : 0); - $y = strlen($b) - (in_array($b, $this->excludedWords) ? 1000 : 0); + $x = \strlen($a) - (\in_array($a, $this->excludedWords) ? 1000 : 0); + $y = \strlen($b) - (\in_array($b, $this->excludedWords) ? 1000 : 0); return $y < $x ? 1 : ($y > $x ? -1 : 0); } @@ -243,12 +243,12 @@ public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsE } // Excluded phrases don't benefit from being split into subwords. - if (count($subwords) > 1 && $isExcluded) { + if (\count($subwords) > 1 && $isExcluded) { return; } foreach ($subwords as $subword) { - if (Utils::entityStrlen((string) $subword) >= $this->min_word_length && !in_array($subword, $this->blacklisted_words)) { + if (Utils::entityStrlen((string) $subword) >= $this->min_word_length && !\in_array($subword, $this->blacklisted_words)) { $wordsSearch['indexed_words'][] = $subword; if ($isExcluded) { @@ -278,7 +278,7 @@ public function indexedWordQuery(array $words, array $search_data): mixed $count = 0; foreach ($words['words'] as $regularWord) { - if (in_array($regularWord, $query_params['excluded_words'])) { + if (\in_array($regularWord, $query_params['excluded_words'])) { $query_where[] = 'm.body NOT ' . $this->query_match_type . ' {string:complex_body_' . $count . '}'; } else { $query_where[] = 'm.body ' . $this->query_match_type . ' {string:complex_body_' . $count . '}'; @@ -344,7 +344,7 @@ public function indexedWordQuery(array $words, array $search_data): mixed foreach ($words['indexed_words'] as $indexedWord) { $numTables++; - if (in_array($indexedWord, $query_params['excluded_index_words'])) { + if (\in_array($indexedWord, $query_params['excluded_index_words'])) { $query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)'; $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; } else { @@ -895,7 +895,7 @@ public static function getWordNumbers(string $string, ?int $bytes_per_word): arr $total = 0; for ($i = 0; $i < $bytes_per_word; $i++) { - $total += $possible_chars[ord($encrypted[$i])] * pow(63, $i); + $total += $possible_chars[\ord($encrypted[$i])] * pow(63, $i); } $returned_ints[] = $bytes_per_word == 4 ? min($total, 16777215) : $total; diff --git a/Sources/Search/APIs/Fulltext.php b/Sources/Search/APIs/Fulltext.php index a25cc50737..0920c87c50 100644 --- a/Sources/Search/APIs/Fulltext.php +++ b/Sources/Search/APIs/Fulltext.php @@ -80,7 +80,7 @@ class Fulltext extends SearchApi implements SearchApiInterface public function __construct() { // Is this database supported? - if (!in_array(Config::$db_type, $this->supported_databases)) { + if (!\in_array(Config::$db_type, $this->supported_databases)) { $this->is_supported = false; return; @@ -127,7 +127,7 @@ public function getSize(): int if ( !isset($this->size) && isset(Utils::$context['table_info']['index_length']) - && is_int(Utils::$context['table_info']['index_length']) + && \is_int(Utils::$context['table_info']['index_length']) ) { $this->size = Utils::$context['table_info']['index_length']; } @@ -204,8 +204,8 @@ public function getStatus(): ?string */ public function searchSort(string $a, string $b): int { - $x = Utils::entityStrlen($a) - (in_array($a, $this->excludedWords) ? 1000 : 0); - $y = Utils::entityStrlen($b) - (in_array($b, $this->excludedWords) ? 1000 : 0); + $x = Utils::entityStrlen($a) - (\in_array($a, $this->excludedWords) ? 1000 : 0); + $y = Utils::entityStrlen($b) - (\in_array($b, $this->excludedWords) ? 1000 : 0); return $x < $y ? 1 : ($x > $y ? -1 : 0); } @@ -220,20 +220,20 @@ public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsE if (empty(Config::$modSettings['search_force_index'])) { // A boolean capable search engine and not forced to only use an index, we may use a non indexed search // this is harder on the server so we are restrictive here - if (count($subwords) > 1 && preg_match('~[.:@$]~', $word)) { + if (\count($subwords) > 1 && preg_match('~[.:@$]~', $word)) { // using special characters that a full index would ignore and the remaining words are short which would also be ignored if ((Utils::entityStrlen(current($subwords)) < $this->min_word_length) && (Utils::entityStrlen(next($subwords)) < $this->min_word_length)) { $wordsSearch['words'][] = trim($word, '/*- '); - $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; + $wordsSearch['complex_words'][] = \count($subwords) === 1 ? $word : '"' . $word . '"'; } } elseif (Utils::entityStrlen(trim($word, '/*- ')) < $this->min_word_length) { // short words have feelings too $wordsSearch['words'][] = trim($word, '/*- '); - $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; + $wordsSearch['complex_words'][] = \count($subwords) === 1 ? $word : '"' . $word . '"'; } } - $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; + $fulltextWord = \count($subwords) === 1 ? $word : '"' . $word . '"'; $wordsSearch['indexed_words'][] = $fulltextWord; if ($isExcluded) { @@ -264,7 +264,7 @@ public function indexedWordQuery(array $words, array $search_data): mixed if (empty(Config::$modSettings['search_simple_fulltext'])) { foreach ($words['words'] as $regularWord) { - if (in_array($regularWord, $query_params['excluded_words'])) { + if (\in_array($regularWord, $query_params['excluded_words'])) { $query_where[] = 'm.body NOT ' . $this->query_match_type . ' {string:complex_body_' . $count . '}'; } else { $query_where[] = 'm.body ' . $this->query_match_type . ' {string:complex_body_' . $count . '}'; @@ -346,12 +346,12 @@ public function indexedWordQuery(array $words, array $search_data): mixed foreach ($words['indexed_words'] as $fulltextWord) { $query_params['boolean_match'] .= ($row != 0 ? '&' : ''); - $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; + $query_params['boolean_match'] .= (\in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; $row++; } } else { foreach ($words['indexed_words'] as $fulltextWord) { - $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; + $query_params['boolean_match'] .= (\in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; } } @@ -580,7 +580,7 @@ public static function detectIndex(): void } Db::$db->free_result($request); - if (is_array(Utils::$context['fulltext_index'])) { + if (\is_array(Utils::$context['fulltext_index'])) { Utils::$context['fulltext_index'] = array_unique(Utils::$context['fulltext_index']); } } diff --git a/Sources/Search/APIs/Parsed.php b/Sources/Search/APIs/Parsed.php index b8515002de..eb25be750a 100644 --- a/Sources/Search/APIs/Parsed.php +++ b/Sources/Search/APIs/Parsed.php @@ -169,7 +169,7 @@ public function isValid(): bool */ public function searchSort(string $a, string $b): int { - return (Utils::entityStrlen($a) - (in_array($a, $this->excludedWords) ? 1000 : 0)) <=> (Utils::entityStrlen($b) - (in_array($b, $this->excludedWords) ? 1000 : 0)); + return (Utils::entityStrlen($a) - (\in_array($a, $this->excludedWords) ? 1000 : 0)) <=> (Utils::entityStrlen($b) - (\in_array($b, $this->excludedWords) ? 1000 : 0)); } /** @@ -251,7 +251,7 @@ public function prepareIndexes(string $word, array &$wordsSearch, array &$wordsE $word = $this->prepareString($word); // Is this a blacklisted word? - if (in_array($word, $this->blacklisted_words)) { + if (\in_array($word, $this->blacklisted_words)) { foreach ($keys as $key) { unset($wordsSearch['all_words'][$key]); } @@ -289,7 +289,7 @@ public function indexedWordQuery(array $words, array $search_data): mixed $all_words = array_merge($all_words, array_keys($temp)); - if (count($temp) > 1) { + if (\count($temp) > 1) { $phrases[] = array_keys($temp); } else { $single_words[] = key($temp); @@ -368,7 +368,7 @@ public function indexedWordQuery(array $words, array $search_data): mixed } // If this word is only wanted when within the phrase, remove its separate entry. - if (!in_array($word, $single_words)) { + if (!\in_array($word, $single_words)) { unset($found[$word]); } } @@ -409,11 +409,11 @@ public function indexedWordQuery(array $words, array $search_data): mixed foreach (array_keys($found) as $word) { $word = Utils::fixUtf8mb4(Utils::normalize(Utils::entityDecode($word, true), 'c')); - if (!in_array($word, $this->searchArray)) { + if (!\in_array($word, $this->searchArray)) { $this->searchArray[] = $word; $this->marked[$word] = '' . $word . ''; - if (!is_array($this->params['alt_forms'] ?? '')) { + if (!\is_array($this->params['alt_forms'] ?? '')) { $this->params['alt_forms'] = []; } @@ -612,7 +612,7 @@ public function getAdminSubactions(?string $type = null): array ], ]; - return is_null($type) ? $subactions : (isset($subactions[$type]) ? [$subactions[$type]] : []); + return \is_null($type) ? $subactions : (isset($subactions[$type]) ? [$subactions[$type]] : []); } /*********************** @@ -661,7 +661,7 @@ public static function build(int $start_id = 1): void if (SMF === 'BACKGROUND') { $instance = new self(); - $memory_limit = Sapi::memoryReturnBytes(ini_get('memory_limit')) * 0.8; + $memory_limit = Sapi::memoryReturnBytes(\ini_get('memory_limit')) * 0.8; $word_data = []; @@ -957,7 +957,7 @@ protected function save(array $word_data): void ); foreach ($msg_data as $msg => $wordnums) { - if (!is_array($wordnums)) { + if (!\is_array($wordnums)) { Db::$db->query( '', 'DELETE FROM {db_prefix}log_search_parsed @@ -1056,7 +1056,7 @@ protected function prepareString(string $string): string } // Remove HTML. - $string = strip_tags(is_string($string) ? preg_replace('/<[^>]+>/', '$0 ', $string) : ''); + $string = strip_tags(\is_string($string) ? preg_replace('/<[^>]+>/', '$0 ', $string) : ''); // Decode 4-byte Unicode characters. $string = mb_decode_numericentity($string, [0x010000, 0x10FFFF, 0, 0xFFFFFF], 'UTF-8'); @@ -1099,7 +1099,7 @@ function ($matches) { // emoji sequence. This can happen because the digits 0-9 and // the '*' and '#' characters are the base characters for the // "Emoji_Keycap_Sequence" emojis. - if (strlen($matches[0]) === 1) { + if (\strlen($matches[0]) === 1) { return $matches[0]; } @@ -1120,7 +1120,7 @@ function ($matches) { // Get rid of 'http', 'https', etc. if (isset($url_parts['scheme'])) { - $substitute = ltrim(substr($substitute, strlen($url_parts['scheme'])), ':/'); + $substitute = ltrim(substr($substitute, \strlen($url_parts['scheme'])), ':/'); } if (isset($url_parts['host'])) { @@ -1130,7 +1130,7 @@ function ($matches) { if (str_contains($trimmed_host, '.')) { $tld = substr($trimmed_host, strrpos($trimmed_host, '.') + 1); - if (in_array($tld, Url::$basic_tlds)) { + if (\in_array($tld, Url::$basic_tlds)) { $trimmed_host = substr($trimmed_host, 0, strrpos($trimmed_host, '.')); } } @@ -1157,7 +1157,7 @@ function ($matches) { if (str_contains($substitute, '.')) { $tld = substr($substitute, strrpos($substitute, '.') + 1); - if (in_array($tld, Url::$basic_tlds)) { + if (\in_array($tld, Url::$basic_tlds)) { $substitute = substr($substitute, 0, strrpos($substitute, '.')); } } diff --git a/Sources/Search/SearchApi.php b/Sources/Search/SearchApi.php index 1eac4d33bb..e3fda68496 100644 --- a/Sources/Search/SearchApi.php +++ b/Sources/Search/SearchApi.php @@ -496,7 +496,7 @@ public function postRemoved(int $id_msg): void $id_searchs[] = $row['id_search']; } - if (count($id_searchs) < 1) { + if (\count($id_searchs) < 1) { return; } @@ -711,7 +711,7 @@ public function setParticipants(): void [ 'current_member' => User::$me->id, 'topic_list' => array_keys($this->participants), - 'limit' => count($this->participants), + 'limit' => \count($this->participants), ], ); @@ -794,7 +794,7 @@ public function getAdminSubactions(): array */ public function getLabel(): string { - return 'search_index_' . strtolower(substr(strrchr(get_class($this), '\\'), 1)); + return 'search_index_' . strtolower(substr(strrchr(\get_class($this), '\\'), 1)); } /** @@ -802,7 +802,7 @@ public function getLabel(): string */ public function getDescription(): string { - return 'search_index_' . strtolower(substr(strrchr(get_class($this), '\\'), 1)) . '_desc'; + return 'search_index_' . strtolower(substr(strrchr(\get_class($this), '\\'), 1)) . '_desc'; } /*********************** @@ -1159,7 +1159,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, $this->blacklisted_words)) { + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !\in_array($word, $this->blacklisted_words)) { $this->excludedWords[] = $word; } @@ -1188,7 +1188,7 @@ protected function setSearchTerms(): void unset($this->searchArray[$index]); } // Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing. - elseif (in_array($this->searchArray[$index], $this->blacklisted_words)) { + elseif (\in_array($this->searchArray[$index], $this->blacklisted_words)) { $foundBlackListedWords = true; unset($this->searchArray[$index]); } @@ -1199,7 +1199,7 @@ protected function setSearchTerms(): void } } - $this->searchArray = array_slice(array_unique($this->searchArray), 0, 10); + $this->searchArray = \array_slice(array_unique($this->searchArray), 0, 10); foreach ($this->searchArray as $word) { $this->marked[$word] = '' . $word . ''; @@ -1252,13 +1252,13 @@ protected function setSearchTerms(): void } foreach ($orParts[$orIndex] as $word) { - $is_excluded = in_array($word, $this->excludedWords); + $is_excluded = \in_array($word, $this->excludedWords); $this->searchWords[$orIndex]['all_words'][] = $word; $subjectWords = Utils::extractWords($word, 2); - if (!$is_excluded || count($subjectWords) === 1) { + if (!$is_excluded || \count($subjectWords) === 1) { $this->searchWords[$orIndex]['subject_words'] = array_merge($this->searchWords[$orIndex]['subject_words'], $subjectWords); if ($is_excluded) { @@ -1286,9 +1286,9 @@ protected function setSearchTerms(): void } // Make sure we aren't searching for too many indexed words. - $this->searchWords[$orIndex]['indexed_words'] = array_slice($this->searchWords[$orIndex]['indexed_words'], 0, 7); - $this->searchWords[$orIndex]['subject_words'] = array_slice($this->searchWords[$orIndex]['subject_words'], 0, 7); - $this->searchWords[$orIndex]['words'] = array_slice($this->searchWords[$orIndex]['words'], 0, 4); + $this->searchWords[$orIndex]['indexed_words'] = \array_slice($this->searchWords[$orIndex]['indexed_words'], 0, 7); + $this->searchWords[$orIndex]['subject_words'] = \array_slice($this->searchWords[$orIndex]['subject_words'], 0, 7); + $this->searchWords[$orIndex]['words'] = \array_slice($this->searchWords[$orIndex]['words'], 0, 4); } } @@ -1357,10 +1357,10 @@ protected function setUserQuery(): void preg_match_all('~"([^"]+)"~', $userString, $matches); $possible_users = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $userString))); - for ($k = 0, $n = count($possible_users); $k < $n; $k++) { + for ($k = 0, $n = \count($possible_users); $k < $n; $k++) { $possible_users[$k] = trim($possible_users[$k]); - if (strlen($possible_users[$k]) == 0) { + if (\strlen($possible_users[$k]) == 0) { unset($possible_users[$k]); } } @@ -1429,12 +1429,12 @@ protected function setUserQuery(): void protected function setBoardQuery(): void { // If the boards were passed by URL (params=), temporarily put them back in $_REQUEST. - if (!empty($this->params['brd']) && is_array($this->params['brd'])) { + if (!empty($this->params['brd']) && \is_array($this->params['brd'])) { $_REQUEST['brd'] = $this->params['brd']; } // Ensure that brd is an array. - if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) { + if ((!empty($_REQUEST['brd']) && !\is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) { if (!empty($_REQUEST['brd'])) { $_REQUEST['brd'] = str_contains($_REQUEST['brd'], ',') ? explode(',', $_REQUEST['brd']) : [$_REQUEST['brd']]; } else { @@ -1509,7 +1509,7 @@ protected function setBoardQuery(): void } } - if (count($this->params['brd']) != 0) { + if (\count($this->params['brd']) != 0) { foreach ($this->params['brd'] as $k => $v) { $this->params['brd'][$k] = (int) $v; } @@ -1529,9 +1529,9 @@ protected function setBoardQuery(): void Db::$db->free_result($request); - if (count($this->params['brd']) == $num_boards) { + if (\count($this->params['brd']) == $num_boards) { $this->boardQuery = ''; - } elseif (count($this->params['brd']) == $num_boards - 1 && !empty(Config::$modSettings['recycle_board']) && !in_array(Config::$modSettings['recycle_board'], $this->params['brd'])) { + } elseif (\count($this->params['brd']) == $num_boards - 1 && !empty(Config::$modSettings['recycle_board']) && !\in_array(Config::$modSettings['recycle_board'], $this->params['brd'])) { $this->boardQuery = '!= ' . Config::$modSettings['recycle_board']; } else { $this->boardQuery = 'IN (' . implode(', ', $this->params['brd']) . ')'; @@ -1552,7 +1552,7 @@ protected function setSort(): void list($this->params['sort'], $this->params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); } - $this->params['sort'] = !empty($this->params['sort']) && in_array($this->params['sort'], $this->sort_columns) ? $this->params['sort'] : 'relevance'; + $this->params['sort'] = !empty($this->params['sort']) && \in_array($this->params['sort'], $this->sort_columns) ? $this->params['sort'] : 'relevance'; if (!empty($this->params['topic']) && $this->params['sort'] === 'num_replies') { $this->params['sort'] = 'id_msg'; @@ -1596,7 +1596,7 @@ protected function searchSubjectOnly(): void foreach ($words['subject_words'] as $subjectWord) { $numTables++; - if (in_array($subjectWord, $this->excludedSubjectWords)) { + if (\in_array($subjectWord, $this->excludedSubjectWords)) { $subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty(Config::$modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)'; $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; @@ -1713,7 +1713,7 @@ protected function searchSubjectOnly(): void } } Db::$db->free_result($ignoreRequest); - $numSubjectResults = count($inserts); + $numSubjectResults = \count($inserts); } else { $numSubjectResults += Db::$db->affected_rows(); } @@ -1864,7 +1864,7 @@ protected function searchSubjectAndMessage() foreach ($words['subject_words'] as $subjectWord) { $numTables++; - if (in_array($subjectWord, $this->excludedSubjectWords)) { + if (\in_array($subjectWord, $this->excludedSubjectWords)) { if (($subject_query['from'] != '{db_prefix}messages AS m') && !$excluded) { $subject_query['inner_join']['m'] = '{db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)'; $excluded = true; @@ -1983,7 +1983,7 @@ protected function searchSubjectAndMessage() } Db::$db->free_result($ignoreRequest); - $numSubjectResults = count($inserts); + $numSubjectResults = \count($inserts); } else { $numSubjectResults += Db::$db->affected_rows(); } @@ -2089,7 +2089,7 @@ protected function searchSubjectAndMessage() } Db::$db->free_result($ignoreRequest); - $indexedResults = count($inserts); + $indexedResults = \count($inserts); } else { $indexedResults += Db::$db->affected_rows(); } @@ -2137,7 +2137,7 @@ protected function searchSubjectAndMessage() $where = []; foreach ($words['all_words'] as $regularWord) { - if (in_array($regularWord, $this->excludedWords)) { + if (\in_array($regularWord, $this->excludedWords)) { $where[] = 'm.subject NOT ' . $this->query_match_type . ' {string:all_word_body_' . $count . '}'; $where[] = 'm.body NOT ' . $this->query_match_type . ' {string:all_word_body_' . $count . '}'; } else { @@ -2152,12 +2152,12 @@ protected function searchSubjectAndMessage() } if (!empty($where)) { - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; + $orWhere[] = \count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; } } if (!empty($orWhere)) { - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; + $main_query['where'][] = \count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; } if (!empty($this->userQuery)) { @@ -2261,7 +2261,7 @@ protected function searchSubjectAndMessage() ); } - $_SESSION['search_cache']['num_results'] += count($inserts); + $_SESSION['search_cache']['num_results'] += \count($inserts); } else { $_SESSION['search_cache']['num_results'] = Db::$db->affected_rows(); } @@ -2338,7 +2338,7 @@ protected function searchSubjectAndMessage() ); } - $_SESSION['search_cache']['num_results'] += count($inserts); + $_SESSION['search_cache']['num_results'] += \count($inserts); } else { $_SESSION['search_cache']['num_results'] += Db::$db->affected_rows(); } @@ -2349,7 +2349,7 @@ protected function searchSubjectAndMessage() } // Export properties to global namespace for backward compatibility. -if (is_callable([SearchApi::class, 'exportStatic'])) { +if (\is_callable([SearchApi::class, 'exportStatic'])) { SearchApi::exportStatic(); } diff --git a/Sources/Search/SearchResult.php b/Sources/Search/SearchResult.php index 3a5959bb91..e2a327a2c5 100644 --- a/Sources/Search/SearchResult.php +++ b/Sources/Search/SearchResult.php @@ -297,7 +297,7 @@ public function format(int $counter = 0, array $format_options = []): array } // Do we have quote tag enabled? - $quote_enabled = empty(Config::$modSettings['disabledBBC']) || !in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); + $quote_enabled = empty(Config::$modSettings['disabledBBC']) || !\in_array('quote', explode(',', Config::$modSettings['disabledBBC'])); // Reference the main color class. $colorClass = 'windowbg'; @@ -321,8 +321,8 @@ public function format(int $counter = 0, array $format_options = []): array 'posted_in' => !empty(SearchApi::$loadedApi->participants[$this->id_topic]), 'views' => $this->num_views, 'replies' => $this->num_replies, - 'can_reply' => in_array($this->id_board, self::$boards_can['post_reply_any']) || in_array(0, self::$boards_can['post_reply_any']), - 'can_quote' => (in_array($this->id_board, self::$boards_can['post_reply_any']) || in_array(0, self::$boards_can['post_reply_any'])) && $quote_enabled, + 'can_reply' => \in_array($this->id_board, self::$boards_can['post_reply_any']) || \in_array(0, self::$boards_can['post_reply_any']), + 'can_quote' => (\in_array($this->id_board, self::$boards_can['post_reply_any']) || \in_array(0, self::$boards_can['post_reply_any'])) && $quote_enabled, 'first_post' => [ 'id' => $this->first_msg, 'time' => Time::create('@' . $this->first_poster_time)->format(), @@ -464,7 +464,7 @@ public static function get(int|array $ids, array $query_customizations = []): \G 'is_approved' => 1, 'current_member' => User::$me->id, 'approve_boards' => !empty(Config::$modSettings['postmod_active']) ? User::$me->mod_cache['ap'] : [], - 'limit' => count($ids), + 'limit' => \count($ids), ]; if (!empty($ids)) { @@ -501,7 +501,7 @@ public static function highlight(string $text, array $words): string // Don't mess with the content of HTML tags. $parts = preg_split('~(<[^>]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); - for ($i = 0, $n = count($parts); $i < $n; $i++) { + for ($i = 0, $n = \count($parts); $i < $n; $i++) { $highlighted .= $i % 2 === 0 ? preg_replace('~' . $words . '~iu', '$0', $parts[$i]) : $parts[$i]; } @@ -539,11 +539,11 @@ public static function setBoardsCan(): void // How's about some quick moderation? if (!empty(Theme::$current->options['display_quick_mod'])) { - Utils::$context['can_lock'] = in_array(0, self::$boards_can['lock_any']); - Utils::$context['can_sticky'] = in_array(0, self::$boards_can['make_sticky']); - Utils::$context['can_move'] = in_array(0, self::$boards_can['move_any']); - Utils::$context['can_remove'] = in_array(0, self::$boards_can['remove_any']); - Utils::$context['can_merge'] = in_array(0, self::$boards_can['merge_any']); + Utils::$context['can_lock'] = \in_array(0, self::$boards_can['lock_any']); + Utils::$context['can_sticky'] = \in_array(0, self::$boards_can['make_sticky']); + Utils::$context['can_move'] = \in_array(0, self::$boards_can['move_any']); + Utils::$context['can_remove'] = \in_array(0, self::$boards_can['remove_any']); + Utils::$context['can_merge'] = \in_array(0, self::$boards_can['merge_any']); } } } diff --git a/Sources/Security.php b/Sources/Security.php index 05ef7c1889..03a62aef6d 100644 --- a/Sources/Security.php +++ b/Sources/Security.php @@ -126,7 +126,7 @@ public static function checkSubmitOnce(string $action, bool $is_fatal = true): ? return true; } - if (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { + if (!\in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; return true; @@ -144,12 +144,12 @@ public static function checkSubmitOnce(string $action, bool $is_fatal = true): ? if ($action == 'register') { Utils::$context['form_sequence_number'] = 0; - while (empty(Utils::$context['form_sequence_number']) || in_array(Utils::$context['form_sequence_number'], $_SESSION['forms'])) { + while (empty(Utils::$context['form_sequence_number']) || \in_array(Utils::$context['form_sequence_number'], $_SESSION['forms'])) { Utils::$context['form_sequence_number'] = random_int(1, 16000000); } } // Don't check, just free the stack number. - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && \in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { $_SESSION['forms'] = array_diff($_SESSION['forms'], [$_REQUEST['seqnum']]); } // Bail out if $action is unknown. @@ -345,9 +345,9 @@ public static function frameOptionsHeader(?string $override = null): void { $option = 'SAMEORIGIN'; - if (is_null($override) && !empty(Config::$modSettings['frame_security'])) { + if (\is_null($override) && !empty(Config::$modSettings['frame_security'])) { $option = Config::$modSettings['frame_security']; - } elseif (in_array($override, ['SAMEORIGIN', 'DENY'])) { + } elseif (\in_array($override, ['SAMEORIGIN', 'DENY'])) { $option = $override; } diff --git a/Sources/ServerSideIncludes.php b/Sources/ServerSideIncludes.php index 2f47b48e39..1299656411 100644 --- a/Sources/ServerSideIncludes.php +++ b/Sources/ServerSideIncludes.php @@ -383,12 +383,12 @@ public static function recentPosts(int $num_recent = 8, ?array $exclude_boards = if ($exclude_boards === null && !empty(Config::$modSettings['recycle_enable']) && !empty(Config::$modSettings['recycle_board'])) { $exclude_boards = [Config::$modSettings['recycle_board']]; } else { - $exclude_boards = empty($exclude_boards) ? [] : (is_array($exclude_boards) ? $exclude_boards : [$exclude_boards]); + $exclude_boards = empty($exclude_boards) ? [] : (\is_array($exclude_boards) ? $exclude_boards : [$exclude_boards]); } // What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter. - if (is_array($include_boards) || (int) $include_boards === $include_boards) { - $include_boards = is_array($include_boards) ? $include_boards : [$include_boards]; + if (\is_array($include_boards) || (int) $include_boards === $include_boards) { + $include_boards = \is_array($include_boards) ? $include_boards : [$include_boards]; } elseif ($include_boards != null) { $include_boards = []; } @@ -435,7 +435,7 @@ public static function fetchPosts(array $post_ids = [], bool $override_permissio } // Allow the user to request more than one - why not? - $post_ids = is_array($post_ids) ? $post_ids : [$post_ids]; + $post_ids = \is_array($post_ids) ? $post_ids : [$post_ids]; // Restrict the posts required... $query_where = ' @@ -563,7 +563,7 @@ public static function queryPosts( if (!empty(Config::$modSettings['enable_likes'])) { $posts[$row['id_msg']]['likes'] = [ 'count' => $row['likes'], - 'you' => in_array($row['id_msg'], $topic->getLikedMsgs()), + 'you' => \in_array($row['id_msg'], $topic->getLikedMsgs()), 'can_like' => !User::$me->is_guest && $row['id_member'] != User::$me->id && !empty(Utils::$context['can_like']), ]; } @@ -623,12 +623,12 @@ public static function recentTopics(int $num_recent = 8, ?array $exclude_boards if ($exclude_boards === null && !empty(Config::$modSettings['recycle_enable']) && Config::$modSettings['recycle_board'] > 0) { $exclude_boards = [Config::$modSettings['recycle_board']]; } else { - $exclude_boards = empty($exclude_boards) ? [] : (is_array($exclude_boards) ? $exclude_boards : [$exclude_boards]); + $exclude_boards = empty($exclude_boards) ? [] : (\is_array($exclude_boards) ? $exclude_boards : [$exclude_boards]); } // Only some boards?. - if (is_array($include_boards) || (int) $include_boards === $include_boards) { - $include_boards = is_array($include_boards) ? $include_boards : [$include_boards]; + if (\is_array($include_boards) || (int) $include_boards === $include_boards) { + $include_boards = \is_array($include_boards) ? $include_boards : [$include_boards]; } elseif ($include_boards != null) { $output_method = $include_boards; $include_boards = []; @@ -1168,7 +1168,7 @@ public static function fetchMember(array $member_ids = [], string $output_method } // Can have more than one member if you really want... - $member_ids = is_array($member_ids) ? $member_ids : [$member_ids]; + $member_ids = \is_array($member_ids) ? $member_ids : [$member_ids]; // Restrict it right! $query_where = ' @@ -1764,7 +1764,7 @@ public static function pollVote(): void } // Too many options checked? - if (count($_REQUEST['options']) > $row['max_votes']) { + if (\count($_REQUEST['options']) > $row['max_votes']) { Utils::redirectexit('topic=' . $row['id_topic'] . '.0'); } @@ -1775,7 +1775,7 @@ public static function pollVote(): void Utils::redirectexit('topic=' . $row['id_topic'] . '.0'); } // Already voted? - elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) { + elseif (isset($_COOKIE['guest_poll_vote']) && \in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) { Utils::redirectexit('topic=' . $row['id_topic'] . '.0'); } } @@ -1865,7 +1865,7 @@ public static function news(string $output_method = 'echo'): ?string new self(); } - Utils::$context['random_news_line'] = !empty(Utils::$context['news_lines']) ? Utils::$context['news_lines'][mt_rand(0, count(Utils::$context['news_lines']) - 1)] : ''; + Utils::$context['random_news_line'] = !empty(Utils::$context['news_lines']) ? Utils::$context['news_lines'][mt_rand(0, \count(Utils::$context['news_lines']) - 1)] : ''; // If mods want to do something with the news, let them do that now. Don't need to pass the news line itself, since it is already in Utils::$context. IntegrationHook::call('integrate_ssi_news'); @@ -1988,7 +1988,7 @@ public static function todaysEvents(string $output_method = 'echo'): ?array return (array) $return['calendar_events']; } - if (!is_array($return)) { + if (!\is_array($return)) { return null; } @@ -2195,7 +2195,7 @@ public static function boardNews(?int $board = null, ?int $limit = null, ?int $s LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) WHERE t.id_first_msg IN ({array_int:post_list}) ORDER BY t.id_first_msg DESC - LIMIT ' . count($posts), + LIMIT ' . \count($posts), [ 'post_list' => $posts, ], @@ -2280,7 +2280,7 @@ public static function boardNews(?int $board = null, ?int $limit = null, ?int $s // Nasty ternary for likes not messing around the "is_last" check. 'likes' => !empty(Config::$modSettings['enable_likes']) ? [ 'count' => $row['likes'], - 'you' => in_array($row['id_msg'], $topic->getLikedMsgs()), + 'you' => \in_array($row['id_msg'], $topic->getLikedMsgs()), 'can_like' => !User::$me->is_guest && $row['id_member'] != User::$me->id && !empty(Utils::$context['can_like']), ] : [], ]; @@ -2291,7 +2291,7 @@ public static function boardNews(?int $board = null, ?int $limit = null, ?int $s return $return; } - $return[count($return) - 1]['is_last'] = true; + $return[\count($return) - 1]['is_last'] = true; // If mods want to do something with this list of posts, let them do that now. IntegrationHook::call('integrate_ssi_boardNews', [&$return]); @@ -2414,7 +2414,7 @@ public static function recentEvents(int $max_events = 7, string $output_method = $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; } - $allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(\DateTimeZone::ALL_WITH_BC))) ? true : false; + $allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !\in_array($row['timezone'], timezone_identifiers_list(\DateTimeZone::ALL_WITH_BC))) ? true : false; $return[$date][] = [ 'id' => $row['id_event'], @@ -2439,7 +2439,7 @@ public static function recentEvents(int $max_events = 7, string $output_method = Db::$db->free_result($request); foreach ($return as $mday => $array) { - $return[$mday][count($array) - 1]['is_last'] = true; + $return[$mday][\count($array) - 1]['is_last'] = true; } // If mods want to do something with this list of events, let them do that now. @@ -2658,7 +2658,7 @@ public function __construct() { // SSI isn't meant to be used from within the forum, // but apparently someone is doing so anyway... - if (defined('SMF') && SMF !== 'SSI') { + if (\defined('SMF') && SMF !== 'SSI') { if (!self::$setup_done) { IntegrationHook::call('integrate_SSI'); } @@ -2729,7 +2729,7 @@ public function __construct() } // Gzip output? (because it must be boolean and true, this can't be hacked.) - if ($this->gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) { + if ($this->gzip === true && \ini_get('zlib.output_compression') != '1' && \ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) { ob_start('ob_gzhandler'); } else { Config::$modSettings['enableCompressedOutput'] = '0'; @@ -2830,7 +2830,7 @@ public function execute(): bool // Call a function passed by GET. if (method_exists(__CLASS__, $_GET['ssi_function']) && (!empty(Config::$modSettings['allow_guestAccess']) || !User::$me->is_guest)) { - call_user_func([__CLASS__, $_GET['ssi_function']]); + \call_user_func([__CLASS__, $_GET['ssi_function']]); } exit; diff --git a/Sources/Session.php b/Sources/Session.php index 4105af959e..a4549f80b3 100644 --- a/Sources/Session.php +++ b/Sources/Session.php @@ -207,9 +207,9 @@ public static function load(): void // @todo Set the session cookie path? // If it's already been started... probably best to skip this. - if ((ini_get('session.auto_start') == 1 && !empty(Config::$modSettings['databaseSession_enable'])) || session_id() == '') { + if ((\ini_get('session.auto_start') == 1 && !empty(Config::$modSettings['databaseSession_enable'])) || session_id() == '') { // Attempt to end the already-started session. - if (ini_get('session.auto_start') == 1) { + if (\ini_get('session.auto_start') == 1) { session_write_close(); } @@ -225,14 +225,14 @@ public static function load(): void if (!empty(Config::$modSettings['databaseSession_enable'])) { @ini_set('session.serialize_handler', 'php_serialize'); - if (ini_get('session.serialize_handler') != 'php_serialize') { + if (\ini_get('session.serialize_handler') != 'php_serialize') { @ini_set('session.serialize_handler', 'php'); } session_set_save_handler(new self(), true); @ini_set('session.gc_probability', '1'); - } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty(Config::$modSettings['databaseSession_lifetime'])) { + } elseif (\ini_get('session.gc_maxlifetime') <= 1440 && !empty(Config::$modSettings['databaseSession_lifetime'])) { @ini_set('session.gc_maxlifetime', max(Config::$modSettings['databaseSession_lifetime'], 60)); } diff --git a/Sources/Subscriptions/PayPal/Payment.php b/Sources/Subscriptions/PayPal/Payment.php index cec7bc344b..3755392da8 100644 --- a/Sources/Subscriptions/PayPal/Payment.php +++ b/Sources/Subscriptions/PayPal/Payment.php @@ -52,11 +52,11 @@ public function isValid(): bool } // Are we testing? - if (!empty(Config::$modSettings['paidsubs_test']) && strtolower(Config::$modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty(Config::$modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower(Config::$modSettings['paypal_additional_emails']))))) { + if (!empty(Config::$modSettings['paidsubs_test']) && strtolower(Config::$modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty(Config::$modSettings['paypal_additional_emails']) || !\in_array(strtolower($_POST['business']), explode(',', strtolower(Config::$modSettings['paypal_additional_emails']))))) { return false; } - return !(strtolower(Config::$modSettings['paypal_email']) != strtolower($_POST['business']) && (empty(Config::$modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', Config::$modSettings['paypal_additional_emails'])))); + return !(strtolower(Config::$modSettings['paypal_email']) != strtolower($_POST['business']) && (empty(Config::$modSettings['paypal_additional_emails']) || !\in_array(strtolower($_POST['business']), explode(',', Config::$modSettings['paypal_additional_emails'])))); } /** @@ -85,7 +85,7 @@ public function precheck(): string } // Can we use curl? - if (function_exists('curl_init') && $curl = curl_init((!empty(Config::$modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr')) { + if (\function_exists('curl_init') && $curl = curl_init((!empty(Config::$modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr')) { // Set the post data. curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $requestString); @@ -115,7 +115,7 @@ public function precheck(): string $header = 'POST /cgi-bin/webscr HTTP/1.1' . "\r\n"; $header .= 'content-type: application/x-www-form-urlencoded' . "\r\n"; $header .= 'Host: www.' . (!empty(Config::$modSettings['paidsubs_test']) ? 'sandbox.' : '') . 'paypal.com' . "\r\n"; - $header .= 'content-length: ' . strlen($requestString) . "\r\n"; + $header .= 'content-length: ' . \strlen($requestString) . "\r\n"; $header .= 'connection: close' . "\r\n\r\n"; // Open the connection. @@ -152,7 +152,7 @@ public function precheck(): string } // Check that this is intended for us. - if (strtolower(Config::$modSettings['paypal_email']) != strtolower($_POST['business']) && (empty(Config::$modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower(Config::$modSettings['paypal_additional_emails']))))) { + if (strtolower(Config::$modSettings['paypal_email']) != strtolower($_POST['business']) && (empty(Config::$modSettings['paypal_additional_emails']) || !\in_array(strtolower($_POST['business']), explode(',', strtolower(Config::$modSettings['paypal_additional_emails']))))) { exit; } diff --git a/Sources/TOTP/Auth.php b/Sources/TOTP/Auth.php index caca92cae6..ad6442aeec 100644 --- a/Sources/TOTP/Auth.php +++ b/Sources/TOTP/Auth.php @@ -146,7 +146,7 @@ public function getInitKey(): string */ public function setLookup(array $lookup): self { - if (!is_array($lookup)) { + if (!\is_array($lookup)) { throw new \InvalidArgumentException('Lookup value must be an array'); } $this->lookup = $lookup; @@ -226,7 +226,7 @@ public function setCodeLength(int $length): self */ public function validateCode(string $code, ?string $initKey = null, ?string $timestamp = null, ?string $range = null): bool { - if (strlen($code) !== $this->getCodeLength()) { + if (\strlen($code) !== $this->getCodeLength()) { throw new \InvalidArgumentException('Incorrect code length'); } @@ -280,7 +280,7 @@ public function generateCode(int $length = 16): string $code = ''; for ($i = 0; $i < $length; $i++) { - $code .= $lookup[random_int(0, strlen($lookup) - 1)]; + $code .= $lookup[random_int(0, \strlen($lookup) - 1)]; } return $code; @@ -304,13 +304,13 @@ public function generateTimestamp(): int */ public function truncateHash(string $hash): string { - $offset = ord($hash[19]) & 0xf; + $offset = \ord($hash[19]) & 0xf; return (string) (( - ((ord($hash[$offset + 0]) & 0x7f) << 24) | - ((ord($hash[$offset + 1]) & 0xff) << 16) | - ((ord($hash[$offset + 2]) & 0xff) << 8) | - (ord($hash[$offset + 3]) & 0xff) + ((\ord($hash[$offset + 0]) & 0x7f) << 24) | + ((\ord($hash[$offset + 1]) & 0xff) << 16) | + ((\ord($hash[$offset + 2]) & 0xff) << 8) | + (\ord($hash[$offset + 3]) & 0xff) ) % pow(10, $this->getCodeLength())); } @@ -334,14 +334,14 @@ public function base32_decode(string $hash): string $length = 0; $binary = ''; - for ($i = 0; $i < strlen($hash); $i++) { + for ($i = 0; $i < \strlen($hash); $i++) { $buffer = $buffer << 5; $buffer += $lookup[$hash[$i]]; $length += 5; if ($length >= 8) { $length -= 8; - $binary .= chr(($buffer & (0xFF << $length)) >> $length); + $binary .= \chr(($buffer & (0xFF << $length)) >> $length); } } diff --git a/Sources/TaskRunner.php b/Sources/TaskRunner.php index 350086f833..1ad445fcdc 100644 --- a/Sources/TaskRunner.php +++ b/Sources/TaskRunner.php @@ -119,17 +119,17 @@ class TaskRunner public function __construct() { // For backward compatibility. - if (!defined('MAX_CRON_TIME')) { - define('MAX_CRON_TIME', self::MAX_CRON_TIME); + if (!\defined('MAX_CRON_TIME')) { + \define('MAX_CRON_TIME', self::MAX_CRON_TIME); } - if (!defined('MAX_CLAIM_THRESHOLD')) { - define('MAX_CLAIM_THRESHOLD', self::MAX_CLAIM_THRESHOLD); + if (!\defined('MAX_CLAIM_THRESHOLD')) { + \define('MAX_CLAIM_THRESHOLD', self::MAX_CLAIM_THRESHOLD); } // Called from cron.php. if (SMF === 'BACKGROUND') { - define('FROM_CLI', Sapi::isCLI()); + \define('FROM_CLI', Sapi::isCLI()); // Don't do john didley if the forum's been shut down completely. if (!empty(Config::$maintenance) && 2 === Config::$maintenance) { @@ -302,7 +302,7 @@ public function runScheduledTasks(array $tasks): void [ 'task_ids' => $task_ids, 'task_names' => $task_names, - 'limit' => count($task_ids) + count($task_names), + 'limit' => \count($task_ids) + \count($task_names), ], ); diff --git a/Sources/Tasks/CreatePost_Notify.php b/Sources/Tasks/CreatePost_Notify.php index e753fe667e..22b2cb7d2f 100644 --- a/Sources/Tasks/CreatePost_Notify.php +++ b/Sources/Tasks/CreatePost_Notify.php @@ -462,7 +462,7 @@ protected function handleWatchedNotifications(): void $user_ids = array_keys($this->members['watching']); - if (!in_array($posterOptions['id'], $user_ids)) { + if (!\in_array($posterOptions['id'], $user_ids)) { $user_ids[] = $posterOptions['id']; } User::load($user_ids, User::LOAD_BY_ID, 'minimal'); @@ -470,7 +470,7 @@ protected function handleWatchedNotifications(): void $parsed_message = []; foreach ($this->members['watching'] as $member_id => $member_data) { - if (in_array($member_id, $this->members['done'])) { + if (\in_array($member_id, $this->members['done'])) { continue; } @@ -479,17 +479,17 @@ protected function handleWatchedNotifications(): void // Don't send a notification if: // 1. The watching member ignored the member who did the action. - if (!empty($member_data['pm_ignore_list']) && in_array($member_data['id_member_updated'], explode(',', $member_data['pm_ignore_list']))) { + if (!empty($member_data['pm_ignore_list']) && \in_array($member_data['id_member_updated'], explode(',', $member_data['pm_ignore_list']))) { continue; } // 2. The watching member is not interested in moderation on this topic. - if (!in_array($type, ['reply', 'topic']) && ($notify_types == self::NOTIFY_TYPE_ONLY_REPLIES || ($notify_types == self::NOTIFY_TYPE_REPLIES_AND_OWN_TOPIC_MODERATION && $member_id != $member_data['id_member_started']))) { + if (!\in_array($type, ['reply', 'topic']) && ($notify_types == self::NOTIFY_TYPE_ONLY_REPLIES || ($notify_types == self::NOTIFY_TYPE_REPLIES_AND_OWN_TOPIC_MODERATION && $member_id != $member_data['id_member_started']))) { continue; } // 3. This is the watching member's own post. - if (in_array($type, ['reply', 'topic']) && $member_id == $posterOptions['id']) { + if (\in_array($type, ['reply', 'topic']) && $member_id == $posterOptions['id']) { continue; } @@ -499,7 +499,7 @@ protected function handleWatchedNotifications(): void } // 5. The watching member doesn't want notifications until later. - if (in_array($frequency, [ + if (\in_array($frequency, [ self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST])) { @@ -512,7 +512,7 @@ protected function handleWatchedNotifications(): void } // 7. The watching member isn't on club security's VIP list. - if (!empty($this->_details['members_only']) && !in_array($member_id, $this->_details['members_only'])) { + if (!empty($this->_details['members_only']) && !\in_array($member_id, $this->_details['members_only'])) { continue; } @@ -578,8 +578,8 @@ protected function handleWatchedNotifications(): void 'alert_time' => time(), 'id_member' => (int) $member_id, // Only tell sender's information for new topics and replies - 'id_member_started' => in_array($type, ['topic', 'reply']) ? (int) $posterOptions['id'] : 0, - 'member_name' => in_array($type, ['topic', 'reply']) ? $posterOptions['name'] : '', + 'id_member_started' => \in_array($type, ['topic', 'reply']) ? (int) $posterOptions['id'] : 0, + 'member_name' => \in_array($type, ['topic', 'reply']) ? $posterOptions['name'] : '', 'content_type' => $content_type, 'content_id' => (int) $topicOptions['id'], 'content_action' => $type, @@ -588,7 +588,7 @@ protected function handleWatchedNotifications(): void 'topic' => (int) $topicOptions['id'], 'board' => (int) $topicOptions['board'], 'content_subject' => $parsed_message[$localization]['subject'], - 'content_link' => Config::$scripturl . '?topic=' . $topicOptions['id'] . (in_array($type, ['reply', 'topic']) ? '.new;topicseen#new' : '.0'), + 'content_link' => Config::$scripturl . '?topic=' . $topicOptions['id'] . (\in_array($type, ['reply', 'topic']) ? '.new;topicseen#new' : '.0'), ]), ]; } @@ -630,7 +630,7 @@ protected function handleQuoteNotifications(): void User::load($posterOptions['id'], User::LOAD_BY_ID, 'minimal'); foreach ($this->members['quoted'] as $member_id => $member_data) { - if (in_array($member_id, $this->members['done'])) { + if (\in_array($member_id, $this->members['done'])) { continue; } @@ -667,7 +667,7 @@ protected function handleQuoteNotifications(): void if (!($pref & self::RECEIVE_NOTIFY_EMAIL)) { // Don't want an email, so forget this member in any respawned tasks. unset($msgOptions['quoted_members'][$member_id]); - } elseif (TIME_START >= $this->mention_mail_time || in_array($member_id, $this->members['watching'])) { + } elseif (TIME_START >= $this->mention_mail_time || \in_array($member_id, $this->members['watching'])) { $replacements = [ 'CONTENTSUBJECT' => $msgOptions['subject'], 'QUOTENAME' => Utils::htmlspecialcharsDecode(User::$loaded[$posterOptions['id']]->name ?? $posterOptions['name']), @@ -699,7 +699,7 @@ protected function handleMentionedNotifications(): void $msgOptions = &$this->_details['msgOptions']; foreach ($this->members['mentioned'] as $member_id => $member_data) { - if (in_array($member_id, $this->members['done'])) { + if (\in_array($member_id, $this->members['done'])) { continue; } @@ -736,7 +736,7 @@ protected function handleMentionedNotifications(): void if (!($pref & self::RECEIVE_NOTIFY_EMAIL)) { // Don't want an email, so forget this member in any respawned tasks. unset($msgOptions['mentioned_members'][$member_id]); - } elseif (TIME_START >= $this->mention_mail_time || in_array($member_id, $this->members['watching'])) { + } elseif (TIME_START >= $this->mention_mail_time || \in_array($member_id, $this->members['watching'])) { $replacements = [ 'CONTENTSUBJECT' => $msgOptions['subject'], 'MENTIONNAME' => $member_data['mentioned_by']['name'], diff --git a/Sources/Tasks/DailyMaintenance.php b/Sources/Tasks/DailyMaintenance.php index 84810c559a..6113d8203f 100644 --- a/Sources/Tasks/DailyMaintenance.php +++ b/Sources/Tasks/DailyMaintenance.php @@ -135,7 +135,7 @@ public function execute(): bool $export_files = glob(rtrim(Config::$modSettings['export_dir'], '/\\') . DIRECTORY_SEPARATOR . '*'); foreach ($export_files as $export_file) { - if (!in_array(basename($export_file), ['index.php', '.htaccess']) && filemtime($export_file) <= $expiry_date) { + if (!\in_array(basename($export_file), ['index.php', '.htaccess']) && filemtime($export_file) <= $expiry_date) { @unlink($export_file); } } diff --git a/Sources/Tasks/ExportProfileData.php b/Sources/Tasks/ExportProfileData.php index 35ec7b2b7f..0d1f136f23 100644 --- a/Sources/Tasks/ExportProfileData.php +++ b/Sources/Tasks/ExportProfileData.php @@ -880,14 +880,14 @@ class ExportProfileData extends BackgroundTask */ public function execute(): bool { - if (!defined('EXPORTING')) { - define('EXPORTING', 1); + if (!\defined('EXPORTING')) { + \define('EXPORTING', 1); } // Avoid leaving files in an inconsistent state. ignore_user_abort(true); - $this->time_limit = (int) ((ini_get('safe_mode') === false && @set_time_limit(Taskrunner::MAX_CLAIM_THRESHOLD) !== false) ? Taskrunner::MAX_CLAIM_THRESHOLD : (int) ini_get('max_execution_time')); + $this->time_limit = (int) ((\ini_get('safe_mode') === false && @set_time_limit(Taskrunner::MAX_CLAIM_THRESHOLD) !== false) ? Taskrunner::MAX_CLAIM_THRESHOLD : (int) \ini_get('max_execution_time')); // This could happen if the user manually changed the URL params of the export request. if ($this->_details['format'] == 'HTML' && (!class_exists('DOMDocument') || !class_exists('XSLTProcessor'))) { @@ -912,7 +912,7 @@ public function execute(): bool // Use some temporary integration hooks to manipulate BBC parsing during export. $hook_methods = [ - 'pre_parsebbc' => in_array($this->_details['format'], ['HTML', 'XML_XSLT']) ? 'pre_parsebbc_html' : 'pre_parsebbc_xml', + 'pre_parsebbc' => \in_array($this->_details['format'], ['HTML', 'XML_XSLT']) ? 'pre_parsebbc_html' : 'pre_parsebbc_xml', 'post_parsebbc' => 'post_parsebbc', 'bbc_codes' => 'bbc_codes', 'post_parseAttachBBC' => 'post_parseAttachBBC', @@ -1027,7 +1027,7 @@ function ($datatype) { ]; // Some paranoid hosts disable or hamstring the disk space functions in an attempt at security via obscurity. - $check_diskspace = !empty(Config::$modSettings['export_min_diskspace_pct']) && function_exists('disk_free_space') && function_exists('disk_total_space') && intval(@disk_total_space(Config::$modSettings['export_dir']) >= 1440); + $check_diskspace = !empty(Config::$modSettings['export_min_diskspace_pct']) && \function_exists('disk_free_space') && \function_exists('disk_total_space') && \intval(@disk_total_space(Config::$modSettings['export_dir']) >= 1440); $minspace = $check_diskspace ? ceil(disk_total_space(Config::$modSettings['export_dir']) * Config::$modSettings['export_min_diskspace_pct'] / 100) : 0; // If a necessary file is missing, we need to start over. @@ -1049,7 +1049,7 @@ function ($datatype) { } // Get the data. - $xml_data = call_user_func([$feed, $included[$datatype]['func']]); + $xml_data = \call_user_func([$feed, $included[$datatype]['func']]); // No data retrieved? Just move on then. if (empty($xml_data)) { @@ -1074,7 +1074,7 @@ function ($datatype) { $profile_basic_items = CacheApi::get('export_profile_basic-' . $uid, Taskrunner::MAX_CLAIM_THRESHOLD); if (empty($profile_basic_items)) { - $profile_data = call_user_func([$feed, $included['profile']['func']]); + $profile_data = \call_user_func([$feed, $included['profile']['func']]); Feed::build('smf', $profile_data, $feed->metadata, 'profile'); @@ -1127,7 +1127,7 @@ function ($datatype) { Feed::build('smf', $items, $feed->metadata, 'profile'); // If disk space is insufficient, pause for a day so the admin can fix it. - if ($check_diskspace && disk_free_space(Config::$modSettings['export_dir']) - $minspace <= strlen(implode('', Utils::$context['feed']) . ($this->stylesheet ?? ''))) { + if ($check_diskspace && disk_free_space(Config::$modSettings['export_dir']) - $minspace <= \strlen(implode('', Utils::$context['feed']) . ($this->stylesheet ?? ''))) { Lang::load('Errors'); ErrorHandler::log(Lang::getTxt('export_low_diskspace', [Config::$modSettings['export_min_diskspace_pct']])); @@ -1142,15 +1142,15 @@ function ($datatype) { // Insert the new data before the feed footer. $handle = fopen($tempfile, 'r+'); - if (is_resource($handle)) { + if (\is_resource($handle)) { flock($handle, LOCK_EX); - fseek($handle, strlen(Utils::$context['feed']['footer']) * -1, SEEK_END); + fseek($handle, \strlen(Utils::$context['feed']['footer']) * -1, SEEK_END); $bytes_written = fwrite($handle, Utils::$context['feed']['items'] . Utils::$context['feed']['footer']); // If we couldn't write everything, revert the changes and consider the write to have failed. - if ($bytes_written > 0 && $bytes_written < strlen(Utils::$context['feed']['items'] . Utils::$context['feed']['footer'])) { + if ($bytes_written > 0 && $bytes_written < \strlen(Utils::$context['feed']['items'] . Utils::$context['feed']['footer'])) { fseek($handle, $bytes_written * -1, SEEK_END); $pointer_pos = ftell($handle); ftruncate($handle, $pointer_pos); @@ -1177,12 +1177,12 @@ function ($datatype) { file_put_contents($progressfile, Utils::jsonEncode($progress)); // Are we done with this datatype yet? - if (!isset($last_id) || (count($items) < $per_page && $last_id >= $latest[$datatype])) { + if (!isset($last_id) || (\count($items) < $per_page && $last_id >= $latest[$datatype])) { $datatype_done = true; } // Finished the file for this chunk, so move on to the next one. - if (count($items) >= $per_page - $prev_item_count) { + if (\count($items) >= $per_page - $prev_item_count) { rename($tempfile, $realfile); $realfile = $export_dir_slash . ++$filenum . '_' . $idhash_ext; $prev_item_count = $new_item_count = 0; @@ -1190,7 +1190,7 @@ function ($datatype) { // This was the last chunk. else { // Should we append more items to this file next time? - $new_item_count = isset($last_id) ? $prev_item_count + count($items) : 0; + $new_item_count = isset($last_id) ? $prev_item_count + \count($items) : 0; } } } @@ -1291,14 +1291,14 @@ protected function exportHtml(): void $libxml_options = 0; foreach (['LIBXML_COMPACT', 'LIBXML_PARSEHUGE', 'LIBXML_BIGLINES'] as $libxml_option) { - if (defined($libxml_option)) { - $libxml_options = $libxml_options | constant($libxml_option); + if (\defined($libxml_option)) { + $libxml_options = $libxml_options | \constant($libxml_option); } } // Transform the files to HTML. $i = 0; - $num_files = count($new_exportfiles); + $num_files = \count($new_exportfiles); $max_transform_time = 0; $xmldoc = new DOMDocument(); @@ -1361,7 +1361,7 @@ protected function exportXmlXslt(): void $idhash = hash_hmac('sha1', (string) $this->_details['uid'], Config::getAuthSecret()); $idhash_ext = $idhash . '.' . $this->_details['format_settings']['extension']; - $test_length = strlen($this->stylesheet . Utils::$context['feed']['footer']); + $test_length = \strlen($this->stylesheet . Utils::$context['feed']['footer']); $new_exportfiles = []; @@ -1381,15 +1381,15 @@ protected function exportXmlXslt(): void foreach ($new_exportfiles as $exportfile) { $handle = fopen($exportfile, 'r+'); - if (is_resource($handle)) { + if (\is_resource($handle)) { flock($handle, LOCK_EX); - fseek($handle, strlen(Utils::$context['feed']['footer']) * -1, SEEK_END); + fseek($handle, \strlen(Utils::$context['feed']['footer']) * -1, SEEK_END); $bytes_written = fwrite($handle, $this->stylesheet . Utils::$context['feed']['footer']); // If we couldn't write everything, revert the changes. - if ($bytes_written > 0 && $bytes_written < strlen($this->stylesheet . Utils::$context['feed']['footer'])) { + if ($bytes_written > 0 && $bytes_written < \strlen($this->stylesheet . Utils::$context['feed']['footer'])) { fseek($handle, $bytes_written * -1, SEEK_END); $pointer_pos = ftell($handle); ftruncate($handle, $pointer_pos); @@ -1412,7 +1412,7 @@ protected function buildStylesheet(): void { $xslt_variables = []; - if (in_array($this->_details['format'], ['HTML', 'XML_XSLT'])) { + if (\in_array($this->_details['format'], ['HTML', 'XML_XSLT'])) { if (!class_exists('DOMDocument') || !class_exists('XSLTProcessor')) { $this->_details['format'] = 'XML_XSLT'; } diff --git a/Sources/Tasks/GenericScheduledTask.php b/Sources/Tasks/GenericScheduledTask.php index 7ffeb07362..9d1762e0e3 100644 --- a/Sources/Tasks/GenericScheduledTask.php +++ b/Sources/Tasks/GenericScheduledTask.php @@ -33,7 +33,7 @@ public function execute(): bool $callable_task = Utils::getCallable($this->_details['callable']); // Perform the task. - $this->should_log = !empty($callable_task) ? call_user_func($callable_task) : false; + $this->should_log = !empty($callable_task) ? \call_user_func($callable_task) : false; return true; } diff --git a/Sources/Tasks/GenericTask.php b/Sources/Tasks/GenericTask.php index 21431fd697..dadf7b928f 100644 --- a/Sources/Tasks/GenericTask.php +++ b/Sources/Tasks/GenericTask.php @@ -37,7 +37,7 @@ public function execute(): bool // Perform the task. if (!empty($callable_task)) { - call_user_func_array($callable_task, $args); + \call_user_func_array($callable_task, $args); } return true; diff --git a/Sources/Tasks/Likes_Notify.php b/Sources/Tasks/Likes_Notify.php index 00aade823d..fea1757820 100644 --- a/Sources/Tasks/Likes_Notify.php +++ b/Sources/Tasks/Likes_Notify.php @@ -61,7 +61,7 @@ public function execute(): bool $ignored_members = explode(',', $row['pm_ignore_list']); // If the user is in group 1 anywhere, they can see everything anyway. - if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) { + if (\in_array(1, $groups) || \count(array_intersect($allowed, $groups)) != 0) { $author = $row['id_member']; } } @@ -89,7 +89,7 @@ public function execute(): bool } // If the person who sent the notification is on this person's ignore list, do nothing. - if (!empty($ignored_members) && in_array($this->_details['sender_id'], $ignored_members)) { + if (!empty($ignored_members) && \in_array($this->_details['sender_id'], $ignored_members)) { return true; } diff --git a/Sources/Tasks/RemoveOldDrafts.php b/Sources/Tasks/RemoveOldDrafts.php index 5e301d8ca7..3107c8289d 100644 --- a/Sources/Tasks/RemoveOldDrafts.php +++ b/Sources/Tasks/RemoveOldDrafts.php @@ -61,7 +61,7 @@ public function execute(): bool Db::$db->free_result($request); // If we have old ones, remove them. - if (count($drafts) > 0) { + if (\count($drafts) > 0) { Draft::delete($drafts, false); } diff --git a/Sources/Tasks/RemoveTempAttachments.php b/Sources/Tasks/RemoveTempAttachments.php index 51bcec5527..1e039ae65e 100644 --- a/Sources/Tasks/RemoveTempAttachments.php +++ b/Sources/Tasks/RemoveTempAttachments.php @@ -36,7 +36,7 @@ public function execute(): bool { // We need to know where this thing is going. if (!empty(Config::$modSettings['currentAttachmentUploadDir'])) { - if (!is_array(Config::$modSettings['attachmentUploadDir'])) { + if (!\is_array(Config::$modSettings['attachmentUploadDir'])) { Config::$modSettings['attachmentUploadDir'] = Utils::jsonDecode(Config::$modSettings['attachmentUploadDir'], true); } diff --git a/Sources/Tasks/RemoveTopicRedirects.php b/Sources/Tasks/RemoveTopicRedirects.php index 56231aedb8..e70646f6c2 100644 --- a/Sources/Tasks/RemoveTopicRedirects.php +++ b/Sources/Tasks/RemoveTopicRedirects.php @@ -55,7 +55,7 @@ public function execute(): bool Db::$db->free_result($request); // Zap, you're gone. - if (count($topics) > 0) { + if (\count($topics) > 0) { Topic::remove($topics, false, true); } diff --git a/Sources/Tasks/SendDigests.php b/Sources/Tasks/SendDigests.php index 939053cf05..c796e95ede 100644 --- a/Sources/Tasks/SendDigests.php +++ b/Sources/Tasks/SendDigests.php @@ -239,7 +239,7 @@ public function execute(): bool foreach ($types['topic'] as $id => $board) { foreach ($board['lines'] as $topic) { - if (in_array($mid, $topic['members'])) { + if (\in_array($mid, $topic['members'])) { if (!$titled) { $email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------'; $titled = true; @@ -261,7 +261,7 @@ public function execute(): bool foreach ($types['reply'] as $id => $board) { foreach ($board['lines'] as $topic) { - if (in_array($mid, $topic['members'])) { + if (\in_array($mid, $topic['members'])) { if (!$titled) { $email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------'; $titled = true; @@ -288,7 +288,7 @@ public function execute(): bool foreach ($type as $id => $board) { foreach ($board['lines'] as $topic) { - if (in_array($mid, $topic['members'])) { + if (\in_array($mid, $topic['members'])) { if (!$titled) { $email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------'; $titled = true; diff --git a/Sources/Tasks/UpdateUnicode.php b/Sources/Tasks/UpdateUnicode.php index 013fc9b829..1a6901927e 100644 --- a/Sources/Tasks/UpdateUnicode.php +++ b/Sources/Tasks/UpdateUnicode.php @@ -561,7 +561,7 @@ public function execute(): bool @ini_set('memory_limit', '256M'); - $this->time_limit = (empty(ini_get('max_execution_time')) || @set_time_limit(TaskRunner::MAX_CLAIM_THRESHOLD) !== false) ? TaskRunner::MAX_CLAIM_THRESHOLD : ini_get('max_execution_time'); + $this->time_limit = (empty(\ini_get('max_execution_time')) || @set_time_limit(TaskRunner::MAX_CLAIM_THRESHOLD) !== false) ? TaskRunner::MAX_CLAIM_THRESHOLD : \ini_get('max_execution_time'); foreach ($this->funcs as $func_name => $func_info) { $file_paths['final'] = implode(DIRECTORY_SEPARATOR, [$this->unicodedir, $func_info['file']]); @@ -699,7 +699,7 @@ public function execute(): bool $file_paths['temp'] = $this->temp_dir . DIRECTORY_SEPARATOR . $func_info['file']; $file_paths['real'] = $this->unicodedir . DIRECTORY_SEPARATOR . $func_info['file']; - if (in_array($file_paths['temp'], $done_files)) { + if (\in_array($file_paths['temp'], $done_files)) { continue; } @@ -805,10 +805,10 @@ private function fetch_unicode_file(string $filename, string $data_url): string| return $local_file; } - if (!file_exists(dirname($local_file))) { - @mkdir(dirname($local_file), 0777, true); + if (!file_exists(\dirname($local_file))) { + @mkdir(\dirname($local_file), 0777, true); - if (!is_dir(dirname($local_file))) { + if (!is_dir(\dirname($local_file))) { return false; } } @@ -946,7 +946,7 @@ public function export_funcs_to_file(): void private function get_function_code_and_regex(string|int $func_name): array { // No function name means data is raw code. - if (!is_string($func_name)) { + if (!\is_string($func_name)) { $func_code = implode("\n\n", $this->funcs[$func_name]['data']); $func_regex = $this->funcs[$func_name]['regex'] ?? '/' . preg_quote($func_code, '/') . '/'; } else { @@ -1027,8 +1027,8 @@ private function build_func_array(string &$func_code, array $data, string $key_t $func_code .= var_export($key, true) . ' => '; } - if (is_array($value)) { - if ($val_type == 'string' && count($value) === count($value, COUNT_RECURSIVE)) { + if (\is_array($value)) { + if ($val_type == 'string' && \count($value) === \count($value, COUNT_RECURSIVE)) { $nextline = "\n" . str_repeat("\t", $indent + 1); $func_code = rtrim($func_code); @@ -1174,7 +1174,7 @@ private function process_derived_normalization_props(): bool if (!isset($fields[2])) { $value = 'SAME'; - } elseif (in_array($fields[1], ['FC_NFKC', 'NFKC_CF'])) { + } elseif (\in_array($fields[1], ['FC_NFKC', 'NFKC_CF'])) { $value = trim($fields[2]) !== '' ? '' . str_replace(' ', '; ', trim($fields[2])) . ';' : ''; } else { $value = $fields[2]; @@ -1316,12 +1316,12 @@ private function process_casing_data(): bool } // Full casefolding. - if (in_array($fields[1], ['C', 'F'])) { + if (\in_array($fields[1], ['C', 'F'])) { $this->funcs['utf8_casefold_maps']['data']['' . $fields[0] . ';'] = '' . str_replace(' ', '; ', trim($fields[2])) . ';'; } // Simple casefolding. - if (in_array($fields[1], ['C', 'S'])) { + if (\in_array($fields[1], ['C', 'S'])) { $this->funcs['utf8_casefold_simple_maps']['data']['' . $fields[0] . ';'] = '' . str_replace(' ', '; ', trim($fields[2])) . ';'; } } @@ -1372,7 +1372,7 @@ private function finalize_decomposition_forms(): bool $temp = []; foreach ($this->funcs['utf8_normalize_d_maps']['data'] as $composed => $decomposed) { - if ($iteration === 0 && !in_array($composed, $this->derived_normalization_props['Full_Composition_Exclusion'])) { + if ($iteration === 0 && !\in_array($composed, $this->derived_normalization_props['Full_Composition_Exclusion'])) { $this->funcs['utf8_compose_maps']['data'][$decomposed] = $composed; } @@ -1415,7 +1415,7 @@ private function build_quick_check(): bool $ord = hexdec(trim($entity, '')); - if (is_null($current_range['start'])) { + if (\is_null($current_range['start'])) { $current_range['start'] = $ord; } @@ -1473,7 +1473,7 @@ private function build_regex_properties(): bool $fields[$key] = trim($value); } - if (in_array($fields[1], $this->funcs['utf8_regex_properties']['props'])) { + if (\in_array($fields[1], $this->funcs['utf8_regex_properties']['props'])) { if (!isset($this->funcs['utf8_regex_properties']['data'][$fields[1]])) { $this->funcs['utf8_regex_properties']['data'][$fields[1]] = []; } @@ -1547,7 +1547,7 @@ private function build_regex_variation_selectors(): bool $current_range = ['start' => null, 'end' => null]; foreach ($ords as $ord) { - if (is_null($current_range['start'])) { + if (\is_null($current_range['start'])) { $current_range['start'] = $ord; } @@ -1649,7 +1649,7 @@ private function build_script_stats(): bool $fields[$key] = trim($value); } - if (in_array($fields[1], ['Common', 'Inherited'])) { + if (\in_array($fields[1], ['Common', 'Inherited'])) { continue; } @@ -1691,7 +1691,7 @@ private function build_script_stats(): bool $char_scripts = []; foreach (explode(' ', $fields[1]) as $alias) { - if (!in_array($this->script_aliases[$alias], ['Common', 'Inherited'])) { + if (!\in_array($this->script_aliases[$alias], ['Common', 'Inherited'])) { $char_scripts[] = $this->script_aliases[$alias]; } } @@ -1911,7 +1911,7 @@ private function build_regex_indic(): bool $insc = $fields[1]; - if (!in_array($insc, ['Virama', 'Vowel_Dependent'])) { + if (!\in_array($insc, ['Virama', 'Vowel_Dependent'])) { continue; } @@ -1988,7 +1988,7 @@ private function build_regex_indic(): bool foreach ($inscs as $insc => $value) { sort($value); - if (!in_array($insc, ['All', 'Letter', 'Nonspacing_Mark', 'Nonspacing_Combining_Mark'])) { + if (!\in_array($insc, ['All', 'Letter', 'Nonspacing_Mark', 'Nonspacing_Combining_Mark'])) { continue; } @@ -1997,7 +1997,7 @@ private function build_regex_indic(): bool $current_range = ['start' => null, 'end' => null]; foreach ($value as $ord) { - if (is_null($current_range['start'])) { + if (\is_null($current_range['start'])) { $current_range['start'] = $ord; } @@ -2087,7 +2087,7 @@ private function build_idna(): bool } elseif ($fields[1] === 'ignored') { $this->funcs['idna_regex']['data']['ignored'][] = '\\x{' . str_replace('..', '}-\\x{', $fields[0]) . '}'; } elseif ($fields[1] === 'disallowed') { - if (in_array('', $entities)) { + if (\in_array('', $entities)) { continue; } diff --git a/Sources/Theme.php b/Sources/Theme.php index f8ae4bff29..c359a683e1 100644 --- a/Sources/Theme.php +++ b/Sources/Theme.php @@ -206,7 +206,7 @@ public static function load(int $id = 0, bool $initialize = true): self // Sometimes the user can choose their own theme. if (!empty(Config::$modSettings['theme_allow']) || (isset(User::$me) && User::$me->allowedTo('admin_forum'))) { // The theme was specified by REQUEST. - if (!empty($_REQUEST['theme']) && (User::$me->allowedTo('admin_forum') || in_array($_REQUEST['theme'], explode(',', Config::$modSettings['knownThemes'])))) { + if (!empty($_REQUEST['theme']) && (User::$me->allowedTo('admin_forum') || \in_array($_REQUEST['theme'], explode(',', Config::$modSettings['knownThemes'])))) { $id = (int) $_REQUEST['theme']; $_SESSION['id_theme'] = $id; } @@ -227,7 +227,7 @@ public static function load(int $id = 0, bool $initialize = true): self } elseif (!empty(Config::$modSettings['enableThemes'])) { $themes = explode(',', Config::$modSettings['enableThemes']); - if (!in_array($id, $themes)) { + if (!\in_array($id, $themes)) { $id = Config::$modSettings['theme_guests']; } else { $id = (int) $id; @@ -326,7 +326,7 @@ public static function loadTemplate(string|bool $template_name, array|string $st { // Do any style sheets first, cause we're easy with those. if (!empty($style_sheets)) { - if (!is_array($style_sheets)) { + if (!\is_array($style_sheets)) { $style_sheets = [$style_sheets]; } @@ -356,8 +356,8 @@ public static function loadTemplate(string|bool $template_name, array|string $st } // If they have specified an initialization function for this template, go ahead and call it now. - if (function_exists('template_' . $template_name . '_init')) { - call_user_func('template_' . $template_name . '_init'); + if (\function_exists('template_' . $template_name . '_init')) { + \call_user_func('template_' . $template_name . '_init'); } return true; @@ -413,7 +413,7 @@ public static function loadSubTemplate(string $sub_template_name, bool|string $f // Figure out what the template function is named. $theme_function = 'template_' . $sub_template_name; - if (function_exists($theme_function)) { + if (\function_exists($theme_function)) { $theme_function(); } elseif ($fatal === false) { ErrorHandler::fatalLang('theme_template_error', 'template', [(string) $sub_template_name]); @@ -469,9 +469,9 @@ public static function loadCSSFile(string $fileName, array $params = [], string Utils::$context['css_files_order'] = []; } - $params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? - (array_key_exists('browser_cache', Utils::$context) ? Utils::$context['browser_cache'] : '') : - (is_string($params['seed']) ? '?' . ltrim($params['seed'], '?') : ''); + $params['seed'] = (!\array_key_exists('seed', $params) || (\array_key_exists('seed', $params) && $params['seed'] === true)) ? + (\array_key_exists('browser_cache', Utils::$context) ? Utils::$context['browser_cache'] : '') : + (\is_string($params['seed']) ? '?' . ltrim($params['seed'], '?') : ''); $params['force_current'] = $params['force_current'] ?? false; $themeRef = !empty($params['default_theme']) ? 'default_theme' : 'theme'; $params['minimize'] = $params['minimize'] ?? true; @@ -598,9 +598,9 @@ public static function addInlineCss(string $css): bool */ public static function loadJavaScriptFile(string $fileName, array $params = [], string $id = ''): void { - $params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? - (array_key_exists('browser_cache', Utils::$context) ? Utils::$context['browser_cache'] : '') : - (is_string($params['seed']) ? '?' . ltrim($params['seed'], '?') : ''); + $params['seed'] = (!\array_key_exists('seed', $params) || (\array_key_exists('seed', $params) && $params['seed'] === true)) ? + (\array_key_exists('browser_cache', Utils::$context) ? Utils::$context['browser_cache'] : '') : + (\is_string($params['seed']) ? '?' . ltrim($params['seed'], '?') : ''); $params['force_current'] = $params['force_current'] ?? false; $themeRef = !empty($params['default_theme']) ? 'default_theme' : 'theme'; $params['async'] = $params['async'] ?? false; @@ -667,13 +667,13 @@ public static function loadJavaScriptFile(string $fileName, array $params = [], public static function addJavaScriptVar(string $key, mixed $value, bool $escape = false): void { // Variable name must be a valid string. - if (!is_string($key) || $key === '' || is_numeric($key)) { + if (!\is_string($key) || $key === '' || is_numeric($key)) { return; } // Take care of escaping the value for JavaScript? if (!empty($escape)) { - switch (gettype($value)) { + switch (\gettype($value)) { // Illegal. case 'resource': break; @@ -689,7 +689,7 @@ public static function addJavaScriptVar(string $key, mixed $value, bool $escape array_walk_recursive( $value, function ($v, $k) use (&$replacements) { - if (is_string($v)) { + if (\is_string($v)) { $replacements[json_encode($v)] = Utils::escapeJavaScript($v, true); } }, @@ -709,7 +709,7 @@ function ($v, $k) use (&$replacements) { // At this point, value should contain suitably escaped JavaScript code. // If it obviously doesn't, declare the var with an undefined value. - if (!is_string($value) && !is_numeric($value)) { + if (!\is_string($value) && !is_numeric($value)) { $value = null; } @@ -768,7 +768,7 @@ public static function setupContext(bool $forceload = false): void // Get some news... Utils::$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes(Config::$modSettings['news']))))); - for ($i = 0, $n = count(Utils::$context['news_lines']); $i < $n; $i++) { + for ($i = 0, $n = \count(Utils::$context['news_lines']); $i < $n; $i++) { if (trim(Utils::$context['news_lines'][$i]) == '') { continue; } @@ -778,7 +778,7 @@ public static function setupContext(bool $forceload = false): void } if (!empty(Utils::$context['news_lines']) && (!empty(Config::$modSettings['allow_guestAccess']) || User::$me->is_logged)) { - Utils::$context['random_news_line'] = Utils::$context['news_lines'][mt_rand(0, count(Utils::$context['news_lines']) - 1)]; + Utils::$context['random_news_line'] = Utils::$context['news_lines'][mt_rand(0, \count(Utils::$context['news_lines']) - 1)]; } if (!User::$me->is_guest) { @@ -1294,8 +1294,8 @@ public static function template_header(): void } if ($position !== false) { - $before = array_slice(Utils::$context['template_layers'], 0, $position + 1); - $after = array_slice(Utils::$context['template_layers'], $position + 1); + $before = \array_slice(Utils::$context['template_layers'], 0, $position + 1); + $after = \array_slice(Utils::$context['template_layers'], $position + 1); Utils::$context['template_layers'] = array_merge($before, ['maint_warning'], $after); } } @@ -1307,7 +1307,7 @@ public static function template_header(): void self::loadSubTemplate($layer . '_above', true); // May seem contrived, but this is done in case the body and main layer aren't there... - if (in_array($layer, ['body', 'main']) && User::$me->allowedTo('admin_forum') && !User::$me->is_guest && !$checked_securityFiles) { + if (\in_array($layer, ['body', 'main']) && User::$me->allowedTo('admin_forum') && !User::$me->is_guest && !$checked_securityFiles) { $checked_securityFiles = true; $securityFiles = ['install.php', 'upgrade.php', 'convert.php', 'repair_paths.php', 'repair_settings.php', 'Settings.php~', 'Settings_bak.php~']; @@ -1392,7 +1392,7 @@ public static function template_header(): void } } // If the user is banned from posting inform them of it. - elseif (in_array($layer, ['main', 'body']) && isset($_SESSION['ban']['cannot_post']) && !$showed_banned) { + elseif (\in_array($layer, ['main', 'body']) && isset($_SESSION['ban']['cannot_post']) && !$showed_banned) { $showed_banned = true; echo ' @@ -1441,7 +1441,7 @@ public static function template_footer(): void Utils::$context['load_time'] = round(microtime(true) - TIME_START, 3); Utils::$context['load_queries'] = Db::$count; - if (!empty(Utils::$context['template_layers']) && is_array(Utils::$context['template_layers'])) { + if (!empty(Utils::$context['template_layers']) && \is_array(Utils::$context['template_layers'])) { foreach (array_reverse(Utils::$context['template_layers']) as $layer) { self::loadSubTemplate($layer . '_below', true); } @@ -1470,11 +1470,11 @@ public static function template_javascript(bool $do_deferred = false): void echo "\n\t