Skip to content

Commit

Permalink
Generic.CodeAnalysis.EmptyPHPStatement now detects empty statements a…
Browse files Browse the repository at this point in the history
…t the start of control structures (ref #2810)
  • Loading branch information
gsherwood committed Feb 18, 2020
1 parent 19c8127 commit db617f1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
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
- Generic.CodeAnalysis.EmptyPHPStatement now detects empty statements at the start of control structures
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public function process(File $phpcsFile, $stackPtr)
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG_WITH_ECHO
) {
if ($tokens[$prevNonEmpty]['code'] !== T_CLOSE_CURLY_BRACKET
|| isset($tokens[$prevNonEmpty]['scope_condition']) === false
if (isset($tokens[$prevNonEmpty]['scope_condition']) === false) {
return;
}

if ($tokens[$prevNonEmpty]['scope_opener'] !== $prevNonEmpty
&& $tokens[$prevNonEmpty]['code'] !== T_CLOSE_CURLY_BRACKET
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ switch ( $a ) {
$a = function () {};
$b = new class {};
echo $a{0};

if ($foo) {
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ switch ( $a ) {
$a = function () {};
$b = new class {};
echo $a{0};

if ($foo) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getWarningList()
63 => 2,
71 => 1,
72 => 1,
80 => 1,
];

}//end getWarningList()
Expand Down

0 comments on commit db617f1

Please sign in to comment.