Skip to content
Browse files

Fixed bug #20123 : PSR2 complains about an empty second statement in …

…for-loop
  • Loading branch information...
1 parent 0bce916 commit 69389641c04f0534abf75890fe9d184bf1c0ae92 @gsherwood gsherwood committed Nov 15, 2013
View
8 CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php
@@ -94,7 +94,9 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $stackPtr, 'SpacingBeforeFirst');
}
- if ($tokens[($firstSemicolon + 1)]['code'] !== T_WHITESPACE) {
+ if ($tokens[($firstSemicolon + 1)]['code'] !== T_WHITESPACE
+ && $tokens[($firstSemicolon + 1)]['code'] !== T_SEMICOLON
+ ) {
$error = 'Expected 1 space after first semicolon of FOR loop; 0 found';
$phpcsFile->addError($error, $stackPtr, 'NoSpaceAfterFirst');
} else {
@@ -109,7 +111,9 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$secondSemicolon = $phpcsFile->findNext(T_SEMICOLON, ($firstSemicolon + 1));
if ($secondSemicolon !== false) {
- if ($tokens[($secondSemicolon - 1)]['code'] === T_WHITESPACE) {
+ if ($tokens[($secondSemicolon - 1)]['code'] === T_WHITESPACE
+ && $tokens[($firstSemicolon + 1)]['code'] !== T_SEMICOLON
+ ) {
$error = 'Space found before second semicolon of FOR loop';
$phpcsFile->addError($error, $stackPtr, 'SpacingBeforeSecond');
}
View
5 CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.inc
@@ -27,4 +27,9 @@ for ($i = 0; $i < 10;) {
for ($i = 0; $i < 10; ) {
}
+for ($i = 0; ; $i++) {
+}
+for ($i = 0;; $i++) {
+}
+
?>
View
5 CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.js
@@ -32,3 +32,8 @@ for (var i = 0; i < 10;) {
}
for (var i = 0; i < 10; ) {
}
+
+for (var i = 0; ; i++) {
+}
+for (var i = 0;; i++) {
+}
View
2 CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.php
@@ -53,6 +53,7 @@ public function getErrorList($testFile='ForLoopDeclarationUnitTest.inc')
17 => 2,
21 => 6,
27 => 1,
+ 30 => 1,
);
break;
case 'ForLoopDeclarationUnitTest.js':
@@ -63,6 +64,7 @@ public function getErrorList($testFile='ForLoopDeclarationUnitTest.inc')
15 => 2,
19 => 6,
33 => 1,
+ 36 => 1,
);
break;
default:
View
1 package.xml
@@ -37,6 +37,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Exit statements are now recognised as valid closers for CASE and DEFAULT blocks
- Fixed bug #20097 : CLI.php throws error in php 5.2
- Fixed bug #20100 : incorrect Function mysql() has been deprecated report
+ - Fixed bug #20123 : PSR2 complains about an empty second statement in for-loop
</notes>
<contents>
<dir name="/">

0 comments on commit 6938964

Please sign in to comment.
Something went wrong with that request. Please try again.