Skip to content

Commit 8352b5f

Browse files
authored
[naming] Skip public properties in RenamePropertyToMatchTypeRector to avoid external code conflicts (#6860)
1 parent fb815c5 commit 8352b5f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\Naming\Rector\Class_\RenamePropertyToMatchTypeRector\Fixture;
4+
5+
use Rector\Tests\Naming\Rector\Class_\RenamePropertyToMatchTypeRector\Source\EliteManager;
6+
7+
final class SkipPublicProperty
8+
{
9+
public function __construct(
10+
public EliteManager $entityMessenger
11+
) {
12+
}
13+
}

rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public function renamePropertyPromotion(Class_|Interface_ $classLike): bool
7171
continue;
7272
}
7373

74+
// skip public properties, as they can be used in external code
75+
if ($param->isPublic()) {
76+
continue;
77+
}
78+
7479
// promoted property
7580
$desiredPropertyName = $this->matchParamTypeExpectedNameResolver->resolve($param);
7681
if ($desiredPropertyName === null) {

rules/Naming/Rector/Class_/RenamePropertyToMatchTypeRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public function refactor(Node $node): ?Node
108108
private function refactorClassProperties(ClassLike $classLike): void
109109
{
110110
foreach ($classLike->getProperties() as $property) {
111+
// skip public properties, as they can be used in external code
112+
if ($property->isPublic()) {
113+
continue;
114+
}
115+
111116
$expectedPropertyName = $this->matchPropertyTypeExpectedNameResolver->resolve($property, $classLike);
112117
if ($expectedPropertyName === null) {
113118
continue;

0 commit comments

Comments
 (0)