diff --git a/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php b/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php index cc9958c586..5c3f161c30 100644 --- a/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php +++ b/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php @@ -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; } diff --git a/src/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc b/src/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc index 1d980ae26c..0d220c96ed 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc +++ b/src/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc @@ -10,4 +10,8 @@ if (true) { if (file_exists(__FILE__) === true) { -} \ No newline at end of file +} + +// Intentional parse error/live coding. +// This needs to be the last test in the file. +if(true diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 0fa6d42c17..3b37ab0a29 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -3049,14 +3049,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'];