rector icon indicating copy to clipboard operation
rector copied to clipboard

RenameVariableToMatchMethodCallReturnTypeRector only considers first return type

Open FloydOtsoko opened this issue 2 months ago • 2 comments

Bug Report

Subject Details
Rector version v 2.2.11

Description: If a Function returns ClassA|ClassB, Rector will always use the first one, to rename the Variables.

In my example I am using:

$ffmpeg = FFMpeg::create();

$video = $ffmpeg->open(Storage::disk('media')->path($this->path));

from FFMpeg::open header: * @return Audio|Video

Rector will rename my variable $video to $audio

Reproduce Demo does not make changes, probably because FFMpeg is not found. I have attached my console output to the demo

https://getrector.com/demo/38133f09-9257-41cb-becd-0742d6edf8c2

Expected Behaviour

I expect Rector to allow $audio and $video as possible variable names in this case specific case.

For other similar cases, I expect Rector to allow all possible return types as variable names

FloydOtsoko avatar Dec 04 '25 12:12 FloydOtsoko

Hi, thanks for reporting.

Could you update the demo to work with generic example? Without any external deps. Any union type and single method will do here. Ideally 5-10 lines max, so we can clearly extract broken parts.

TomasVotruba avatar Dec 04 '25 13:12 TomasVotruba

Hello,

I am sorry but I cannot. I have tried though: https://getrector.com/demo/fc709411-9d9e-48d0-ad73-5d56334da8f8

I have even renamed my variable to $illnamed but it does not trigger the Rule (I have even added it manually)

So I have created a public Project on my user here, where I am able to reproduce the error. It has only setup sail, rector and my rector config. Also I added the code which triggers the ill behaviour.

I am sorry for the inconvenience but I am not able to reproduce the error in the Online Demo. If a working online demo showcasing the error is mandatory, I will just ignore the file in my project and you can close the issue.

FloydOtsoko avatar Dec 09 '25 11:12 FloydOtsoko