Skip to content

Commit

Permalink
Merge pull request #9392 from weirdan/report-docblock-issues-on-trait…
Browse files Browse the repository at this point in the history
…s-and-interfaces
  • Loading branch information
weirdan committed Feb 24, 2023
2 parents 5f765a9 + caac14c commit 1b2598c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Analyzer/InterfaceAnalyzer.php
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Analyzer/TraitAnalyzer.php
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node\Stmt\Trait_;
use Psalm\Aliases;
use Psalm\Context;
use Psalm\IssueBuffer;

use function assert;

Expand Down Expand Up @@ -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);
}
}
}
83 changes: 83 additions & 0 deletions tests/TypeAnnotationTest.php
Expand Up @@ -876,6 +876,89 @@ interface B {}
class C implements B {}',
'error_message' => 'UndefinedDocblockClass',
],
'duplicateKeyInArrayShapeOnInterfaceIsReported' => [
'code' => <<<'PHP'
<?php
/**
* @psalm-type Attributes = array{
* name: string,
* email: string,
* email: string,
* }
*/
interface A {
/**
* @return Attributes
*/
public function getAttributes(): array;
}
PHP,
'error_message' => 'InvalidDocblock',
],
'duplicateKeyInArrayShapeOnAClassIsReported' => [
'code' => <<<'PHP'
<?php
/**
* @psalm-type Attributes = array{
* name: string,
* email: string,
* email: string,
* }
*/
class A {
/**
* @return Attributes
*/
public function getAttributes(): array {
return [];
}
}
PHP,
'error_message' => 'InvalidDocblock',
],
'duplicateKeyInArrayShapeOnATraitIsReported' => [
'code' => <<<'PHP'
<?php
/**
* @psalm-type Attributes = array{
* name: string,
* email: string,
* email: string,
* }
*/
trait A {
/**
* @return Attributes
*/
public function getAttributes(): array {
return [];
}
}
PHP,
'error_message' => 'InvalidDocblock',
],
'duplicateKeyInArrayShapeOnAnEnumIsReported' => [
'code' => <<<'PHP'
<?php
/**
* @psalm-type Attributes = array{
* name: string,
* email: string,
* email: string,
* }
*/
enum A {
case FOO;
}
PHP,
'error_message' => 'InvalidDocblock',
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}
}

0 comments on commit 1b2598c

Please sign in to comment.