Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug #19685 : PSR2 catch-22 with empty third statement in for loop

  • Loading branch information...
commit 2b1adc7ec33ea57e2cf342888c8d069ddd67c0d5 1 parent 371df28
Greg Sherwood gsherwood authored
15 CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php
View
@@ -114,15 +114,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $stackPtr, 'SpacingBeforeSecond');
}
- if ($tokens[($secondSemicolon + 1)]['code'] !== T_WHITESPACE) {
+ if (($secondSemicolon + 1) !== $closingBracket
+ && $tokens[($secondSemicolon + 1)]['code'] !== T_WHITESPACE
+ ) {
$error = 'Expected 1 space after second semicolon of FOR loop; 0 found';
$phpcsFile->addError($error, $stackPtr, 'NoSpaceAfterSecond');
} else {
if (strlen($tokens[($secondSemicolon + 1)]['content']) !== 1) {
- $spaces = strlen($tokens[($firstSemicolon + 1)]['content']);
- $error = 'Expected 1 space after second semicolon of FOR loop; %s found';
+ $spaces = strlen($tokens[($secondSemicolon + 1)]['content']);
$data = array($spaces);
- $phpcsFile->addError($error, $stackPtr, 'SpacingAfterSecond', $data);
+ if (($secondSemicolon + 2) === $closingBracket) {
+ $error = 'Expected no space after second semicolon of FOR loop; %s found';
+ $phpcsFile->addError($error, $stackPtr, 'SpacingAfterSecondNoThird', $data);
+ } else {
+ $error = 'Expected 1 space after second semicolon of FOR loop; %s found';
+ $phpcsFile->addError($error, $stackPtr, 'SpacingAfterSecond', $data);
+ }
}
}
}//end if
8 CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.inc
View
@@ -21,4 +21,10 @@ for ($i = 0;$i < 10;$i++) {
for ( $i = 0 ; $i < 10 ; $i++ ) {
}
-?>
+for ($i = 0; $i < 10;) {
+}
+
+for ($i = 0; $i < 10; ) {
+}
+
+?>
7 CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.js
View
@@ -26,4 +26,9 @@ for (var widgetid in this.loadedContents) {
if (dfx.isset(widget) === true) {
widget.loadAutoSaveCWidgetStore.setData('activeScreen', null);widget.getContents(this.loadedContents[widgetid], function() {self.widgetLoaded(widget.id);});
}
-}
+}
+
+for (var i = 0; i < 10;) {
+}
+for (var i = 0; i < 10; ) {
+}
2  CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.php
View
@@ -52,6 +52,7 @@ public function getErrorList($testFile='ForLoopDeclarationUnitTest.inc')
14 => 2,
17 => 2,
21 => 6,
+ 27 => 1,
);
break;
case 'ForLoopDeclarationUnitTest.js':
@@ -61,6 +62,7 @@ public function getErrorList($testFile='ForLoopDeclarationUnitTest.inc')
12 => 2,
15 => 2,
19 => 6,
+ 33 => 1,
);
break;
default:
1  package.xml
View
@@ -65,6 +65,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #19644 : Alternative syntax, e.g. if/endif triggers Inline Control Structure error
- Fixed bug #19655 : Closures reporting as multi-line when they are not
- Fixed bug #19675 : Improper indent of nested anonymous function bodies in a call
+ - Fixed bug #19685 : PSR2 catch-22 with empty third statement in for loop
</notes>
<contents>
<dir name="/">
Please sign in to comment.
Something went wrong with that request. Please try again.