1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1803 - complain about DeprecatedClass when using its constants

This commit is contained in:
Brown 2019-06-18 16:21:04 -04:00
parent 22ae114baa
commit 10613192c9
2 changed files with 25 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use Psalm\Internal\FileManipulation\FileManipulationBuffer;
use Psalm\Codebase; use Psalm\Codebase;
use Psalm\CodeLocation; use Psalm\CodeLocation;
use Psalm\Context; use Psalm\Context;
use Psalm\Issue\DeprecatedClass;
use Psalm\Issue\DeprecatedConstant; use Psalm\Issue\DeprecatedConstant;
use Psalm\Issue\InaccessibleClassConstant; use Psalm\Issue\InaccessibleClassConstant;
use Psalm\Issue\ParentNotFound; use Psalm\Issue\ParentNotFound;
@ -293,7 +294,18 @@ class ConstFetchAnalyzer
$class_const_storage = $codebase->classlike_storage_provider->get($fq_class_name); $class_const_storage = $codebase->classlike_storage_provider->get($fq_class_name);
if (isset($class_const_storage->deprecated_constants[$stmt->name->name])) { if ($class_const_storage->deprecated) {
if (IssueBuffer::accepts(
new DeprecatedClass(
'Class ' . $fq_class_name . ' is deprecated',
new CodeLocation($statements_analyzer->getSource(), $stmt),
$fq_class_name
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
} elseif (isset($class_const_storage->deprecated_constants[$stmt->name->name])) {
if (IssueBuffer::accepts( if (IssueBuffer::accepts(
new DeprecatedConstant( new DeprecatedConstant(
'Constant ' . $const_id . ' is deprecated', 'Constant ' . $const_id . ' is deprecated',

View File

@ -102,6 +102,18 @@ class DeprecatedAnnotationTest extends TestCase
$a->foo = 5;', $a->foo = 5;',
'error_message' => 'DeprecatedProperty', 'error_message' => 'DeprecatedProperty',
], ],
'deprecatedClassConstant' => [
'<?php
/**
* @deprecated
*/
class Foo {
public const FOO = 5;
}
echo Foo::FOO;',
'error_message' => 'DeprecatedClass',
]
]; ];
} }
} }