Skip to content

Commit

Permalink
Merge pull request #1665 from WordPress-Coding-Standards/feature/glob…
Browse files Browse the repository at this point in the history
…alvarsoverride-implement-is-foreach-as

GlobalVariablesOverride: implement the Sniff::is_foreach_as() method
  • Loading branch information
GaryJones authored Mar 28, 2019
2 parents 15b7ffb + 2600112 commit 3ba3005
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,8 @@ protected function process_global_statement( $stackPtr, $in_function_scope ) {
}

// Check if this is a variable assignment within a `foreach()` declaration.
if ( isset( $this->tokens[ $ptr ]['nested_parenthesis'] ) ) {
$nested_parenthesis = $this->tokens[ $ptr ]['nested_parenthesis'];
$close_parenthesis = end( $nested_parenthesis );
if ( isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] )
&& \T_FOREACH === $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code']
&& ( false !== $previous
&& ( \T_DOUBLE_ARROW === $this->tokens[ $previous ]['code']
|| \T_AS === $this->tokens[ $previous ]['code'] ) )
) {
$this->maybe_add_error( $ptr );
}
if ( $this->is_foreach_as( $ptr ) === true ) {
$this->maybe_add_error( $ptr );
}
}
}
Expand Down

0 comments on commit 3ba3005

Please sign in to comment.