diff --git a/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc b/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc index 231736ad35..d356c02382 100644 --- a/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc +++ b/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc @@ -104,4 +104,8 @@ if ($foo): elseif ($baz): $foo = 2; endif; +endif; + +if ($foo): +else if ($baz): $foo = 2; endif; \ No newline at end of file diff --git a/CodeSniffer/Tokenizers/PHP.php b/CodeSniffer/Tokenizers/PHP.php index 77e5480830..fe927d91a9 100644 --- a/CodeSniffer/Tokenizers/PHP.php +++ b/CodeSniffer/Tokenizers/PHP.php @@ -601,6 +601,13 @@ public function processAdditional(&$tokens, $eolChar) $numTokens = count($tokens); for ($i = ($numTokens - 1); $i >= 0; $i--) { + // Check for any unset scope conditions due to alternate IF/ENDIF syntax. + if (isset($tokens[$i]['scope_opener']) === true + && isset($tokens[$i]['scope_condition']) === false + ) { + $tokens[$i]['scope_condition'] = $tokens[$tokens[$i]['scope_opener']]['scope_condition']; + } + // Looking for functions that are actually closures. if ($tokens[$i]['code'] === T_FUNCTION && isset($tokens[$i]['scope_opener']) === true) { for ($x = ($i + 1); $x < $numTokens; $x++) {