From caac14c4a4d8c1f662013376a04d7b95d004871f Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 24 Feb 2023 03:28:58 -0400 Subject: [PATCH] Consistently report docblock issues on all classlikes Fixes vimeo/psalm#9365 --- .../Internal/Analyzer/InterfaceAnalyzer.php | 4 + src/Psalm/Internal/Analyzer/TraitAnalyzer.php | 5 ++ tests/TypeAnnotationTest.php | 83 +++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/InterfaceAnalyzer.php b/src/Psalm/Internal/Analyzer/InterfaceAnalyzer.php index 37d53354d22..dd2a107498b 100644 --- a/src/Psalm/Internal/Analyzer/InterfaceAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/InterfaceAnalyzer.php @@ -127,6 +127,10 @@ public function analyze(): void $class_storage->suppressed_issues + $this->getSuppressedIssues(), ); + foreach ($class_storage->docblock_issues as $docblock_issue) { + IssueBuffer::maybeAdd($docblock_issue); + } + $member_stmts = []; foreach ($this->class->stmts as $stmt) { if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod) { diff --git a/src/Psalm/Internal/Analyzer/TraitAnalyzer.php b/src/Psalm/Internal/Analyzer/TraitAnalyzer.php index 8bea62d068c..c6192a666a5 100644 --- a/src/Psalm/Internal/Analyzer/TraitAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/TraitAnalyzer.php @@ -5,6 +5,7 @@ use PhpParser\Node\Stmt\Trait_; use Psalm\Aliases; use Psalm\Context; +use Psalm\IssueBuffer; use function assert; @@ -80,5 +81,9 @@ public static function analyze(StatementsAnalyzer $statements_analyzer, Trait_ $ AttributesAnalyzer::TARGET_CLASS, $storage->suppressed_issues + $statements_analyzer->getSuppressedIssues(), ); + + foreach ($storage->docblock_issues as $docblock_issue) { + IssueBuffer::maybeAdd($docblock_issue); + } } } diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index a4dc169d510..497a051ac65 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -876,6 +876,89 @@ interface B {} class C implements B {}', 'error_message' => 'UndefinedDocblockClass', ], + 'duplicateKeyInArrayShapeOnInterfaceIsReported' => [ + 'code' => <<<'PHP' + 'InvalidDocblock', + ], + 'duplicateKeyInArrayShapeOnAClassIsReported' => [ + 'code' => <<<'PHP' + 'InvalidDocblock', + ], + 'duplicateKeyInArrayShapeOnATraitIsReported' => [ + 'code' => <<<'PHP' + 'InvalidDocblock', + ], + 'duplicateKeyInArrayShapeOnAnEnumIsReported' => [ + 'code' => <<<'PHP' + 'InvalidDocblock', + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; } }