From 1d4c9d2a33cdc247b985ed3f2dd22764413648f6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 16 Jul 2024 01:15:00 +0200 Subject: [PATCH] PSR2/ClassDeclaration: remove some redundant code [2] In the original version of the sniff, only comments tokens after the close brace were ignored for the `CloseBraceSameLine` check. Since then the sniff has received numerous changes improving on that code to prevent false positives. Once such change was made in response to issue squizlabs/PHP_CodeSniffer 689, the fix adding ignoring for whitespace tokens to the code block. This makes the `$tokens[$nextContent]['content'] !== $phpcsFile->eolChar` check redundant as that condition can now never be true anymore (as it could only match on `T_WHITESPACE` tokens and those are now ignored). This change is covered by the tests previously added. --- src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php b/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php index 42cff38957..887c552edc 100644 --- a/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php +++ b/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php @@ -526,9 +526,7 @@ public function processClose(File $phpcsFile, $stackPtr) $ignoreTokens[] = T_COMMENT; $ignoreTokens[] = T_SEMICOLON; $nextContent = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true); - if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar - && $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line'] - ) { + if ($tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']) { $type = strtolower($tokens[$stackPtr]['content']); $error = 'Closing %s brace must be on a line by itself'; $data = [$type];