Skip to content

Incorrect Behavior of RemoveUnusedConstructorParamRector with Interfaces #8580

@splitbrain

Description

@splitbrain

Bug Report

Subject Details
Rector version 0.19.1

The RemoveUnusedConstructorParamRector removes parameters that are required by an interface contract.

Minimal PHP Code Causing Issue

<?php

Interface RectorTest {
    public function __construct(string $name, array $config);
}

abstract class RectorClass implements RectorTest {
    protected $name;

    public function __construct(string $name, array $config) {
        $this->name = $name;
    }
}

class Rector extends RectorClass {
    public function __construct(string $name, array $config) {
        parent::__construct($name, $config);

        if($config['type'] == 'a') {
            echo 'a';
        }
    }
}

The RemoveUnusedConstructorParamRector will remove the $config parameter in RectorClass resulting in an invalid method signature.

Expected Behaviour

Rector should not remove parameters required by interfaces.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions