From 270a8cf2aa440d2ab597090fdce80f50c826de5c Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 9 Dec 2024 11:56:20 -0300 Subject: [PATCH 1/2] 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. --- WordPress/Sniffs/WP/I18nSniff.php | 4 ++-- WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index bf9b9936e..33158ed08 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -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; } @@ -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; diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 995216a56..f9b5038b7 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -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 ); } From 55c134248f09bfee76479fcf0e52059ce82b34be Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 9 Dec 2024 12:01:11 -0300 Subject: [PATCH 2/2] 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. --- WordPress/Sniffs/Security/EscapeOutputSniff.php | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 92c1b2ef0..7861940ca 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -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: