Skip to content

Commit

Permalink
Remove unused variables from a few sniffs (#2514)
Browse files Browse the repository at this point in the history
* Remove unused variable passed as the third parameter to `preg_match()`

This commit removes three instances where a variable was passed to
`preg_match()` as the third parameter to fill it with the results of the
search, but later it was not used.

* EscapeOutput: remove unused variable `$end`

This commit removes the unnecessary initialization of the variable
`$end` at the beginning of the sniff code. Every single `case` statement
of the `switch` that follows either re-initialize the variable with a
different value or returns without using the variable.
  • Loading branch information
rodrigoprimo authored Dec 27, 2024
1 parent 9f9726a commit c028f32
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion WordPress/Sniffs/Security/EscapeOutputSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ public function getGroups() {
*/
public function process_token( $stackPtr ) {
$start = ( $stackPtr + 1 );
$end = $start;

switch ( $this->tokens[ $stackPtr ]['code'] ) {
case \T_STRING:
Expand Down
4 changes: 2 additions & 2 deletions WordPress/Sniffs/WP/I18nSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ private function check_for_translator_comment( $stackPtr, $matched_content, $par
continue;
}

if ( preg_match( self::SPRINTF_PLACEHOLDER_REGEX, $param_info['clean'], $placeholders ) === 1 ) {
if ( preg_match( self::SPRINTF_PLACEHOLDER_REGEX, $param_info['clean'] ) === 1 ) {
$needs_translators_comment = true;
break;
}
Expand Down Expand Up @@ -969,7 +969,7 @@ private function check_for_translator_comment( $stackPtr, $matched_content, $par
* @return bool
*/
private function is_translators_comment( $content ) {
if ( preg_match( '`^(?:(?://|/\*{1,2}) )?translators:`i', $content, $matches ) === 1 ) {
if ( preg_match( '`^(?:(?://|/\*{1,2}) )?translators:`i', $content ) === 1 ) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function process_token( $stackPtr ) {

// Move past end comments.
if ( $this->tokens[ $trailingContent ]['line'] === $this->tokens[ $scopeCloser ]['line'] ) {
if ( preg_match( '`^//[ ]?end`i', $this->tokens[ $trailingContent ]['content'], $matches ) > 0 ) {
if ( preg_match( '`^//[ ]?end`i', $this->tokens[ $trailingContent ]['content'] ) > 0 ) {
$scopeCloser = $trailingContent;
$trailingContent = $this->phpcsFile->findNext( \T_WHITESPACE, ( $trailingContent + 1 ), null, true );
}
Expand Down

0 comments on commit c028f32

Please sign in to comment.