1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Check for declare strict types block mode

This commit is contained in:
tuqqu 2023-09-26 20:59:06 +02:00
parent a70b2c0fbf
commit 09fbe99f5b
2 changed files with 35 additions and 0 deletions

View File

@ -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);

View File

@ -33,11 +33,27 @@ final class DeclareAnalyzerTest extends TestCase
PHP,
];
yield 'declareTicksBlockMode' => [
'code' => <<<'PHP'
<?php declare(ticks=5) {
$foo = 'bar';
}
PHP,
];
yield 'declareEncoding' => [
'code' => <<<'PHP'
<?php declare(encoding='ISO-8859-1');
PHP,
];
yield 'declareEncodingBlockMode' => [
'code' => <<<'PHP'
<?php declare(encoding='ISO-8859-1') {
$foo = 'bar';
}
PHP,
];
}
public function providerInvalidCodeParse(): iterable
@ -56,6 +72,15 @@ final class DeclareAnalyzerTest extends TestCase
'error_message' => 'UnrecognizedStatement',
];
yield 'declareStrictTypesBlockMode' => [
'code' => <<<'PHP'
<?php declare(strict_types=1) {
$foo = 'bar';
}
PHP,
'error_message' => 'UnrecognizedStatement',
];
yield 'declareInvalidValueForTicks' => [
'code' => <<<'PHP'
<?php declare(ticks='often');