diff --git a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php index ff19526a9b..efb8932bfa 100644 --- a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php +++ b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php @@ -170,15 +170,13 @@ public function process(File $phpcsFile, $stackPtr) $ignore[] = T_WHITESPACE; $next = $phpcsFile->findNext($ignore, ($openingBrace + 1), null, true); if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { - if ($next === $tokens[$stackPtr]['scope_closer']) { - // Ignore empty functions. - return; - } - - $error = 'Opening brace must be the last content on the line'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($openingBrace); + // Only throw this error when this is not an empty function. + if ($next !== $tokens[$stackPtr]['scope_closer']) { + $error = 'Opening brace must be the last content on the line'; + $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); + if ($fix === true) { + $phpcsFile->fixer->addNewline($openingBrace); + } } } diff --git a/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc b/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc index 3ae3b1ed0b..146f9cf6dd 100644 --- a/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc +++ b/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc @@ -261,3 +261,10 @@ class Issue3357WithComment // code here. } } + + function myFunction() + {} + function myFunction() + {} // Too many spaces indent with an empty function. + function myFunction() +{} // Too little spaces indent with an empty function. diff --git a/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed b/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed index f164c4934e..ac4929d7d5 100644 --- a/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed @@ -278,3 +278,10 @@ class Issue3357WithComment // code here. } } + + function myFunction() + {} + function myFunction() + {} // Too many spaces indent with an empty function. + function myFunction() + {} // Too little spaces indent with an empty function. diff --git a/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php b/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php index 10af4fd55a..c2dc221eff 100644 --- a/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php +++ b/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php @@ -61,6 +61,8 @@ public function getErrorList() 244 => 1, 252 => 1, 260 => 1, + 268 => 1, + 270 => 1, ]; }//end getErrorList()