Conversation
Given that: * `$insideIfConditionalReturn` has a default value of `0`; * And that value is only ever increased; * The `$insideIfConditionalReturn >= 0` condition will always be `true`. So this condition can be safely removed, just like the - now unused - assignments to the variable. The original condition was introduced with the introduction of the sniff in 177. The condition was adjusted in 291, which made the logic redundant. Looking at the sniff, I believe the intention was to only flag the "return outside condition missing" when not all control structure paths had a `return` statement, but this was never really properly checked as the only control structures taken into account are `if` control structures. I believe it would be good to improve the sniff to handle more control structures (`switch`, `while` etc) and to not throw the "return outside condition missing" error if all possible paths have a `return` statement, but that is outside the scope of the current PR. I will add a note to this effect to the review ticket for this sniff - 520.
51 tasks
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.
Given that:
$insideIfConditionalReturnhas a default value of0;$insideIfConditionalReturn >= 0condition will always betrue.So this condition can be safely removed, just like the - now unused - assignments to the variable.
The original condition was introduced with the introduction of the sniff in #177. The condition was adjusted in #291, which made the logic redundant.
Looking at the sniff, I believe the intention was to only flag the "return outside condition missing" when not all control structure paths had a
returnstatement, but this was never really properly checked as the only control structures taken into account areifcontrol structures.I believe it would be good to improve the sniff to handle more control structures (
switch,whileetc) and to not throw the "return outside condition missing" error if all possible paths have areturnstatement, but that is outside the scope of the current PR.I will add a note to this effect to the review ticket for this sniff - #520.