fix(admin-edit-ban): resolve PHPStan false positive - #1541
Merged
Conversation
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.
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Gate the IP-length/validity check on
$postBanType === BanType::Ipalone, then nest the$_POST['ip']-dependent conditions inside, instead of re-checking the enum inside a compound&&alongside a mixed-typed operand.Before:
After:
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 (
$postBanType === BanType::Ipwas already a common factor to both branches, just factored out as an outer gate).Motivation and Context
#1540
PHPStan was flagging the previous compound condition as always-false dead code:
blocking CI on
pages/admin.edit.ban.php.Confirmed false positive via isolated repro: combining a re-check of
$postBanTypewith a mixed-typed$_POSTvalue in the same&&expression, right after an earlierif/elseif/elseif/elsechain that discriminates on$postBanTypeonly 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.Fixes #
How Has This Been Tested?
includes/vendor/bin/phpstan analyse --configuration=phpstan.neon --no-progress --error-format=github --memory-limit=1Glocally — clean, no errors onpages/admin.edit.ban.php.Screenshots (if appropriate):
Types of changes
Checklist:
Note: If your PR touches
web/**and this is your firstcontribution to the web panel, the CLA bot will comment within
~30 seconds with one-line sign instructions. You only need to sign
once per repo. See
[CLA.md](https://claude.ai/chat/CLA.md)for the full text and[CONTRIBUTING.md](https://claude.ai/chat/CONTRIBUTING.md)for the rationale.