-
Notifications
You must be signed in to change notification settings - Fork 20
Description
This stems from work in mglaman/phpstan-drupal#714 and mglaman/phpstan-drupal#659 in phpstan-drupal.
It's complicated, but it's based on this code:
$result = DeprecationHelper::backwardsCompatibleCall(
currentVersion: \Drupal::VERSION,
deprecatedVersion: '10.3',
currentCallable: fn() => Role::loadMultiple(),
deprecatedCallable: fn() => user_roles(),
);
We want to use a DeprecatedScopeResolver
to ensure the code called in the deprecatedCallable
is within a deprecated scope. That's been accomplished in the PR with DeprecationHelperScope so far. However, it is including currentCallable
(we want to find and error on deprecated code within that callable.)
Using a NodeVisitor it is possible to traverse the children in the deprecatedCallable
tree and set a deprecated
attribute. But, this attribute cannot be read using the Scope alone.
There are problems with backwards compatibility to modify \PHPStan\Rules\Deprecations\DeprecatedScopeResolver::isScopeDeprecated
. So, this is my idea.
Introduce NodeAwareDeprecatedScopeResolver
which DeprecatedScopeResolver
implementations can also implement.
interface NodeAwareDeprecatedScopeResolver
{
public function withNode(Node $node);
}
DeprecatedScopeHelper
needs to be modified to support this:
public function isScopeDeprecated(Scope $scope, Node $node): bool
{
foreach ($this->resolvers as $checker) {
if ($checker instanceof NodeAwareDeprecatedScopeResolver) {
$checker->withNode($node);
}
if ($checker->isScopeDeprecated($scope)) {
return true;
}
}
return false;
}