diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php index 4c22a59b8b..ea3194373e 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php @@ -63,9 +63,11 @@ public function process(File $phpcsFile, $stackPtr) $scopeStart = $tokens[$stackPtr]['scope_opener']; $scopeEnd = $tokens[$stackPtr]['scope_closer']; - // Check that the closing brace is on it's own line. + // Check that the closing brace is on it's own line. Empty {} is always allowed. $lastContent = $phpcsFile->findPrevious(array(T_INLINE_HTML, T_WHITESPACE, T_OPEN_TAG), ($scopeEnd - 1), $scopeStart, true); - if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { + if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line'] + && $scopeEnd !== ($scopeStart + 1) + ) { $error = 'Closing brace must be on a line by itself'; $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'ContentBefore'); if ($fix === true) { diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc b/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc index de09a82bb2..579aa3a0ce 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc @@ -10,9 +10,11 @@ class Test { } - function test2() {} + function test2() {foo();} - private function _test3() + function test3() {} + + private function _test4() { } @@ -92,6 +94,8 @@ switch ($blah) { 1, 13 => 1, - 24 => 1, - 80 => 1, - 102 => 1, + 26 => 1, + 82 => 1, + 106 => 1, ); }//end getErrorList()