Skip to content

Commit 2600112

Browse files
committed
GlobalVariablesOverride: implement the Sniff::is_foreach_as() method
Removing some code duplication.
1 parent 5f27d8e commit 2600112

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,8 @@ protected function process_global_statement( $stackPtr, $in_function_scope ) {
321321
}
322322

323323
// Check if this is a variable assignment within a `foreach()` declaration.
324-
if ( isset( $this->tokens[ $ptr ]['nested_parenthesis'] ) ) {
325-
$nested_parenthesis = $this->tokens[ $ptr ]['nested_parenthesis'];
326-
$close_parenthesis = end( $nested_parenthesis );
327-
if ( isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] )
328-
&& \T_FOREACH === $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code']
329-
&& ( false !== $previous
330-
&& ( \T_DOUBLE_ARROW === $this->tokens[ $previous ]['code']
331-
|| \T_AS === $this->tokens[ $previous ]['code'] ) )
332-
) {
333-
$this->maybe_add_error( $ptr );
334-
}
324+
if ( $this->is_foreach_as( $ptr ) === true ) {
325+
$this->maybe_add_error( $ptr );
335326
}
336327
}
337328
}

0 commit comments

Comments
 (0)