Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/
Other
236 stars 40 forks source link

Hooks/AlwaysReturnInFilter: remove redundant condition #783

Closed jrfnl closed 1 year ago

jrfnl commented 1 year ago

Given that:

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.