Skip to content

Commit

Permalink
If an ELSE token is both an opener and closer, but it is followed by …
Browse files Browse the repository at this point in the history
…an IF, the scope_condition will be unset to allow it to act as an opener, but the condition will never be set again. So added a sanity check for this case.
  • Loading branch information
gsherwood committed Feb 13, 2014
1 parent 71526ae commit 2679192
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ if ($foo):
elseif ($baz):
$foo = 2;
endif;
endif;

if ($foo):
else if ($baz): $foo = 2;
endif;
7 changes: 7 additions & 0 deletions CodeSniffer/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 2679192

Please sign in to comment.