mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Merge pull request #10234 from tuqqu/block-mode-declare-check
Check for declare strict_types in block mode
This commit is contained in:
commit
83485f3fcf
@ -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);
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user