File tree Expand file tree Collapse file tree 2 files changed +6
-16
lines changed
Privatization/NodeManipulator Expand file tree Collapse file tree 2 files changed +6
-16
lines changed Original file line number Diff line number Diff line change 9
9
use PhpParser \Node \Stmt \ClassMethod ;
10
10
use PhpParser \Node \Stmt \Property ;
11
11
use Rector \Core \NodeAnalyzer \ClassAnalyzer ;
12
- use Rector \Core \NodeAnalyzer \PromotedPropertyParamCleaner ;
13
12
use Rector \Core \Rector \AbstractRector ;
14
13
use Rector \Core \ValueObject \MethodName ;
15
14
use Rector \Core \ValueObject \PhpVersionFeature ;
@@ -35,8 +34,7 @@ final class ReadOnlyClassRector extends AbstractRector implements MinPhpVersionI
35
34
public function __construct (
36
35
private readonly ClassAnalyzer $ classAnalyzer ,
37
36
private readonly VisibilityManipulator $ visibilityManipulator ,
38
- private readonly PhpAttributeAnalyzer $ phpAttributeAnalyzer ,
39
- private readonly PromotedPropertyParamCleaner $ promotedPropertyParamCleaner
37
+ private readonly PhpAttributeAnalyzer $ phpAttributeAnalyzer
40
38
) {
41
39
}
42
40
@@ -89,8 +87,9 @@ public function refactor(Node $node): ?Node
89
87
90
88
$ constructClassMethod = $ node ->getMethod (MethodName::CONSTRUCT );
91
89
if ($ constructClassMethod instanceof ClassMethod) {
92
- die;
93
- $ this ->promotedPropertyParamCleaner ->cleanFromFlags ($ constructClassMethod ->getParams ());
90
+ foreach ($ constructClassMethod ->getParams () as $ param ) {
91
+ $ this ->visibilityManipulator ->removeReadonly ($ param );
92
+ }
94
93
}
95
94
96
95
foreach ($ node ->getProperties () as $ property ) {
Original file line number Diff line number Diff line change @@ -58,17 +58,8 @@ public function makeNonFinal(Class_ | ClassMethod $node): void
58
58
/**
59
59
* This way "abstract", "static", "final" are kept
60
60
*/
61
- public function removeVisibility (Class_ | ClassMethod | Property | ClassConst $ node ): void
61
+ public function removeVisibility (ClassMethod | Property | ClassConst $ node ): void
62
62
{
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
-
72
63
// no modifier
73
64
if ($ node ->flags === 0 ) {
74
65
return ;
@@ -163,7 +154,7 @@ private function replaceVisibilityFlag(Class_ | ClassMethod | Property | ClassCo
163
154
$ this ->makeNonStatic ($ node );
164
155
}
165
156
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 ) {
167
158
$ this ->removeVisibility ($ node );
168
159
}
169
160
You can’t perform that action at this time.
0 commit comments