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

Incorrect behavior of RemoveUnusedPrivateMethodRector #7547

Closed
alcohol opened this issue Oct 19, 2022 · 3 comments · Fixed by rectorphp/rector-src#3007
Closed

Incorrect behavior of RemoveUnusedPrivateMethodRector #7547

alcohol opened this issue Oct 19, 2022 · 3 comments · Fixed by rectorphp/rector-src#3007
Labels

Comments

@alcohol
Copy link

alcohol commented Oct 19, 2022

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/ed9a3a77-ec36-4654-ad47-d8dd8f4c73ba

<?php

final class DemoFile
{
    public function run(): array
    {
        return array_map(
            static fn (string $bar): string => self::returnFoo(),
            ['bar']
        );
    }
    
    private static function returnFoo(): string
    {
        return 'foo';
    }
}

Responsible rules

  • RemoveUnusedPrivateMethodRector

Expected Behavior

I would not expect the static method to be removed, but it is.

@alcohol alcohol added the bug label Oct 19, 2022
@samsonasik
Copy link
Member

It seems because it used in ArrowFunction, directly call seems not removed https://getrector.org/demo/87ee34dc-7bfd-4d09-9950-54e8f6a09e66

@samsonasik
Copy link
Member

It seems caused by multiple rules applied, tried using only RemoveUnusedPrivateMethodRector seems working ok https://getrector.org/demo/a7f2f91c-f791-4585-a48b-5079059cb765

@samsonasik
Copy link
Member

It seems due to combination rules:

Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
Rector\DeadCode\Rector\FunctionLike\RemoveDuplicatedIfReturnRector;

ref https://getrector.org/demo/66d03737-04b4-4345-89e5-074046ba496c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants