@@ -91,15 +91,23 @@ public function check(Input $input): ResultInterface
91
91
return Failure::fromNameAndReason ($ this ->getName (), 'Property "config" should not be promoted ' );
92
92
}
93
93
94
+ $ expectedProperties = [
95
+ 'basePath ' => 'protected ' ,
96
+ 'key ' => 'private ' ,
97
+ 'visitor ' => 'private ' ,
98
+ ];
99
+
94
100
$ properties = collect ($ reflectionClass ->getProperties ());
95
- $ properties = $ properties ->flatMap (fn (\ReflectionProperty $ prop ) => [$ prop ->getName () => $ prop ]);
96
- $ private = $ properties ->filter (fn (\ReflectionProperty $ prop ) => $ prop ->isPrivate ());
101
+ $ properties = $ properties ->flatMap (fn (\ReflectionProperty $ prop ) => [
102
+ $ prop ->getName () => $ this ->getPropertyVisibility ($ prop )
103
+ ])->getArrayCopy ();
104
+ ksort ($ properties );
97
105
98
- if ($ notPrivate = array_diff ([ ' visitor ' , ' key ' ], $ private -> keys ()-> getArrayCopy ( ))) {
106
+ if ($ changedVisibility = array_keys ( array_diff_assoc ( $ expectedProperties , $ properties ))) {
99
107
return Failure::fromNameAndReason ($ this ->getName (), pluralise (
100
- 'Visibility changed for property %s ' ,
101
- $ notPrivate ,
102
- implode ('" & " ' , $ notPrivate )
108
+ 'Visibility changed for property "%s" ' ,
109
+ $ changedVisibility ,
110
+ implode ('" & " ' , $ changedVisibility )
103
111
));
104
112
}
105
113
@@ -143,4 +151,13 @@ public function check(Input $input): ResultInterface
143
151
144
152
return new Success ($ this ->getName ());
145
153
}
154
+
155
+ private function getPropertyVisibility (\ReflectionProperty $ prop ): string
156
+ {
157
+ return match (true ) {
158
+ $ prop ->isPrivate () => 'private ' ,
159
+ $ prop ->isProtected () => 'protected ' ,
160
+ default => 'public ' ,
161
+ };
162
+ }
146
163
}
0 commit comments