Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed May 8, 2019
1 parent f50d9c3 commit 6cc41f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@ class EmptyPHPStatementSniff implements Sniff
{


/**
* Any token that should not have a scope_closer followed by a semi-colon.
*
* @var int[]
*/
private $conditionTokens = [
T_IF,
T_SWITCH,
T_CASE,
T_WHILE,
T_ELSE,
T_ELSEIF,
T_FOR,
T_FOREACH,
T_DO,
T_TRY,
T_CATCH,
T_FINALLY,
];


/**
* Returns an array of tokens this test wants to listen for.
*
Expand Down Expand Up @@ -74,15 +53,18 @@ public function process(File $phpcsFile, $stackPtr)
case 'T_SEMICOLON':
$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);

if ($prevNonEmpty === false
|| ($tokens[$prevNonEmpty]['code'] !== T_SEMICOLON
if ($prevNonEmpty === false) {
return;
}

if ($tokens[$prevNonEmpty]['code'] !== T_SEMICOLON
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG_WITH_ECHO)
&& $tokens[$prevNonEmpty]['code'] !== T_OPEN_TAG_WITH_ECHO
) {
// Still detect `if (foo) {};`.
if ($tokens[$prevNonEmpty]['code'] !== T_CLOSE_CURLY_BRACKET
|| isset($tokens[$prevNonEmpty]['scope_condition']) === false
|| in_array($tokens[$tokens[$prevNonEmpty]['scope_condition']]['code'], $this->conditionTokens) === false
|| in_array($tokens[$tokens[$prevNonEmpty]['scope_condition']]['code'], [T_CLOSURE, T_ANON_CLASS]) === true
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ while (true) {};
// Do not break closure and anonymous class;
$a = function () {};
$b = new class {};
echo $a{0};
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ while (true) {}
// Do not break closure and anonymous class;
$a = function () {};
$b = new class {};
echo $a{0};

0 comments on commit 6cc41f7

Please sign in to comment.