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;
}
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:
We want to use a
DeprecatedScopeResolverto ensure the code called in thedeprecatedCallableis within a deprecated scope. That's been accomplished in the PR with DeprecationHelperScope so far. However, it is includingcurrentCallable(we want to find and error on deprecated code within that callable.)Using a NodeVisitor it is possible to traverse the children in the
deprecatedCallabletree and set adeprecatedattribute. 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
NodeAwareDeprecatedScopeResolverwhichDeprecatedScopeResolverimplementations can also implement.DeprecatedScopeHelperneeds to be modified to support this: