Skip to content

Commit 0547626

Browse files
committed
Fixed bug #2810 : PHPCBF fails to fix file with empty statement at start on control structure
1 parent 659bec3 commit 0547626

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2828
<notes>
2929
- The T_FN backfill now works more reliably so T_FN tokens only ever represent real arrow functions
3030
-- Thanks to Juliette Reinders Folmer for the patch
31+
- Fixed bug #2810 : PHPCBF fails to fix file with empty statement at start on control structure
3132
- Fixed bug #2848 : PSR12.Files.FileHeader false positive for file with mixed PHP and HTML and no file header
3233
- Fixed bug #2849 : Generic.WhiteSpace.ScopeIndent false positive with arrow function inside array
3334
- Fixed bug #2850 : Generic.PHP.LowerCaseKeyword complains __HALT_COMPILER is uppercase

src/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr)
5959

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

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

7878
if ($tokens[$nonSpace]['code'] === T_SEMICOLON
7979
|| ($forCondition === true && $nonSpace === $tokens[$owner]['parenthesis_opener'])
80+
|| (isset($tokens[$nonSpace]['scope_opener']) === true)
8081
) {
8182
// Empty statement.
8283
return;

src/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ for ( ; ; ) {}
2828
// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
2929
for ( /* Deliberately left empty. */ ; $ptr >= 0; $ptr-- ) {}
3030
for ( $i = 1 ; /* Deliberately left empty. */ ; $i++ ) {}
31+
32+
// This is an empty statement and should be ignored.
33+
if ($foo) {
34+
;
35+
}

src/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ for ( ; ; ) {}
2828
// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
2929
for ( /* Deliberately left empty. */; $ptr >= 0; $ptr-- ) {}
3030
for ( $i = 1; /* Deliberately left empty. */; $i++ ) {}
31+
32+
// This is an empty statement and should be ignored.
33+
if ($foo) {
34+
;
35+
}

0 commit comments

Comments
 (0)