This is a tidy-up. It does not change what the sniff reports.
AlwaysReturnInFilterSniff::isInsideIfConditonal() decides whether a return in a filter callback sits inside an if. It has a guard for a token that has no conditions array, but the guard comes after two end() calls that have already read that array, so it protects nothing. PHP_CodeSniffer sets conditions on every token, so the guard is not needed in the first place.
The reset() call between the two has no effect on the result either. It only undoes the array pointer move that end() made on the shared token array.
The method can read the array once, return false when the innermost condition is a function or closure, and otherwise return in_array( T_IF, $conditions, true ).
@GaryJones spotted this while reviewing #901. It was left out of that PR because that one only adds return types.
This is a tidy-up. It does not change what the sniff reports.
AlwaysReturnInFilterSniff::isInsideIfConditonal()decides whether areturnin a filter callback sits inside anif. It has a guard for a token that has noconditionsarray, but the guard comes after twoend()calls that have already read that array, so it protects nothing. PHP_CodeSniffer setsconditionson every token, so the guard is not needed in the first place.The
reset()call between the two has no effect on the result either. It only undoes the array pointer move thatend()made on the shared token array.The method can read the array once, return
falsewhen the innermost condition is a function or closure, and otherwise returnin_array( T_IF, $conditions, true ).@GaryJones spotted this while reviewing #901. It was left out of that PR because that one only adds return types.