Skip to content

ReplaceArgumentDefaultValueRector - incorrect behavoir #9737

Description

@sreichel

Bug Report

Subject Details
Rector version 2.4.1
Rule ReplaceArgumentDefaultValueRector

Minimal PHP Code Causing Issue

https://getrector.com/demo/ee3028f5-5037-4449-9329-5b2aa1da98aa

Expected Behaviour

See comments in demo.


Notes:

  • ''testClass/replaceClass" works, but "self::" should be used
  • "testSelf/replaceSelf" looks good, but test4 goes wrong! This causes errors, const does not exist.
<?php

class Super
{
    public const SORT_ORDER_ASC = 'ASC';

	public const SORT_ORDER_DESC = 'DESC';
}

class Test1 extends Super
{
    public function testClass(string $dir = self::SORT_ORDER_ASC)
    {
        $this->replaceClass(self::SORT_ORDER_ASC);
    }

    public function testSelf(string $dir = self::SORT_ORDER_ASC)
    {
        $this->replaceSelf(self::SORT_ORDER_ASC);
    }

}

class Test2 extends Super
{
    public function testClass(string $dir = self::SORT_ORDER_ASC)
    {
        $this->replaceClass(self::SORT_ORDER_ASC);
    }

    public function testSelf(string $dir = self::SORT_ORDER_ASC)
    {
        $this->replaceSelf(self::SORT_ORDER_ASC);
    }

}

class Test3 extends Super
{
    public function testClass(string $dir = self::SORT_ORDER_ASC)
    {
        $this->replaceClass(self::SORT_ORDER_ASC);
    }
    
    public function testSelf(string $dir = self::SORT_ORDER_ASC)
    {
        $this->replaceSelf(self::SORT_ORDER_ASC);
    }
}

class Test4
{
    public function testClass(string $dir = Super::SORT_ORDER_ASC)
    {
        $test = new Test3();
        $test->replaceClass(Super::SORT_ORDER_ASC);
    }

    public function testSelf(string $dir = Super::SORT_ORDER_ASC)
    {
        $test = new Test3();
        $test->replaceSelf(Super::SORT_ORDER_ASC);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions