Apply automated PHP8 safety transforms

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/89922108-1604-44ae-949d-358d32b9d70a

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-23 14:01:37 +00:00 committed by GitHub
parent aca850b6cd
commit e44519c030
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
465 changed files with 1716 additions and 1716 deletions

View file

@ -78,14 +78,14 @@ class AdminWorkshopController
$fanOut = [];
$groupIndex = $this->indexGameGroups();
foreach ($payload as $groupKey => $adapterKey) {
foreach ((array)$payload as $groupKey => $adapterKey) {
$groupKey = (string)$groupKey;
$adapterKey = (string)$adapterKey;
if (!isset($groupIndex[$groupKey])) {
continue;
}
foreach ($groupIndex[$groupKey] as $gameKey) {
foreach ((array)$groupIndex[$groupKey] as $gameKey) {
$fanOut[$gameKey] = $adapterKey;
}
}
@ -152,7 +152,7 @@ class AdminWorkshopController
$override = ($this->adapterFormGameKey === $primaryKey) ? $this->adapterFormOverride : null;
$mappingValues = [];
foreach ($group['game_keys'] as $gameKey) {
foreach ((array)$group['game_keys'] as $gameKey) {
if (isset($mappings[$gameKey]) && $mappings[$gameKey] !== '') {
$mappingValues[$mappings[$gameKey]] = true;
}
@ -164,8 +164,8 @@ class AdminWorkshopController
'game_name' => $group['game_name'],
'game_keys' => $group['game_keys'],
'primary_game_key' => $primaryKey,
'mixed_mapping' => count($mappingValues) > 1,
'selected_adapter' => count($mappingValues) === 1 ? array_key_first($mappingValues) : '',
'mixed_mapping' => count((array)$mappingValues) > 1,
'selected_adapter' => count((array)$mappingValues) === 1 ? array_key_first($mappingValues) : '',
'exists' => $this->service->gameAdapterExists($primaryKey),
'adapter' => $this->service->getGameAdapter($primaryKey),
'updated_at' => $this->service->getGameAdapterUpdatedAt($primaryKey),
@ -193,7 +193,7 @@ class AdminWorkshopController
continue;
}
foreach ($group['game_keys'] as $gameKey) {
foreach ((array)$group['game_keys'] as $gameKey) {
$this->service->upsertAdapterMapping($gameKey, $primaryGameKey);
}
return;
@ -209,7 +209,7 @@ class AdminWorkshopController
continue;
}
foreach ($group['game_keys'] as $gameKey) {
foreach ((array)$group['game_keys'] as $gameKey) {
$this->service->removeAdapterMapping($gameKey, $primaryGameKey);
}
return;

View file

@ -148,7 +148,7 @@ class SteamWorkshopController
{
$records = [];
$homes = $this->service->listHomesForUser($userId, $isAdmin);
foreach ($homes as $home) {
foreach ((array)$homes as $home) {
$config = $this->service->loadConfig((int)$home['home_id']);
$this->applyGameAdapterOverride($home, $config);
$adapter = $this->service->getAdapterByKey($config['adapter_key']);

View file

@ -23,10 +23,10 @@
*/
function create_drop_box_from_array_onchange($input_array,$listname,$current_value = "")
{
$only_one = count($input_array) == 1;
$only_one = count((array)$input_array) == 1;
$disabled = $only_one? "disabled=disabled":"";
$retval = "<select id=\"$listname\" name=\"$listname\" style=\"max-width:330px;\" onchange=\"this.form.submit()\" $disabled>\n";
foreach($input_array as $key => $value)
foreach ((array)$input_array as $key => $value)
{
// Make sure we don't allow HTML or script
$key = trim(strip_tags($key));
@ -56,7 +56,7 @@ function get_mod_names_list($mods_list, $xml_mods)
$mod_names = "";
foreach(explode(',', $mods_list) as $workshop_mod_id)
{
foreach($xml_mods as $mod)
foreach ((array)$xml_mods as $mod)
{
if($mod['id'] == $workshop_mod_id)
{
@ -137,7 +137,7 @@ function get_installed_mods($home_cfg, $remote, $xml)
$retval = $remote->get_workshop_mods_info($mod_info_array);
$current = explode($string_separator, $current_mods_string);
$installed_mods = array();
foreach($current as $c)
foreach ((array)$current as $c)
{
if($c != "")
{
@ -182,7 +182,7 @@ function remove_mod($home_cfg, $remote, $xml, $mod_string)
{
$current = explode($string_separator, $current_mods_string);
foreach($current as $index => $c)
foreach ((array)$current as $index => $c)
{
if(trim($c) == $mod_string)
unset($current[$index]);

View file

@ -131,7 +131,7 @@ class SteamWorkshopService
$root->appendChild($doc->createElement('rawDefinition', $config['raw_definition']));
$modsNode = $doc->createElement('mods');
foreach ($config['workshop_items'] as $item) {
foreach ((array)$config['workshop_items'] as $item) {
$mod = $doc->createElement('mod');
$mod->setAttribute('id', (string)$item['id']);
$mod->setAttribute('label', (string)$item['label']);
@ -181,7 +181,7 @@ class SteamWorkshopService
$items = [];
$lines = preg_split('/\r\n|\r|\n/', $raw);
foreach ($lines as $line) {
foreach ((array)$lines as $line) {
$line = trim($line);
if ($line === '') {
continue;
@ -239,7 +239,7 @@ class SteamWorkshopService
$logins[] = ['user' => $username, 'password' => $password];
}
foreach ($logins as $credentials) {
foreach ((array)$logins as $credentials) {
$this->appendLog($logPath, sprintf('SteamCMD download start app=%s workshop=%s login=%s', $appId, $workshopId, $credentials['user']));
$result = $this->runSteamCmdDownload($steamCmdPath, $appId, $workshopId, $credentials['user'], $credentials['password']);
$this->appendSteamCmdOutput($logPath, $result['output']);
@ -339,7 +339,7 @@ class SteamWorkshopService
{
$sanitized = [];
$options = $this->getAdapterOptions();
foreach ($mappings as $gameKey => $adapterKey) {
foreach ((array)$mappings as $gameKey => $adapterKey) {
$gameKey = trim((string)$gameKey);
$adapterKey = $this->sanitizeAdapterKey((string)$adapterKey);
if ($gameKey === '' || !isset($options[$adapterKey])) {
@ -391,7 +391,7 @@ class SteamWorkshopService
}
$result = [];
foreach ($decoded as $gameKey => $adapterKey) {
foreach ((array)$decoded as $gameKey => $adapterKey) {
if (!is_string($gameKey) || !is_string($adapterKey)) {
continue;
}
@ -595,7 +595,7 @@ class SteamWorkshopService
$groups[$groupKey]['game_keys'][] = $gameKey;
}
foreach ($groups as &$group) {
foreach ((array)$groups as &$group) {
$group['game_keys'] = array_values(array_unique($group['game_keys']));
sort($group['game_keys']);
$group['primary_game_key'] = $group['game_keys'][0];
@ -865,7 +865,7 @@ class SteamWorkshopService
$results = [];
$lines = preg_split('/\r\n|\r|\n/', trim($stdout));
if (is_array($lines)) {
foreach ($lines as $line) {
foreach ((array)$lines as $line) {
if ($line === '') {
continue;
}
@ -887,7 +887,7 @@ class SteamWorkshopService
'subscriptions' => 0,
'source' => 'scraper',
];
if (count($results) >= $perPage) {
if (count((array)$results) >= $perPage) {
break;
}
}
@ -901,8 +901,8 @@ class SteamWorkshopService
'success' => $success,
'error' => $errorMessage,
'results' => $results,
'total' => count($results),
'has_more' => count($results) >= $perPage,
'total' => count((array)$results),
'has_more' => count((array)$results) >= $perPage,
'request' => $request,
];
}
@ -948,7 +948,7 @@ class SteamWorkshopService
preg_match_all('/sharedfiles\/filedetails\/\?id=([0-9]+)/i', $html, $matches);
$rawIds = $matches[1] ?? [];
$uniqueIds = [];
foreach ($rawIds as $rawId) {
foreach ((array)$rawIds as $rawId) {
$id = preg_replace('/[^0-9]/', '', (string)$rawId);
if ($id === '' || isset($uniqueIds[$id])) {
continue;
@ -956,11 +956,11 @@ class SteamWorkshopService
$uniqueIds[$id] = true;
}
$orderedIds = array_keys($uniqueIds);
$hasMore = count($orderedIds) > $perPage;
$hasMore = count((array)$orderedIds) > $perPage;
$sliceIds = array_slice($orderedIds, 0, $perPage);
$results = [];
foreach ($sliceIds as $id) {
foreach ((array)$sliceIds as $id) {
$detailResponse = $this->httpGet(self::STEAM_WORKSHOP_DETAIL_URL, ['id' => $id], $this->getScraperUserAgent());
$title = '';
if ($detailResponse['error'] === null && $detailResponse['http_code'] >= 200 && $detailResponse['http_code'] < 300 && $detailResponse['body'] !== null) {
@ -987,7 +987,7 @@ class SteamWorkshopService
'success' => true,
'error' => null,
'results' => $results,
'total' => count($results),
'total' => count((array)$results),
'has_more' => $hasMore,
'request' => $request,
];
@ -1071,7 +1071,7 @@ class SteamWorkshopService
}
$adapters = $this->getAdapterOptions();
if (array_key_exists($key, $adapters)) {
if (array_key_exists($key, (array)$adapters)) {
return $key;
}
@ -1213,7 +1213,7 @@ class SteamWorkshopService
dirname($this->adapterMapFile),
];
foreach ($directories as $dir) {
foreach ((array)$directories as $dir) {
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
@ -1312,7 +1312,7 @@ class SteamWorkshopService
}
$result = [];
foreach ($decoded as $item) {
foreach ((array)$decoded as $item) {
if (!is_array($item)) {
continue;
}
@ -1340,7 +1340,7 @@ class SteamWorkshopService
private function serializeWorkshopItems(array $items): string
{
$lines = [];
foreach ($items as $item) {
foreach ((array)$items as $item) {
$id = preg_replace('/[^0-9]/', '', (string)($item['id'] ?? ''));
if ($id === '') {
continue;

View file

@ -128,7 +128,7 @@ function exec_ogp_module()
if(isset($_POST['uninstall']) and isset($_POST['mod_string']))
{
$output = "";
foreach($_POST['mod_string'] as $mod_string)
foreach ((array)$_POST['mod_string'] as $mod_string)
{
$result = remove_mod($home_cfg, $remote, $xml, $mod_string);
if($result !== FALSE)
@ -143,13 +143,13 @@ function exec_ogp_module()
{
$mods = get_installed_mods($home_cfg, $remote, $xml);
if($mods and count($mods) > 0)
if($mods and count((array)$mods) > 0)
{
$ft = new FormTable();
$ft->start_form("?m=steam_workshop&p=uninstall&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port'], "post", "autocomplete=\"off\"");
$ft->start_table();
echo '<tr><td><div id="uninstall_scrolling_checkbox">';
foreach($mods as $mod_id => $mod_name)
foreach ((array)$mods as $mod_id => $mod_name)
echo "<input type='checkbox' id='select_mod_$mod_id' name='mod_string[]' value='$mod_id'><label for='select_mod_$mod_id'>$mod_name</label><br>";
echo '</div></td></tr>';
$ft->end_table();

View file

@ -33,7 +33,7 @@ declare(strict_types=1);
<td colspan="5"><?php echo htmlspecialchars($lang['admin_no_game_keys'] ?? 'No Steam Workshop-enabled game definitions were detected.'); ?></td>
</tr>
<?php else: ?>
<?php foreach ($gameRows as $row): ?>
<?php foreach ((array)$gameRows as $row): ?>
<?php
$groupKey = $row['group_key'];
$primaryKey = $row['primary_game_key'];
@ -56,7 +56,7 @@ declare(strict_types=1);
<?php endif; ?>
</div>
<div class="sw-game-variants">
<?php foreach ($row['game_keys'] as $variantKey): ?>
<?php foreach ((array)$row['game_keys'] as $variantKey): ?>
<span class="sw-chip"><?php echo htmlspecialchars($variantKey); ?></span>
<?php endforeach; ?>
</div>
@ -66,7 +66,7 @@ declare(strict_types=1);
<td>
<select form="sw-mapping-form" name="mapping[<?php echo htmlspecialchars($groupKey); ?>]">
<option value="">--</option>
<?php foreach ($adapterOptions as $key => $label): ?>
<?php foreach ((array)$adapterOptions as $key => $label): ?>
<option value="<?php echo htmlspecialchars($key); ?>" <?php echo ($selectValue === $key) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($label); ?>
</option>
@ -172,7 +172,7 @@ declare(strict_types=1);
</tr>
</thead>
<tbody>
<?php foreach ($adapters as $adapter): ?>
<?php foreach ((array)$adapters as $adapter): ?>
<tr>
<td><?php echo htmlspecialchars($adapter['key']); ?></td>
<td><?php echo htmlspecialchars($adapter['name']); ?></td>

View file

@ -12,7 +12,7 @@ declare(strict_types=1);
</div>
<?php else: ?>
<div class="sw-grid">
<?php foreach ($records as $record): ?>
<?php foreach ((array)$records as $record): ?>
<?php $currentRecord = $record; include __DIR__ . '/partials/server_card.php'; ?>
<?php endforeach; ?>
</div>

View file

@ -92,7 +92,7 @@ $requestSummaryText = $requestSummary ?? '';
</tr>
</thead>
<tbody>
<?php foreach ($results as $item): ?>
<?php foreach ((array)$results as $item): ?>
<?php
$itemId = htmlspecialchars($item['id'] ?? '', ENT_QUOTES, 'UTF-8');
$label = htmlspecialchars($item['label'] ?? ('@' . $itemId), ENT_QUOTES, 'UTF-8');

View file

@ -27,7 +27,7 @@ $currentAdapterName = $adapterOptions[$formConfig['adapter_key']] ?? strtoupper(
<small><?php echo htmlspecialchars($lang['adapter_locked_note'] ?? 'This adapter is managed by the administrator.'); ?></small>
<?php else: ?>
<select name="workshop[adapter_key]">
<?php foreach ($adapterOptions as $key => $label): ?>
<?php foreach ((array)$adapterOptions as $key => $label): ?>
<option value="<?php echo htmlspecialchars($key); ?>" <?php echo $formConfig['adapter_key'] === $key ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($label); ?>
</option>

View file

@ -47,7 +47,7 @@ $langAttrs = [
];
?>
<div class="sw-picker" id="<?php echo $pickerId; ?>" data-endpoint="<?php echo htmlspecialchars($endpoint, ENT_QUOTES, 'UTF-8'); ?>" data-detail-base="https://steamcommunity.com/sharedfiles/filedetails/?id="
<?php foreach ($langAttrs as $key => $value): ?>data-lang-<?php echo $key; ?>="<?php echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); ?>" <?php endforeach; ?>>
<?php foreach ((array)$langAttrs as $key => $value): ?>data-lang-<?php echo $key; ?>="<?php echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); ?>" <?php endforeach; ?>>
<div class="sw-picker__header">
<h4><?php echo htmlspecialchars($lang['mod_picker_heading'] ?? 'Workshop library'); ?></h4>
<p class="sw-picker__hint"><?php echo htmlspecialchars($lang['mod_picker_hint'] ?? 'Search by Workshop ID or keyword to add mods.'); ?></p>

View file

@ -19,7 +19,7 @@ $mods = $config['workshop_items'] ?? [];
</tr>
</thead>
<tbody>
<?php foreach ($mods as $mod): ?>
<?php foreach ((array)$mods as $mod): ?>
<tr>
<td><?php echo htmlspecialchars($mod['id']); ?></td>
<td><?php echo htmlspecialchars($mod['label']); ?></td>

View file

@ -7,7 +7,7 @@ $config = $currentRecord['config'];
$adapter = $currentRecord['adapter'];
$homeName = htmlspecialchars($home['home_name'] ?? ('#' . $home['home_id']));
$homeId = (int)($home['home_id'] ?? 0);
$modCount = count($config['workshop_items']);
$modCount = count((array)$config['workshop_items']);
$interval = (int)$config['update_interval_minutes'];
$enabled = !empty($config['workshop_enabled']);
$lastSaved = $config['last_saved_at'] ? date('Y-m-d H:i', (int)$config['last_saved_at']) : '—';