Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug #20248 : The Squiz_Sniffs_WhiteSpace_ControlStructureSpacin…

…gSniff sniff and empty scope
  • Loading branch information...
commit 8345e9d6dd5c6e4666d19a66d50d9ed3e9cc5114 1 parent 3415069
Greg Sherwood gsherwood authored
34 CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php
View
@@ -114,24 +114,26 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $scopeOpener, 'SpacingBeforeOpen');
}
- $lastContent = $phpcsFile->findPrevious(
- T_WHITESPACE,
- ($scopeCloser - 1),
- null,
- true
- );
-
- if ($tokens[$lastContent]['line'] !== ($tokens[$scopeCloser]['line'] - 1)) {
- $errorToken = $scopeCloser;
- for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
- if ($tokens[$i]['line'] < $tokens[$scopeCloser]['line']) {
- $errorToken = $i;
- break;
+ if ($firstContent !== $scopeCloser) {
+ $lastContent = $phpcsFile->findPrevious(
+ T_WHITESPACE,
+ ($scopeCloser - 1),
+ null,
+ true
+ );
+
+ if ($tokens[$lastContent]['line'] !== ($tokens[$scopeCloser]['line'] - 1)) {
+ $errorToken = $scopeCloser;
+ for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
+ if ($tokens[$i]['line'] < $tokens[$scopeCloser]['line']) {
+ $errorToken = $i;
+ break;
+ }
}
- }
- $error = 'Blank line found at end of control structure';
- $phpcsFile->addError($error, $errorToken, 'SpacingAfterClose');
+ $error = 'Blank line found at end of control structure';
+ $phpcsFile->addError($error, $errorToken, 'SpacingAfterClose');
+ }
}
$trailingContent = $phpcsFile->findNext(
4 CodeSniffer/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc
View
@@ -146,3 +146,7 @@ else if ($three) {
} // else do something
else {
}
+
+if ($one) {
+
+}
1  CodeSniffer/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php
View
@@ -61,6 +61,7 @@ public function getErrorList($testFile='ControlStructureSpacingUnitTest.inc')
113 => 2,
114 => 2,
118 => 1,
+ 150 => 1,
);
break;
case 'ControlStructureSpacingUnitTest.js':
1  package.xml
View
@@ -43,6 +43,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #20213 : Invalid error, Inline IF must be declared on single line
- Fixed bug #20225 : array_merge() that takes more than one line generates error
- Fixed bug #20230 : Squiz ControlStructureSpacing sniff assumes specific condition formatting
+ - Fixed bug #20248 : The Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff sniff and empty scope
- Fixed bug #20252 : Unitialized string offset when package name starts with underscore
</notes>
<contents>
Please sign in to comment.
Something went wrong with that request. Please try again.