diff --git a/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php b/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php index 894fb21691..5b2df9e3cd 100644 --- a/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php +++ b/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php @@ -87,8 +87,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) } // Ignore the ELSE in ELSE IF. We'll process the IF part later. - if (($tokens[$stackPtr]['code'] === T_ELSE) && ($tokens[($stackPtr + 2)]['code'] === T_IF)) { - return; + if ($tokens[$stackPtr]['code'] === T_ELSE) { + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); + if ($tokens[$next]['code'] === T_IF) { + return; + } } if ($tokens[$stackPtr]['code'] === T_WHILE) { diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc index d704a8746d..e7f3b125b1 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc @@ -98,3 +98,10 @@ if ($this->allowShopping !== true): else: echo 'foo'; endif; + +// ELSE IF split over multiple lines (not inline) +if ($test) { +} else + if ($test) { + } else { + } diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed index 0089aa3e0c..3a170fc81b 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed @@ -99,3 +99,10 @@ if ($this->allowShopping !== true): else: echo 'foo'; endif; + +// ELSE IF split over multiple lines (not inline) +if ($test) { +} else + if ($test) { + } else { + } diff --git a/package.xml b/package.xml index fbba5d6e1a..86e81d98d9 100644 --- a/package.xml +++ b/package.xml @@ -47,6 +47,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #527 : Closure inside IF statement is not tokenized correctly - Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff - Fixed bug #554 : ScopeIndentSniff causes errors when encountering an unmatched parenthesis + - Fixed bug #558 : PHPCBF adds brace for ELSE IF split over multiple lines