Skip to content

Commit 0dc8e9d

Browse files
committed
fix
1 parent 15f2089 commit 0dc8e9d

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

rules/Php82/Rector/Class_/ReadOnlyClassRector.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PhpParser\Node\Stmt\ClassMethod;
1010
use PhpParser\Node\Stmt\Property;
1111
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
12-
use Rector\Core\NodeAnalyzer\PromotedPropertyParamCleaner;
1312
use Rector\Core\Rector\AbstractRector;
1413
use Rector\Core\ValueObject\MethodName;
1514
use Rector\Core\ValueObject\PhpVersionFeature;
@@ -35,8 +34,7 @@ final class ReadOnlyClassRector extends AbstractRector implements MinPhpVersionI
3534
public function __construct(
3635
private readonly ClassAnalyzer $classAnalyzer,
3736
private readonly VisibilityManipulator $visibilityManipulator,
38-
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer,
39-
private readonly PromotedPropertyParamCleaner $promotedPropertyParamCleaner
37+
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer
4038
) {
4139
}
4240

@@ -89,8 +87,9 @@ public function refactor(Node $node): ?Node
8987

9088
$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
9189
if ($constructClassMethod instanceof ClassMethod) {
92-
die;
93-
$this->promotedPropertyParamCleaner->cleanFromFlags($constructClassMethod->getParams());
90+
foreach ($constructClassMethod->getParams() as $param) {
91+
$this->visibilityManipulator->removeReadonly($param);
92+
}
9493
}
9594

9695
foreach ($node->getProperties() as $property) {

rules/Privatization/NodeManipulator/VisibilityManipulator.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,8 @@ public function makeNonFinal(Class_ | ClassMethod $node): void
5858
/**
5959
* This way "abstract", "static", "final" are kept
6060
*/
61-
public function removeVisibility(Class_ | ClassMethod | Property | ClassConst $node): void
61+
public function removeVisibility(ClassMethod | Property | ClassConst $node): void
6262
{
63-
if ($node instanceof Class_ && $node->flags === 0) {
64-
$node->flags -= Class_::MODIFIER_READONLY;
65-
return;
66-
}
67-
68-
if ($node instanceof Class_) {
69-
return;
70-
}
71-
7263
// no modifier
7364
if ($node->flags === 0) {
7465
return;
@@ -163,7 +154,7 @@ private function replaceVisibilityFlag(Class_ | ClassMethod | Property | ClassCo
163154
$this->makeNonStatic($node);
164155
}
165156

166-
if ($visibility !== Visibility::STATIC && $visibility !== Visibility::ABSTRACT && $visibility !== Visibility::FINAL) {
157+
if ($visibility !== Visibility::STATIC && $visibility !== Visibility::ABSTRACT && $visibility !== Visibility::FINAL && $visibility !== Visibility::READONLY) {
167158
$this->removeVisibility($node);
168159
}
169160

0 commit comments

Comments
 (0)