Skip to content

Commit

Permalink
Fix #2028 - warn when using deprecated class in function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 22, 2019
1 parent 855ab35 commit 4fcbc0f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Psalm/Type/Atomic/TNamedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ public function check(
return false;
}

if ($codebase->classlike_storage_provider->has($this->value)) {
$class_storage = $codebase->classlike_storage_provider->get($this->value);

if ($class_storage->deprecated) {
if (\Psalm\IssueBuffer::accepts(
new \Psalm\Issue\DeprecatedClass(
'Class ' . $this->value . ' is marked as deprecated',
$code_location,
$this->value
),
$source->getSuppressedIssues()
)) {
// fall through
}
}
}

$this->checkIntersectionTypes(
$source,
$code_location,
Expand Down
10 changes: 10 additions & 0 deletions tests/DeprecatedAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ class Foo {}
echo Foo::class;',
'error_message' => 'DeprecatedClass',
],
'deprecatedClassAsParam' => [
'<?php
/**
* @deprecated
*/
class DeprecatedClass{}
function foo(DeprecatedClass $deprecatedClass): void {}',
'error_message' => 'DeprecatedClass',
],
];
}
}

0 comments on commit 4fcbc0f

Please sign in to comment.