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

Fix: double deprecated calls when already refactored #288

Merged
merged 2 commits into from
Jan 17, 2024

Conversation

bbrala
Copy link
Collaborator

@bbrala bbrala commented Jan 16, 2024

Description

This will fix the double deprecated calls. In the future we might need to refactor this, since something might actually need a nested deprecated call. That would be kinda nasty, but is an edge case that could happen (tm).

Codestyle is a bit noisy, annoying, but ah well.

To Test

Run test.

Drupal.org issue

https://www.drupal.org/project/rector/issues/3414169

This will fix the double deprecated calls. In the future we might need to refactor this, since something might actually need a nested deprecated call. That would be kinda nasty, but is an edge case that could happen (tm).
@bbrala bbrala requested a review from mglaman January 16, 2024 20:00
Comment on lines +34 to +57
protected function isInBackwardsCompatibleCall(Node $node): bool
{
if (!class_exists(DeprecationHelper::class)) {
return false;
}

$scope = $node->getAttribute(AttributeKey::SCOPE);

$callStack = $scope->getFunctionCallStackWithParameters();
if (count($callStack) === 0) {
return false;
}
[$function, $parameter] = $callStack[0];
if (!$function instanceof MethodReflection) {
return false;
}
if ($function->getName() !== 'backwardsCompatibleCall'
|| $function->getDeclaringClass()->getName() !== DeprecationHelper::class
) {
return false;
}

return $parameter !== null && $parameter->getName() === 'deprecatedCallable';
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Rector have a node visitor to just stop processing so that it doesn't handle nodes in this execution tree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think so yes. My old fix for phpstan would probably also work. This seemed easier is 0retty much why I used this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we're calling it in our base class, which all rules should extend. This is fine, but could lead to a "bug" if a rule didn't. But probably a minimal problem

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid point. But if it doesn't extend this class, it should not add the deprecation helper. But you are right though, it could slip through if we need some sort of exotic way to do things. Still would probably use the base class for the helpers.

@bbrala bbrala merged commit 4a2e739 into main Jan 17, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants