Skip to content

Commit

Permalink
PSR12/DeclareStatement - handle parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Feb 8, 2024
1 parent 2d90233 commit 7f5c88a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Standards/PSR12/Sniffs/Files/DeclareStatementSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
// Safeguard sniff handles parse error/live coding correctly.
declare(strict_types=

0 comments on commit 7f5c88a

Please sign in to comment.