Generic/InlineControlStructure: remove unreachable if condition#1386
Merged
jrfnl merged 1 commit intoMar 7, 2026
Merged
Conversation
Commit e1b9595 changed the InlineControlStructure sniff to make it bail early for all control structures without a body (before the sniff did that only for `while` and `for`). Before commit e1b9595, `$nextNonEmpty` could be `false` as there were some scenarios where there would be no non-empty tokens after the `$stackPtr` or after the `parenthesis_closer`. This is the case for the `else` without a body in InlineControlStructureUnitTest.2.inc and the `if` without a body in InlineControlStructureUnitTest.5.inc. After commit e1b9595, `$nextNonEmpty` cannot be `false` anymore as cases where there are no non-empty tokens are handled before this variable is set. This happens either in line 83 when `$nextTokenIndex` is set or line 98 when `$nextTokenIndex` is not set (a control structure that is not `T_ELSE` or `T_DO` and is missing the parenthesis closer).
jrfnl
approved these changes
Mar 7, 2026
Member
jrfnl
left a comment
There was a problem hiding this comment.
Makes sense. Thanks @rodrigoprimo !
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR is a follow-up to #1144 and removes an unreachable if condition.
Commit 29d0be3 changed the
InlineControlStructuresniff to make it bail early for all control structures without a body (before the sniff did that only forwhileandfor).Before commit 29d0be3,
$nextNonEmptycould befalseas there were some scenarios where there would be no non-empty tokens after the$stackPtror after the parenthesis_closer. This is the case for the else without a body in InlineControlStructureUnitTest.2.inc and the if without a body in InlineControlStructureUnitTest.5.inc.After commit 29d0be3,
$nextNonEmptycannot befalseanymore, as cases where there are no non-empty tokens are handled before this variable is set. This happens either in line 83 when$nextTokenIndexis set or line 98 when$nextTokenIndexis not set (a control structure that is notT_ELSEorT_DOand is missing the parenthesis closer).Suggested changelog entry
N/A
Types of changes
PR checklist