Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flag DeprecatedProperty on static fetch #7025

Merged
merged 2 commits into from Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -483,10 +485,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 @@ -265,6 +265,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',
],
];
}
}