Skip to content

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

Description

@raphaelincert

Bug Report

Subject Details
Rector version 2.6.6

Hi,
i am using rector on a huge project with many files and without directory restrictions it keeps crashing.
If i add directory restrictions via ->withPaths() and child classes with empty methods inside of that directory have parent classes that are not inside the directory that force the child to implement these methods, the methods will be removed due to the rule RemoveEmptyClassMethodRector.

Minimal PHP Code Causing Issue

Directory Structure
Running rector withPath() on /Common/Webservice/External/Implementations/ (with already 10k+ files)

.
└── Common
    ├── Posting
    │   └── AbstractPosting.php
    └── Webservice
        └── External
            └── Implementations
                └── SAP
                    └── S4HANA
                        └── PostingBL
                            └── SAPPosting.php

AbstractPosting.php

abstract class AbstractPosting
{
    abstract protected function submitPosting(Posting $posting): void;
}

SAPPosting.php

final class SAPPosting extends AbstractPosting implements AccountingListAggregatedPostingSubmit
{
    protected function submitPosting(Posting $posting): void
    {
    }
    
    public function submitPostingsToDateLimit(?DateTime $dt = null): void
    {
         // code happens here due to extra interface implement
    }
}

Working example:
https://getrector.com/demo/02764c42-e332-441d-9c77-7051cfe3617f
Not working (commented out file that is not in the same directory)
https://getrector.com/demo/250ff764-0243-48b9-9da8-714ced7dc9de

Expected Behaviour

Do not remove the empty methods.

Is it possible to tell rector to skip certain rules if for example the parent class or interface is not in the current analyze scope?

Thank you

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions