diff --git a/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php b/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php index 978fba73a6..ccf902fd0e 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 7321e8be42..68a9ab76ec 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -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'];