From 286cd814b8e105a472d64d68a9aba524862809a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Tue, 26 Nov 2024 16:54:28 -0300 Subject: [PATCH] Generic/OpeningFunctionBraceKernighanRitchie: simplify logic to find end of the function signature When finding the end of the function signature, the sniff had an unnecessary block of code to change the `$end` parameter passed to `findPrevious()` when handling a closure with a `use` statement. Since we are looking for the first non-empty token before the opening curly brace, it is not necessary to change the value of the `$end` parameter. Actually, we don't even need to limit the search and we can pass `null` (the default value). The returned first non-empty token will be the same anyway regardless if `$end` is the closing parenthesis before `use`, after `use` or `null`. --- .../OpeningFunctionBraceKernighanRitchieSniff.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php index f8fa07582d..1e2df37d86 100644 --- a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php +++ b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php @@ -72,17 +72,9 @@ public function process(File $phpcsFile, $stackPtr) } $openingBrace = $tokens[$stackPtr]['scope_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - } - } // Find the end of the function declaration. - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($openingBrace - 1), $closeBracket, true); + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($openingBrace - 1), null, true); $functionLine = $tokens[$prev]['line']; $braceLine = $tokens[$openingBrace]['line'];