Skip to content

Incorrect behavior of SeparateMultiUseImportsRector, ClassPropertyAssignToConstructorPromotionRector, FinalizeClassesWithoutChildrenRector #8114

@zingimmick

Description

@zingimmick

Bug Report

The code private const PRIVATE_CONST = 1; that should have been kept was removed, and the code public $bar; that should have been deleted was retained.

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/70c5b6ad-566a-4a8e-beb8-c213568fca50

<?php

trait TraitA
{

}

trait TraitB
{
}

class TestClass
{
    use TraitA, TraitB;

    public const PUBLIC_CONST = 2;

    private const PRIVATE_CONST = 1;

    protected $foo;

    public $bar;

    public function __construct(int $foo, int $bar)
    {
        $this->foo = $foo;
        $this->bar = $bar;
    }

    public function getConst(): int
    {
        return self::PRIVATE_CONST ?? self::PUBLIC_CONST;
    }
}

Responsible rules

  • SeparateMultiUseImportsRector

  • ClassPropertyAssignToConstructorPromotionRector

  • FinalizeClassesWithoutChildrenRector

Expected Behavior

Keep the code private const PRIVATE_CONST = 1; and remove the code public $bar;.

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