Skip to content

AlwaysReturnInFilter: isInsideIfConditonal() guards the conditions array after reading it #903

Description

@tomjn

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions