Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…Control Structure error
  • Loading branch information...
commit c18e898d2ed02c775bbc904e8cb66c87cd3b203f 1 parent 1ed1cfa
@gsherwood gsherwood authored
View
18 CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc
@@ -23,4 +23,20 @@ do {
if(true)
$someObject->{$name};
-?>
+if (true) :
+ $foo = true;
+endif;
+
+while (true) :
+ $foo = true;
+endwhile;
+
+for ($i; $i > 0; $i--) :
+ echo 'hello';
+endfor;
+
+foreach ($array as $element) :
+ echo 'hello';
+endforeach;
+
+?>
View
5 CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php
@@ -163,7 +163,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
- if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
+ if ($next !== false
+ && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET
+ && $tokens[$next]['code'] !== T_COLON
+ ) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement';
$phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
}
View
6 CodeSniffer/Standards/PEAR/Tests/ControlStructures/MultiLineConditionUnitTest.inc
@@ -136,4 +136,8 @@ if (array_key_exists($key, $value)
)
) {
}
-?>
+
+if (true) :
+ $foo = true;
+endif;
+?>
View
40 CodeSniffer/Tokenizers/PHP.php
@@ -38,8 +38,14 @@ class PHP_CodeSniffer_Tokenizers_PHP
*/
public $scopeOpeners = array(
T_IF => array(
- 'start' => array(T_OPEN_CURLY_BRACKET),
- 'end' => array(T_CLOSE_CURLY_BRACKET),
+ 'start' => array(
+ T_OPEN_CURLY_BRACKET,
+ T_COLON,
+ ),
+ 'end' => array(
+ T_CLOSE_CURLY_BRACKET,
+ T_ENDIF,
+ ),
'strict' => false,
'shared' => false,
'with' => array(),
@@ -73,15 +79,27 @@ class PHP_CodeSniffer_Tokenizers_PHP
'with' => array(),
),
T_FOR => array(
- 'start' => array(T_OPEN_CURLY_BRACKET),
- 'end' => array(T_CLOSE_CURLY_BRACKET),
+ 'start' => array(
+ T_OPEN_CURLY_BRACKET,
+ T_COLON,
+ ),
+ 'end' => array(
+ T_CLOSE_CURLY_BRACKET,
+ T_ENDFOR,
+ ),
'strict' => false,
'shared' => false,
'with' => array(),
),
T_FOREACH => array(
- 'start' => array(T_OPEN_CURLY_BRACKET),
- 'end' => array(T_CLOSE_CURLY_BRACKET),
+ 'start' => array(
+ T_OPEN_CURLY_BRACKET,
+ T_COLON,
+ ),
+ 'end' => array(
+ T_CLOSE_CURLY_BRACKET,
+ T_ENDFOREACH,
+ ),
'strict' => false,
'shared' => false,
'with' => array(),
@@ -122,8 +140,14 @@ class PHP_CodeSniffer_Tokenizers_PHP
'with' => array(),
),
T_WHILE => array(
- 'start' => array(T_OPEN_CURLY_BRACKET),
- 'end' => array(T_CLOSE_CURLY_BRACKET),
+ 'start' => array(
+ T_OPEN_CURLY_BRACKET,
+ T_COLON,
+ ),
+ 'end' => array(
+ T_CLOSE_CURLY_BRACKET,
+ T_ENDWHILE,
+ ),
'strict' => false,
'shared' => false,
'with' => array(),
View
1  package.xml
@@ -53,6 +53,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- PSR1 ClassDeclarationSniff no longer throws an error for non-namespaced code if PHP version is less than 5.3.0
- Fixed bug #19616 : Nested switches cause false error in PSR2
- Fixed bug #19629 : PSR2 error for inline comments on multi-line argument lists
+ - Fixed bug #19644 : Alternative syntax, e.g. if/endif triggers Inline Control Structure error
</notes>
<contents>
<dir name="/">
Please sign in to comment.
Something went wrong with that request. Please try again.