Skip to content

Commit

Permalink
Fix #1814 - warn about deprected ::class access
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 19, 2019
1 parent 0246f60 commit bdf54ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -155,6 +155,23 @@ public static function analyzeClassConst(
}

if ($stmt->name instanceof PhpParser\Node\Identifier && $stmt->name->name === 'class') {
if ($codebase->classExists($fq_class_name)) {
$class_const_storage = $codebase->classlike_storage_provider->get($fq_class_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
}
}
}

$stmt->inferredType = Type::getLiteralClassString($fq_class_name);

if ($codebase->store_node_types) {
Expand Down
10 changes: 10 additions & 0 deletions tests/DeprecatedAnnotationTest.php
Expand Up @@ -113,6 +113,16 @@ class Foo {
echo Foo::FOO;',
'error_message' => 'DeprecatedClass',
],
'deprecatedClassStringConstant' => [
'<?php
/**
* @deprecated
*/
class Foo {}
echo Foo::class;',
'error_message' => 'DeprecatedClass',
]
];
}
Expand Down

0 comments on commit bdf54ae

Please sign in to comment.