Skip to content

[Downgrade] A 2nd rule should modify the output from a previous rule in the set, but it doesn't happen #5962

Description

@leoloso

Bug Report

Subject Details
Rector version e.g. v0.10.1
Installed as composer dependency

Package symfony/cache has file vendor/symfony/cache/CacheItem.php, with this content (here):

final class CacheItem implements ItemInterface
{
    public function tag($tags): ItemInterface
    {
        // ...
        return $this;
    }
}

The interface ItemInterface has this content (here):

interface ItemInterface extends CacheItemInterface
{
    public function tag($tags): self;
}

The downgrade set for PHP 7.4 has these 2 rules, in this same order:

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();
    $services->set(DowngradeCovariantReturnTypeRector::class);
    $services->set(DowngradeSelfTypeDeclarationRector::class);
};

When downgrading CacheItem.php, function tag should be modified twice:

  1. DowngradeCovariantReturnTypeRector must first transform the return type, from ItemInterface to self
  2. DowngradeSelfTypeDeclarationRector should then remove the self return type

But the second step is not happening. As a consequence, after running the downgrade, function tag returns self, which is not accepted for PHP 7.3.

Minimal PHP Code Causing Issue

I tried to recreate the problem here, but the output is different:

https://getrector.org/demo/0d1b5ce4-c1a3-4fb8-bc3f-1fbe982f6e90

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions