Skip to content

Commit

Permalink
Merge pull request #90 from PHPCSStandards/php-8.3/generic-unconditio…
Browse files Browse the repository at this point in the history
…nalifstatement-tokenizer-php-bugs

PHP 8.3 | Tokenizer/PHP + Generic/UnconditionalIfStatement: bug fix
  • Loading branch information
jrfnl authored Dec 4, 2023
2 parents 0cea0cc + 6b1c30b commit 11ea94d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function process(File $phpcsFile, $stackPtr)
$token = $tokens[$stackPtr];

// Skip if statement without body.
if (isset($token['parenthesis_opener']) === false) {
if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ if (true) {

if (file_exists(__FILE__) === true) {

}
}

// Intentional parse error/live coding.
// This needs to be the last test in the file.
if(true
6 changes: 4 additions & 2 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -3131,14 +3131,16 @@ protected function processAdditional()
|| $this->tokens[$i]['code'] === T_FALSE
|| $this->tokens[$i]['code'] === T_NULL
) {
for ($x = ($i + 1); $i < $numTokens; $x++) {
for ($x = ($i + 1); $x < $numTokens; $x++) {
if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
// Non-whitespace content.
break;
}
}

if (isset($this->tstringContexts[$this->tokens[$x]['code']]) === true) {
if ($x !== $numTokens
&& isset($this->tstringContexts[$this->tokens[$x]['code']]) === true
) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$line = $this->tokens[$i]['line'];
$type = $this->tokens[$i]['type'];
Expand Down

0 comments on commit 11ea94d

Please sign in to comment.