diff --git a/src/Standards/PSR12/Sniffs/Files/DeclareStatementSniff.php b/src/Standards/PSR12/Sniffs/Files/DeclareStatementSniff.php index b59d6c5cdb..d9615f9a4e 100644 --- a/src/Standards/PSR12/Sniffs/Files/DeclareStatementSniff.php +++ b/src/Standards/PSR12/Sniffs/Files/DeclareStatementSniff.php @@ -110,6 +110,12 @@ public function process(File $phpcsFile, $stackPtr) // There should be no space between equal sign and directive value. $value = $phpcsFile->findNext(T_WHITESPACE, ($equals + 1), null, true); + + if ($value === false) { + // Live coding / parse error. + return; + } + if ($equals !== false) { if ($tokens[($equals + 1)]['type'] !== 'T_LNUMBER') { $error = 'Expected no space between equal sign and the directive value in a declare statement'; diff --git a/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.inc b/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.1.inc similarity index 100% rename from src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.inc rename to src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.1.inc diff --git a/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.inc.fixed b/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.1.inc.fixed similarity index 100% rename from src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.inc.fixed rename to src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.1.inc.fixed diff --git a/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.2.inc b/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.2.inc new file mode 100644 index 0000000000..01c3a016db --- /dev/null +++ b/src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.2.inc @@ -0,0 +1,3 @@ + */ - public function getErrorList() + public function getErrorList($testFile='') { - return [ - 2 => 1, - 3 => 1, - 4 => 1, - 5 => 2, - 6 => 1, - 7 => 1, - 9 => 2, - 10 => 1, - 11 => 3, - 12 => 2, - 13 => 1, - 14 => 2, - 16 => 3, - 19 => 3, - 22 => 1, - 24 => 1, - 26 => 3, - 28 => 3, - 34 => 2, - 43 => 1, - 46 => 1, - 47 => 1, - 49 => 1, - ]; + switch ($testFile) { + case 'DeclareStatementUnitTest.1.inc': + return [ + 2 => 1, + 3 => 1, + 4 => 1, + 5 => 2, + 6 => 1, + 7 => 1, + 9 => 2, + 10 => 1, + 11 => 3, + 12 => 2, + 13 => 1, + 14 => 2, + 16 => 3, + 19 => 3, + 22 => 1, + 24 => 1, + 26 => 3, + 28 => 3, + 34 => 2, + 43 => 1, + 46 => 1, + 47 => 1, + 49 => 1, + ]; + default: + return []; + }//end switch }//end getErrorList()