Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed bug #19644 : Alternative syntax, e.g. if/endif triggers Inline …

…Control Structure error
  • Loading branch information...
commit c18e898d2ed02c775bbc904e8cb66c87cd3b203f 1 parent 1ed1cfa
Greg Sherwood authored October 17, 2012
18  CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc
@@ -23,4 +23,20 @@ do {
23 23
 if(true)
24 24
   $someObject->{$name};
25 25
 
26  
-?>
  26
+if (true) :
  27
+    $foo = true;
  28
+endif;
  29
+
  30
+while (true) :
  31
+    $foo = true;
  32
+endwhile;
  33
+
  34
+for ($i; $i > 0; $i--) :
  35
+    echo 'hello';
  36
+endfor;
  37
+
  38
+foreach ($array as $element) :
  39
+    echo 'hello';
  40
+endforeach;
  41
+
  42
+?>
5  CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php
@@ -163,7 +163,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
163 163
 
164 164
         // And just in case they do something funny before the brace...
165 165
         $next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
166  
-        if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
  166
+        if ($next !== false
  167
+            && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET
  168
+            && $tokens[$next]['code'] !== T_COLON
  169
+        ) {
167 170
             $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement';
168 171
             $phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
169 172
         }
6  CodeSniffer/Standards/PEAR/Tests/ControlStructures/MultiLineConditionUnitTest.inc
@@ -136,4 +136,8 @@ if (array_key_exists($key, $value)
136 136
     )
137 137
 ) {
138 138
 }
139  
-?>
  139
+
  140
+if (true) :
  141
+    $foo = true;
  142
+endif;
  143
+?>
40  CodeSniffer/Tokenizers/PHP.php
@@ -38,8 +38,14 @@ class PHP_CodeSniffer_Tokenizers_PHP
38 38
      */
39 39
     public $scopeOpeners = array(
40 40
                             T_IF            => array(
41  
-                                                'start'  => array(T_OPEN_CURLY_BRACKET),
42  
-                                                'end'    => array(T_CLOSE_CURLY_BRACKET),
  41
+                                                'start'  => array(
  42
+                                                             T_OPEN_CURLY_BRACKET,
  43
+                                                             T_COLON,
  44
+                                                            ),
  45
+                                                'end'    => array(
  46
+                                                             T_CLOSE_CURLY_BRACKET,
  47
+                                                             T_ENDIF,
  48
+                                                            ),
43 49
                                                 'strict' => false,
44 50
                                                 'shared' => false,
45 51
                                                 'with'   => array(),
@@ -73,15 +79,27 @@ class PHP_CodeSniffer_Tokenizers_PHP
73 79
                                                 'with'   => array(),
74 80
                                                ),
75 81
                             T_FOR           => array(
76  
-                                                'start'  => array(T_OPEN_CURLY_BRACKET),
77  
-                                                'end'    => array(T_CLOSE_CURLY_BRACKET),
  82
+                                                'start'  => array(
  83
+                                                             T_OPEN_CURLY_BRACKET,
  84
+                                                             T_COLON,
  85
+                                                            ),
  86
+                                                'end'    => array(
  87
+                                                             T_CLOSE_CURLY_BRACKET,
  88
+                                                             T_ENDFOR,
  89
+                                                            ),
78 90
                                                 'strict' => false,
79 91
                                                 'shared' => false,
80 92
                                                 'with'   => array(),
81 93
                                                ),
82 94
                             T_FOREACH       => array(
83  
-                                                'start'  => array(T_OPEN_CURLY_BRACKET),
84  
-                                                'end'    => array(T_CLOSE_CURLY_BRACKET),
  95
+                                                'start'  => array(
  96
+                                                             T_OPEN_CURLY_BRACKET,
  97
+                                                             T_COLON,
  98
+                                                            ),
  99
+                                                'end'    => array(
  100
+                                                             T_CLOSE_CURLY_BRACKET,
  101
+                                                             T_ENDFOREACH,
  102
+                                                            ),
85 103
                                                 'strict' => false,
86 104
                                                 'shared' => false,
87 105
                                                 'with'   => array(),
@@ -122,8 +140,14 @@ class PHP_CodeSniffer_Tokenizers_PHP
122 140
                                                 'with'   => array(),
123 141
                                                ),
124 142
                             T_WHILE         => array(
125  
-                                                'start'  => array(T_OPEN_CURLY_BRACKET),
126  
-                                                'end'    => array(T_CLOSE_CURLY_BRACKET),
  143
+                                                'start'  => array(
  144
+                                                             T_OPEN_CURLY_BRACKET,
  145
+                                                             T_COLON,
  146
+                                                            ),
  147
+                                                'end'    => array(
  148
+                                                             T_CLOSE_CURLY_BRACKET,
  149
+                                                             T_ENDWHILE,
  150
+                                                            ),
127 151
                                                 'strict' => false,
128 152
                                                 'shared' => false,
129 153
                                                 'with'   => array(),
1  package.xml
@@ -53,6 +53,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
53 53
   - PSR1 ClassDeclarationSniff no longer throws an error for non-namespaced code if PHP version is less than 5.3.0
54 54
   - Fixed bug #19616 : Nested switches cause false error in PSR2
55 55
   - Fixed bug #19629 : PSR2 error for inline comments on multi-line argument lists
  56
+  - Fixed bug #19644 : Alternative syntax, e.g. if/endif triggers Inline Control Structure error
56 57
  </notes>
57 58
  <contents>
58 59
   <dir name="/">

0 notes on commit c18e898

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