From 09fbe99f5b2a6a604845df9647c986b1e49f0f1a Mon Sep 17 00:00:00 2001 From: tuqqu Date: Tue, 26 Sep 2023 20:59:06 +0200 Subject: [PATCH] Check for declare strict types block mode --- .../Analyzer/Statements/DeclareAnalyzer.php | 10 ++++++++ .../Internal/Analyzer/DeclareAnalyzerTest.php | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/DeclareAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/DeclareAnalyzer.php index 3a6da24af..fed7eb3e1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/DeclareAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/DeclareAnalyzer.php @@ -25,6 +25,16 @@ final class DeclareAnalyzer $declaration_key = (string) $declaration->key; if ($declaration_key === 'strict_types') { + if ($stmt->stmts !== null) { + IssueBuffer::maybeAdd( + new UnrecognizedStatement( + 'strict_types declaration must not use block mode', + new CodeLocation($statements_analyzer, $stmt), + ), + $statements_analyzer->getSuppressedIssues(), + ); + } + self::analyzeStrictTypesDeclaration($statements_analyzer, $declaration, $context); } elseif ($declaration_key === 'ticks') { self::analyzeTicksDeclaration($statements_analyzer, $declaration); diff --git a/tests/Internal/Analyzer/DeclareAnalyzerTest.php b/tests/Internal/Analyzer/DeclareAnalyzerTest.php index 9583ec807..fd6fefc1e 100644 --- a/tests/Internal/Analyzer/DeclareAnalyzerTest.php +++ b/tests/Internal/Analyzer/DeclareAnalyzerTest.php @@ -33,11 +33,27 @@ final class DeclareAnalyzerTest extends TestCase PHP, ]; + yield 'declareTicksBlockMode' => [ + 'code' => <<<'PHP' + [ 'code' => <<<'PHP' [ + 'code' => <<<'PHP' + 'UnrecognizedStatement', ]; + yield 'declareStrictTypesBlockMode' => [ + 'code' => <<<'PHP' + 'UnrecognizedStatement', + ]; + yield 'declareInvalidValueForTicks' => [ 'code' => <<<'PHP'