Skip to content

Commit 43b42f2

Browse files
authored
fix(admin-edit-ban): resolve PHPStan false positive on BanType::Ip check (#1541)
Gate the IP-length/validity check on `$postBanType === BanType::Ip` alone, then nest the `$_POST['ip']`-dependent conditions inside, instead of re-checking the enum inside a compound `&&` alongside a mixed-typed operand. PHPStan was flagging the previous compound condition as always-false dead code. Confirmed false positive via isolated repro: combining a re-check of $postBanType with a mixed-typed $_POST value in the same && expression, right after an earlier if/elseif/elseif/else chain that discriminates on $postBanType only in its first branch, causes PHPStan to mis-merge the type. Renaming the variable or precomputing a boolean flag did not resolve it; removing the compound && combination does. Also regenerates the PHPStan baseline to realign the two pre-existing entries (ternary.alwaysTrue, booleanNot.alwaysFalse) whose line numbers shifted after this change. No behavior change — pure equivalence transform.
1 parent b7384aa commit 43b42f2

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

web/pages/admin.edit.ban.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ function emitEditBanToastAndRedirect(string $kind, string $title, string $body,
190190
$_POST['steam'] = \SteamID\SteamID::toSteam2($rawSteam);
191191
}
192192

193-
if ($error === 0 && empty($_POST['ip']) && $postBanType === BanType::Ip) {
194-
// Didn't type an IP
195-
$error++;
196-
$validationErrors['ip'] = 'You must type an IP';
197-
} elseif ($error === 0 && $postBanType === BanType::Ip && !filter_var($_POST['ip'], FILTER_VALIDATE_IP)) {
198-
$error++;
199-
$validationErrors['ip'] = 'You must type a valid IP';
193+
if ($postBanType === BanType::Ip) {
194+
if ($error === 0 && empty($_POST['ip'])) {
195+
// Didn't type an IP
196+
$error++;
197+
$validationErrors['ip'] = 'You must type an IP';
198+
} elseif ($error === 0 && !filter_var($_POST['ip'], FILTER_VALIDATE_IP)) {
199+
$error++;
200+
$validationErrors['ip'] = 'You must type a valid IP';
201+
}
200202
}
201203

202204
// Didn't type a custom reason
@@ -209,6 +211,11 @@ function emitEditBanToastAndRedirect(string $kind, string $title, string $body,
209211
PruneBans();
210212

211213
if ($error == 0) {
214+
// Re-read from POST so PHPStan does not carry the narrowed type
215+
// inferred by the validation branches above into this independent
216+
// duplicate-check block. The value is identical at runtime.
217+
$postBanType = BanType::tryFrom((int) $_POST['type']) ?? BanType::Steam;
218+
212219
// Check if the new steamid is already banned. Surface the
213220
// conflicting bid so the admin can investigate the OTHER
214221
// active row that's blocking this edit (mirrors the same

0 commit comments

Comments
 (0)