Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 2b1adc7ec33ea57e2cf342888c8d069ddd67c0d5 1 parent 371df28
Greg Sherwood authored October 31, 2012
15  CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php
@@ -114,15 +114,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
114 114
                     $phpcsFile->addError($error, $stackPtr, 'SpacingBeforeSecond');
115 115
                 }
116 116
 
117  
-                if ($tokens[($secondSemicolon + 1)]['code'] !== T_WHITESPACE) {
  117
+                if (($secondSemicolon + 1) !== $closingBracket
  118
+                    && $tokens[($secondSemicolon + 1)]['code'] !== T_WHITESPACE
  119
+                ) {
118 120
                     $error = 'Expected 1 space after second semicolon of FOR loop; 0 found';
119 121
                     $phpcsFile->addError($error, $stackPtr, 'NoSpaceAfterSecond');
120 122
                 } else {
121 123
                     if (strlen($tokens[($secondSemicolon + 1)]['content']) !== 1) {
122  
-                        $spaces = strlen($tokens[($firstSemicolon + 1)]['content']);
123  
-                        $error  = 'Expected 1 space after second semicolon of FOR loop; %s found';
  124
+                        $spaces = strlen($tokens[($secondSemicolon + 1)]['content']);
124 125
                         $data   = array($spaces);
125  
-                        $phpcsFile->addError($error, $stackPtr, 'SpacingAfterSecond', $data);
  126
+                        if (($secondSemicolon + 2) === $closingBracket) {
  127
+                            $error = 'Expected no space after second semicolon of FOR loop; %s found';
  128
+                            $phpcsFile->addError($error, $stackPtr, 'SpacingAfterSecondNoThird', $data);
  129
+                        } else {
  130
+                            $error = 'Expected 1 space after second semicolon of FOR loop; %s found';
  131
+                            $phpcsFile->addError($error, $stackPtr, 'SpacingAfterSecond', $data);
  132
+                        }
126 133
                     }
127 134
                 }
128 135
             }//end if
8  CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.inc
@@ -21,4 +21,10 @@ for ($i = 0;$i < 10;$i++) {
21 21
 for ( $i = 0 ;  $i < 10 ;  $i++ ) {
22 22
 }
23 23
 
24  
-?>
  24
+for ($i = 0; $i < 10;) {
  25
+}
  26
+
  27
+for ($i = 0; $i < 10; ) {
  28
+}
  29
+
  30
+?>
7  CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.js
@@ -26,4 +26,9 @@ for (var widgetid in this.loadedContents) {
26 26
     if (dfx.isset(widget) === true) {
27 27
         widget.loadAutoSaveCWidgetStore.setData('activeScreen', null);widget.getContents(this.loadedContents[widgetid], function() {self.widgetLoaded(widget.id);});
28 28
     }
29  
-}
  29
+}
  30
+
  31
+for (var i = 0; i < 10;) {
  32
+}
  33
+for (var i = 0; i < 10; ) {
  34
+}
2  CodeSniffer/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.php
@@ -52,6 +52,7 @@ public function getErrorList($testFile='ForLoopDeclarationUnitTest.inc')
52 52
                 14 => 2,
53 53
                 17 => 2,
54 54
                 21 => 6,
  55
+                27 => 1,
55 56
                );
56 57
              break;
57 58
         case 'ForLoopDeclarationUnitTest.js':
@@ -61,6 +62,7 @@ public function getErrorList($testFile='ForLoopDeclarationUnitTest.inc')
61 62
                 12 => 2,
62 63
                 15 => 2,
63 64
                 19 => 6,
  65
+                33 => 1,
64 66
                );
65 67
              break;
66 68
         default:
1  package.xml
@@ -65,6 +65,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
65 65
   - Fixed bug #19644 : Alternative syntax, e.g. if/endif triggers Inline Control Structure error
66 66
   - Fixed bug #19655 : Closures reporting as multi-line when they are not
67 67
   - Fixed bug #19675 : Improper indent of nested anonymous function bodies in a call
  68
+  - Fixed bug #19685 : PSR2 catch-22 with empty third statement in for loop
68 69
  </notes>
69 70
  <contents>
70 71
   <dir name="/">

0 notes on commit 2b1adc7

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