Skip to content

Commit 11ea94d

Browse files
authored
Merge pull request #90 from PHPCSStandards/php-8.3/generic-unconditionalifstatement-tokenizer-php-bugs
PHP 8.3 | Tokenizer/PHP + Generic/UnconditionalIfStatement: bug fix
2 parents 0cea0cc + 6b1c30b commit 11ea94d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function process(File $phpcsFile, $stackPtr)
6464
$token = $tokens[$stackPtr];
6565

6666
// Skip if statement without body.
67-
if (isset($token['parenthesis_opener']) === false) {
67+
if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
6868
return;
6969
}
7070

src/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ if (true) {
1010

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

13-
}
13+
}
14+
15+
// Intentional parse error/live coding.
16+
// This needs to be the last test in the file.
17+
if(true

src/Tokenizers/PHP.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,14 +3131,16 @@ protected function processAdditional()
31313131
|| $this->tokens[$i]['code'] === T_FALSE
31323132
|| $this->tokens[$i]['code'] === T_NULL
31333133
) {
3134-
for ($x = ($i + 1); $i < $numTokens; $x++) {
3134+
for ($x = ($i + 1); $x < $numTokens; $x++) {
31353135
if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
31363136
// Non-whitespace content.
31373137
break;
31383138
}
31393139
}
31403140

3141-
if (isset($this->tstringContexts[$this->tokens[$x]['code']]) === true) {
3141+
if ($x !== $numTokens
3142+
&& isset($this->tstringContexts[$this->tokens[$x]['code']]) === true
3143+
) {
31423144
if (PHP_CODESNIFFER_VERBOSITY > 1) {
31433145
$line = $this->tokens[$i]['line'];
31443146
$type = $this->tokens[$i]['type'];

0 commit comments

Comments
 (0)