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

[DeadCode] Skip fluent return $this on RemoveEmptyMethodCallRector #521

Merged
merged 4 commits into from
Jul 27, 2021

Conversation

samsonasik
Copy link
Member

Given the following code:

class SkipFluentReturnThis
{
    /**
     * @return $this
     */
    public function prepare()
    {
        return $this;
    }

    public function run()
    {
    }

   public function call(string $class)
   {
        /** @var SkipFluentReturnThis $obj */
        $obj = new $class();
        $obj->prepare()->run();
   }
}

class Extended extends SkipFluentReturnThis
{
    public function run()
    {
        echo 'hello';
    }
}

(new SkipFluentReturnThis())->call(Extended::class);

It currently got error:

1) Rector\Tests\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector\RemoveEmptyMethodCallRectorTest::test with data set #10 (Symplify\SmartFileSystem\SmartFileInfo Object (...))

Rector\Core\Exception\ShouldNotHappenException: Chain method calls cannot be removed this way. It would remove the whole tree of calls. Remove them manually by creating new parent node with no following method.

It should be skipped. Ref https://3v4l.org/P5pK2

@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba TomasVotruba merged commit 3a96b90 into main Jul 27, 2021
@TomasVotruba TomasVotruba deleted the skip-dynamic-object-method-call-return branch July 27, 2021 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants