Skip to content

Commit

Permalink
Merge pull request #7025 from orklah/6256
Browse files Browse the repository at this point in the history
flag DeprecatedProperty on static fetch
  • Loading branch information
orklah committed Nov 29, 2021
2 parents 978a044 + 328dcb0 commit 466137a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -479,10 +481,13 @@ public static function analyze(
);
}

/**
* @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;
Expand Down
Expand Up @@ -261,6 +261,13 @@ public static function analyze(
return false;
}

AtomicPropertyFetchAnalyzer::checkPropertyDeprecation(
$prop_name,
$declaring_property_class,
$stmt,
$statements_analyzer
);

$class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
$property = $class_storage->properties[$prop_name];

Expand Down
15 changes: 15 additions & 0 deletions tests/DeprecatedAnnotationTest.php
Expand Up @@ -232,6 +232,21 @@ class DeprecatedClass{}
function foo(DeprecatedClass $deprecatedClass): void {}',
'error_message' => 'DeprecatedClass',
],
'deprecatedStaticPropertyFetch' => [
'<?php
class Bar
{
/**
* @deprecated
*/
public static bool $deprecatedPropery = false;
}
Bar::$deprecatedPropery;
',
'error_message' => 'DeprecatedProperty',
],
];
}
}

0 comments on commit 466137a

Please sign in to comment.