Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks/AlwaysReturnInFilter: remove redundant condition #783

Merged

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Aug 25, 2023

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.

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.
@jrfnl jrfnl added this to the 3.0.0 milestone Aug 25, 2023
@jrfnl jrfnl requested a review from a team as a code owner August 25, 2023 18:31
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GaryJones GaryJones merged commit 5f34bbe into develop Aug 25, 2023
@GaryJones GaryJones deleted the fix/alwaysreturninfilter-remove-redundant-condition branch August 25, 2023 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants