Skip to content

Commit e4f38f1

Browse files
committed
Generic/OpeningFunctionBraceKernighanRitchie: simplify logic to find end of the function declaration
When finding the end of the function declaration, 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`.
1 parent f3259e4 commit e4f38f1

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,9 @@ public function process(File $phpcsFile, $stackPtr)
7272
}
7373

7474
$openingBrace = $tokens[$stackPtr]['scope_opener'];
75-
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
76-
if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
77-
$use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
78-
if ($use !== false) {
79-
$openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
80-
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
81-
}
82-
}
8375

8476
// Find the end of the function declaration.
85-
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($openingBrace - 1), $closeBracket, true);
77+
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($openingBrace - 1), null, true);
8678

8779
$functionLine = $tokens[$prev]['line'];
8880
$braceLine = $tokens[$openingBrace]['line'];

0 commit comments

Comments
 (0)