Skip to content

[DeadCode] Keep empty method when parent class or interface is out of analyzed scope - #8433

Closed
TomasVotruba wants to merge 1 commit into
mainfrom
fix-empty-method-unresolvable-parent
Closed

[DeadCode] Keep empty method when parent class or interface is out of analyzed scope#8433
TomasVotruba wants to merge 1 commit into
mainfrom
fix-empty-method-unresolvable-parent

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9881

RemoveEmptyClassMethodRector removed an empty method whose abstract requirement lives in a parent class or interface located outside the analyzed paths. Reflection cannot see the out-of-scope parent, so the rule wrongly treated the method as unnecessary.

Before (analyzing only the child directory, AbstractPosting out of scope):

final class SAPPosting extends AbstractPosting
{
    protected function submitPosting(Posting $posting): void
    {
    }
}

was reduced to an empty class, breaking the abstract requirement.

Now the method is kept when:

  • it is protected and the parent class cannot be resolved (typical abstract override), or
  • an implemented interface is out of scope.

Public methods on classes extending an unresolvable framework base (e.g. Presenter/Controller) still get removed as before, so existing behavior is preserved.

https://claude.ai/code/session_01QswFbKfL2DRR9FTdAAKZPL

… analyzed scope

RemoveEmptyClassMethodRector removed an empty method whose abstract requirement
lives in a parent class or interface outside the analyzed paths, because the
reflection could not see it. Keep the method when the parent class cannot be
resolved (protected override) or an implemented interface is out of scope.

Fixes rectorphp/rector#9881

Claude-Session: https://claude.ai/code/session_01QswFbKfL2DRR9FTdAAKZPL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

RemoveEmptyClassMethodRector removes empty method in child class required by parent if parent is not in current analyze scope

1 participant