1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 22:01:48 +01:00

Merge pull request #9392 from weirdan/report-docblock-issues-on-traits-and-interfaces

This commit is contained in:
Bruce Weirdan 2023-02-24 03:40:00 -04:00 committed by GitHub
commit 1b2598c33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 0 deletions

View File

@ -127,6 +127,10 @@ class InterfaceAnalyzer extends ClassLikeAnalyzer
$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) {

View File

@ -5,6 +5,7 @@ namespace Psalm\Internal\Analyzer;
use PhpParser\Node\Stmt\Trait_;
use Psalm\Aliases;
use Psalm\Context;
use Psalm\IssueBuffer;
use function assert;
@ -80,5 +81,9 @@ class TraitAnalyzer extends ClassLikeAnalyzer
AttributesAnalyzer::TARGET_CLASS,
$storage->suppressed_issues + $statements_analyzer->getSuppressedIssues(),
);
foreach ($storage->docblock_issues as $docblock_issue) {
IssueBuffer::maybeAdd($docblock_issue);
}
}
}

View File

@ -876,6 +876,89 @@ class TypeAnnotationTest extends TestCase
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',
],
];
}
}