8000 [Php82] Handle implicit public readonly on ReadOnlyClassRector (#6919) · rectorphp/rector-src@e02e813 · GitHub
[go: up one dir, main page]

Skip to content

Commit e02e813

Browse files
authored
[Php82] Handle implicit public readonly on ReadOnlyClassRector (#6919)
* [Php82] Handle implicit public readonly on ReadOnlyClassRector * Fix
1 parent 7a3af84 commit e02e813

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture;
4+
5+
final class ImplicitPublicReadonlyProperty
6+
{
7+
readonly string $foo;
8+
9+
public function __construct()
10+
{
11+
$this->foo = 'bar';
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture;
20+
21+
final readonly class ImplicitPublicReadonlyProperty
22+
{
23+
public string $foo;
24+
25+
public function __construct()
26+
{
27+
$this->foo = 'bar';
28+
}
29+
}
30+
31+
?>

rules/Privatization/NodeManipulator/VisibilityManipulator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ public function removeReadonly(Class_ | Property | Param $node): void
139139
if ($node instanceof Param && $isConstructorPromotionBefore && ! $isConstructorPromotionAfter) {
140140
$this->makePublic($node);
141141
}
142+
143+
if ($node instanceof Property) {
144+
$this->publicize($node);
145+
}
142146
}
143147

144-
public function publicize(ClassConst|ClassMethod $node): ClassConst|ClassMethod|null
148+
public function publicize(ClassConst|ClassMethod|Property $node): ClassConst|ClassMethod|Property|null
145149
{
146150
// already non-public
147151
if (! $node->isPublic()) {

0 commit comments

Comments
 (0)
0