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

Merge pull request #10518 from samlitowitz/issue-10490

Deprecated Template Classes are not ignored by @psalm-suppress DeprecatedClass
This commit is contained in:
orklah 2024-01-10 22:01:02 +01:00 committed by GitHub
commit 17cd6a7968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -350,7 +350,7 @@ final class ClassAnalyzer extends ClassLikeAnalyzer
null,
true,
),
$this->getSuppressedIssues(),
$storage->getSuppressedIssuesForTemplateExtendParams() + $this->getSuppressedIssues(),
);
}
}

View File

@ -10,11 +10,13 @@ use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\MethodIdentifier;
use Psalm\Internal\Type\TypeAlias\ClassTypeAlias;
use Psalm\Issue\CodeIssue;
use Psalm\Issue\DeprecatedClass;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;
use function array_values;
use function in_array;
final class ClassLikeStorage implements HasAttributesInterface
{
@ -551,4 +553,22 @@ final class ClassLikeStorage implements HasAttributesInterface
return false;
}
/**
* @return array<int, string>
*/
public function getSuppressedIssuesForTemplateExtendParams(): array
{
$allowed_issue_types = [
DeprecatedClass::getIssueType(),
];
$suppressed_issues_for_template_extend_params = [];
foreach ($this->suppressed_issues as $offset => $suppressed_issue) {
if (!in_array($suppressed_issue, $allowed_issue_types, true)) {
continue;
}
$suppressed_issues_for_template_extend_params[$offset] = $suppressed_issue;
}
return $suppressed_issues_for_template_extend_params;
}
}

View File

@ -99,6 +99,24 @@ class DeprecatedAnnotationTest extends TestCase
public $property;
}
'],
'suppressDeprecatedClassOnTemplateType' => [
'code' => '<?php
/**
* @deprecated
*/
class TheDeprecatedClass {}
/**
* @template T
*/
class TheParentClass {}
/**
* @extends TheParentClass<TheDeprecatedClass>
* @psalm-suppress DeprecatedClass
*/
class TheChildClass extends TheParentClass {}
'],
];
}