Skip to content

Commit

Permalink
Fixed bug #2810 : PHPCBF fails to fix file with empty statement at st…
Browse files Browse the repository at this point in the history
…art on control structure
  • Loading branch information
gsherwood committed Feb 18, 2020
1 parent 659bec3 commit 0547626
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<notes>
- The T_FN backfill now works more reliably so T_FN tokens only ever represent real arrow functions
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2810 : PHPCBF fails to fix file with empty statement at start on control structure
- Fixed bug #2848 : PSR12.Files.FileHeader false positive for file with mixed PHP and HTML and no file header
- Fixed bug #2849 : Generic.WhiteSpace.ScopeIndent false positive with arrow function inside array
- Fixed bug #2850 : Generic.PHP.LowerCaseKeyword complains __HALT_COMPILER is uppercase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr)

$nonSpace = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 2), null, true);

// Detect whether this is a semi-colons for a conditions in a `for()` control structure.
// Detect whether this is a semi-colon for a condition in a `for()` control structure.
$forCondition = false;
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$nestedParens = $tokens[$stackPtr]['nested_parenthesis'];
Expand All @@ -77,6 +77,7 @@ public function process(File $phpcsFile, $stackPtr)

if ($tokens[$nonSpace]['code'] === T_SEMICOLON
|| ($forCondition === true && $nonSpace === $tokens[$owner]['parenthesis_opener'])
|| (isset($tokens[$nonSpace]['scope_opener']) === true)
) {
// Empty statement.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ for ( ; ; ) {}
// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
for ( /* Deliberately left empty. */ ; $ptr >= 0; $ptr-- ) {}
for ( $i = 1 ; /* Deliberately left empty. */ ; $i++ ) {}

// This is an empty statement and should be ignored.
if ($foo) {
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ for ( ; ; ) {}
// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
for ( /* Deliberately left empty. */; $ptr >= 0; $ptr-- ) {}
for ( $i = 1; /* Deliberately left empty. */; $i++ ) {}

// This is an empty statement and should be ignored.
if ($foo) {
;
}

0 comments on commit 0547626

Please sign in to comment.