From e551b248436723439c863f70569f43cc479fb67e Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 16 Dec 2019 11:46:10 -0500 Subject: [PATCH] =?UTF-8?q?Classes=20that=20just=20reference=20themselves?= =?UTF-8?q?=20aren=E2=80=99t=20used?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Expression/Call/StaticCallAnalyzer.php | 4 +++- tests/UnusedCodeTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php index 14af6c7fc..cdffd7e3e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php @@ -210,7 +210,9 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ $fq_class_name, new CodeLocation($source, $stmt->class), $statements_analyzer->getSuppressedIssues(), - false + $stmt->class instanceof PhpParser\Node\Name + && !count($stmt->class->parts) !== 1 + && in_array(strtolower($stmt->class->parts[0]), ['self', 'static'], true) )) { return false; } diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 563daf90e..2df93449a 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -929,6 +929,18 @@ class UnusedCodeTest extends TestCase }', 'error_message' => 'UnusedMethodCall', ], + 'unusedClassReferencesItself' => [ + ' 'UnusedClass', + ], ]; } }