PHP 8.3 | Generic/ScopeIndent: bug fix - missing defensive coding #3857
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
As of PHP 8.3, PHP will throw a
Warning: Decrement on type bool has no effect, this will change in the next major version of PHP
notice.A test run with PHP 8.3 showed this deprecation notice being thrown in the
Generic.WhiteSpace.ScopeIndent
sniff.Investigation of the notice showed that this was actually a bug due to too little defensive coding.
The sniff tries to skip over multi-line/multi-token text strings, but the
findNext()
will returnfalse
for a single-line/single-token text string, which would lead to$i
being reset to0
.This commit fixes this by only changing
$i
when the return from the call tofindNext()
is notfalse
.Ref: https://wiki.php.net/rfc/saner-inc-dec-operators
Note: I've not added any extra tests as this issue was discovered via the pre-existing tests, so is already covered.
Suggested changelog entry
Generic.WhiteSpace.ScopeIndent: bug fix preventing a deprecation notice on PHP 8.3
Types of changes