1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Merge pull request #7025 from orklah/6256

flag DeprecatedProperty on static fetch
This commit is contained in:
orklah 2021-11-29 23:46:25 +01:00 committed by GitHub
commit 466137a4c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -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;
@ -479,10 +481,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;

View File

@ -261,6 +261,13 @@ class StaticPropertyFetchAnalyzer
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];

View File

@ -232,6 +232,21 @@ class DeprecatedAnnotationTest extends TestCase
function foo(DeprecatedClass $deprecatedClass): void {}',
'error_message' => 'DeprecatedClass',
],
'deprecatedStaticPropertyFetch' => [
'<?php
class Bar
{
/**
* @deprecated
*/
public static bool $deprecatedPropery = false;
}
Bar::$deprecatedPropery;
',
'error_message' => 'DeprecatedProperty',
],
];
}
}