Skip to content

[CodingStyle] Skip private parent methods in MakeInheritedMethodVisibilitySameAsParentRector#8114

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-private-parent-method-visibility
Jun 29, 2026
Merged

[CodingStyle] Skip private parent methods in MakeInheritedMethodVisibilitySameAsParentRector#8114
TomasVotruba merged 1 commit into
mainfrom
skip-private-parent-method-visibility

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Bug

MakeInheritedMethodVisibilitySameAsParentRector narrows a child method's visibility to match a private parent method of the same name. But private methods are not inherited — the child method does not override them, so there is no inheritance relationship and no reason to align visibility.

class ParentClassWithPrivateMethod
{
    private function run() {}
}

class PrivateClassParent extends ParentClassWithPrivateMethod
{
    public function run() {}   // independent public method, unrelated to the parent's private run()
}

The rule rewrote the child to private function run(), silently removing it from the public API even though PHP places no visibility constraint between a private parent method and a same-named child method.

Fix

Skip private parent methods when aligning visibility (they are not inherited). The now-unreachable private branches in the two helpers are removed.

The previous private.php.inc fixture encoded the buggy narrowing as expected output; it becomes a no-change fixture (skip_private_parent_method.php.inc).

Protected/public parent behavior is unchanged.

@TomasVotruba TomasVotruba merged commit c9ba93d into main Jun 29, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the skip-private-parent-method-visibility branch June 29, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant