Skip to content

Incorrect behavior of RemoveUnusedPublicMethodParameterRector #8680

@stephanvierkant

Description

@stephanvierkant

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/fc2b72d3-8f36-4159-bc10-c3c3b4bd0614

<?php

declare(strict_types=1);

namespace App\MessageHandler\Cron;

use App\Model\Message\Job\DatabaseCleanupJob;
use App\Services\DatabaseCleanup;
use Symfony\Component\Lock\LockFactory;

#[\Symfony\Component\Messenger\Attribute\AsMessageHandler]
final readonly class DatabaseCleanupJobHandler
{
    private \Symfony\Component\Lock\LockInterface $lock;

    public function __construct(private DatabaseCleanup $cleanup, private LockFactory $lockFactory)
    {
        $this->lock = $this->lockFactory->createLock('database-cleanup-cron');
    }

    public function __invoke(DatabaseCleanupJob $cleanupJob) : void
    {
        if (! $this->lock->acquire()) {
            return;
        }

        $this->cleanup->execute();

        $this->lock->release();
    }
}

Responsible rules

  • RemoveUnusedPublicMethodParameterRector

Expected Behavior

I think there's nothing wrong with an unused parameter when using __invoke isn't it?

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