Skip to content

Use ReplaceArgumentDefaultValueRector with constructor #7956

@GromNaN

Description

@GromNaN

Feature Request

I'd like to use ReplaceArgumentDefaultValueRector to make changes on __construct calls.

Given a class like this:

class SomeClass
{
    public const CONSTANT = 'const_value';

    public function __construct(string $arg) { /* ... */ }
}

The rule with this config has no effect:

$rectorConfig->ruleWithConfiguration(ReplaceArgumentDefaultValueRector::class, [
    new ReplaceArgumentDefaultValue('SomeClass', '__construct', 0, 'const_value', 'SomeClass::CONSTANT'),
]);

Diff

I'd like to make this change:

-$someObject = new SomeClass('const_value');
+$someObject = new SomeClass(SomeClass::CONSTANT);

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