Skip to content

Incorrect behavior of RemoveUnusedPrivateMethodRector #8574

@hogejiro

Description

@hogejiro

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/81e4f9cb-57f5-4240-9fb9-73256732da21

<?php

final class SkipArrayCallablesSelfWithConstructor
{
    private array $args;

    public function __construct(...$args)
    {
        $this->args = $args;
    }

    public function run(): array
    {
        $array  = [3, 2, 1];

        usort($array, [self::class, 'sort']);

        return $array;
    }

    private function sort($a, $b)
    {
        return $a <=> $b;
    }
}

Responsible rules

  • RemoveUnusedPrivateMethodRector

Expected Behavior

Rectorphp should skip it.

In Addition

  • If $this is used instead of self::class in the above code, it will be skipped as intended. link
  • If a default argument is specified for __construct in the above code, even self::class will be skipped as intended. link

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