Skip to content

Commit ab4bae2

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/EmptyPHPStatement: remove some unreachable code
* Removed two unreachable conditions. `$prevNonEmpty` will never be `false` as there will always be at least a PHP open tag token before the semicolon token. * Removed unreachable default case `$tokens[$stackPtr]['type']` will always be either `T_SEMICOLON` or `T_CLOSE_TAG` as those are the two tokens that this sniff listens for. So, the default case will never be reached.
1 parent 609ac10 commit ab4bae2

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/EmptyPHPStatementSniff.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ public function process(File $phpcsFile, $stackPtr)
5353
case 'T_SEMICOLON':
5454
$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
5555

56-
if ($prevNonEmpty === false) {
57-
return;
58-
}
59-
6056
if ($tokens[$prevNonEmpty]['code'] !== T_SEMICOLON
6157
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG
6258
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG_WITH_ECHO
@@ -128,9 +124,8 @@ public function process(File $phpcsFile, $stackPtr)
128124
case 'T_CLOSE_TAG':
129125
$prevNonEmpty = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
130126

131-
if ($prevNonEmpty === false
132-
|| ($tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG
133-
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG_WITH_ECHO)
127+
if ($tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG
128+
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG_WITH_ECHO
134129
) {
135130
return;
136131
}
@@ -150,10 +145,6 @@ public function process(File $phpcsFile, $stackPtr)
150145
$phpcsFile->fixer->endChangeset();
151146
}
152147
break;
153-
154-
default:
155-
// Deliberately left empty.
156-
break;
157148
}//end switch
158149

159150
}//end process()

0 commit comments

Comments
 (0)