From 9de9c128514f6ddf66db79738c0b7d6c084775f1 Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 29 Nov 2021 23:32:27 +0100 Subject: [PATCH 1/2] flag DeprecatedProperty on static fetch --- .../Fetch/AtomicPropertyFetchAnalyzer.php | 7 ++++++- .../Fetch/StaticPropertyFetchAnalyzer.php | 7 +++++++ tests/DeprecatedAnnotationTest.php | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index 5166cc16c..52265878b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -2,6 +2,8 @@ namespace Psalm\Internal\Analyzer\Statements\Expression\Fetch; use PhpParser; +use PhpParser\Node\Expr\PropertyFetch; +use PhpParser\Node\Expr\StaticPropertyFetch; use Psalm\CodeLocation; use Psalm\Config; use Psalm\Context; @@ -483,10 +485,13 @@ class AtomicPropertyFetchAnalyzer ); } + /** + * @param PropertyFetch|StaticPropertyFetch $stmt + */ public static function checkPropertyDeprecation( string $prop_name, string $declaring_property_class, - PhpParser\Node\Expr\PropertyFetch $stmt, + PhpParser\Node\Expr $stmt, StatementsAnalyzer $statements_analyzer ): void { $property_id = $declaring_property_class . '::$' . $prop_name; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php index b1226382e..fb295606e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php @@ -265,6 +265,13 @@ class StaticPropertyFetchAnalyzer return false; } + AtomicPropertyFetchAnalyzer::checkPropertyDeprecation( + $stmt->name->name, + $declaring_property_class, + $stmt, + $statements_analyzer + ); + $class_storage = $codebase->classlike_storage_provider->get($declaring_property_class); $property = $class_storage->properties[$prop_name]; diff --git a/tests/DeprecatedAnnotationTest.php b/tests/DeprecatedAnnotationTest.php index b7845eb0b..c703542b8 100644 --- a/tests/DeprecatedAnnotationTest.php +++ b/tests/DeprecatedAnnotationTest.php @@ -232,6 +232,21 @@ class DeprecatedAnnotationTest extends TestCase function foo(DeprecatedClass $deprecatedClass): void {}', 'error_message' => 'DeprecatedClass', ], + 'deprecatedStaticPropertyFetch' => [ + ' 'DeprecatedProperty', + ], ]; } } From 328dcb093b0714ee65e63526cb1fa24fdb71f11a Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 29 Nov 2021 23:41:47 +0100 Subject: [PATCH 2/2] fix variable name --- .../Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php index fb295606e..ea4903795 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php @@ -266,7 +266,7 @@ class StaticPropertyFetchAnalyzer } AtomicPropertyFetchAnalyzer::checkPropertyDeprecation( - $stmt->name->name, + $prop_name, $declaring_property_class, $stmt, $statements_analyzer