Skip to content

Commit

Permalink
Fixed bug #558 : PHPCBF adds brace for ELSE IF split over multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Apr 21, 2015
1 parent 0f06788 commit 18f98cc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit 18f98cc

Please sign in to comment.