Skip to content

RenamePropertyToMatchTypeRector should skip public properties to preserve public API #9125

@yoannblot

Description

@yoannblot

Bug Report

Subject Details
Rector version v2.0.12 (invoke vendor/bin/rector --version)

RenamePropertyToMatchTypeRector is renaming public properties, which should be avoided as they are part of the public API.

Minimal PHP Code Causing Issue

<?php

declare(strict_types=1);

namespace App\Domain;

use App\Domain\Common\PositiveInteger;

final readonly class Example
{
    public function __construct(
        public PositiveInteger $used,
    ) {}
}

After running Rector with RenamePropertyToMatchTypeRector:

    public function __construct(
-        public PositiveInteger $used,
+        public PositiveInteger $positiveInteger,
    ) {}

Expected Behaviour

RenamePropertyToMatchTypeRector should skip public properties as they're part of the public API, and renaming them could break dependent code. The rule should only apply to private and protected properties.

GitHub issue #7672 suggested this behavior is already implemented, but it doesn't seem to work in the current version.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions