@@ -111,11 +111,7 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
111
111
$ method ->setParameters (array_map ([$ this , 'fromParameterReflection ' ], $ from ->getParameters ()));
112
112
$ method ->setStatic ($ from ->isStatic ());
113
113
$ isInterface = $ from ->getDeclaringClass ()->isInterface ();
114
- $ method ->setVisibility (
115
- $ from ->isPrivate ()
116
- ? ClassType::VISIBILITY_PRIVATE
117
- : ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ($ isInterface ? null : ClassType::VISIBILITY_PUBLIC ))
118
- );
114
+ $ method ->setVisibility ($ isInterface ? null : $ this ->getVisibility ($ from ));
119
115
$ method ->setFinal ($ from ->isFinal ());
120
116
$ method ->setAbstract ($ from ->isAbstract () && !$ isInterface );
121
117
$ method ->setBody ($ from ->isAbstract () ? null : '' );
@@ -201,11 +197,7 @@ public function fromConstantReflection(\ReflectionClassConstant $from): Constant
201
197
{
202
198
$ const = new Constant ($ from ->name );
203
199
$ const ->setValue ($ from ->getValue ());
204
- $ const ->setVisibility (
205
- $ from ->isPrivate ()
206
- ? ClassType::VISIBILITY_PRIVATE
207
- : ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC )
208
- );
200
+ $ const ->setVisibility ($ this ->getVisibility ($ from ));
209
201
$ const ->setFinal (PHP_VERSION_ID >= 80100 ? $ from ->isFinal () : false );
210
202
$ const ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
211
203
$ const ->setAttributes (self ::getAttributes ($ from ));
@@ -229,11 +221,7 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
229
221
$ prop = new Property ($ from ->name );
230
222
$ prop ->setValue ($ defaults [$ prop ->getName ()] ?? null );
231
223
$ prop ->setStatic ($ from ->isStatic ());
232
- $ prop ->setVisibility (
233
- $ from ->isPrivate ()
234
- ? ClassType::VISIBILITY_PRIVATE
235
- : ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC )
236
- );
224
+ $ prop ->setVisibility ($ this ->getVisibility ($ from ));
237
225
if (PHP_VERSION_ID >= 70400 ) {
238
226
if ($ from ->getType () instanceof \ReflectionNamedType) {
239
227
$ prop ->setType ($ from ->getType ()->getName ());
@@ -255,6 +243,25 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
255
243
}
256
244
257
245
246
+ private function getAttributes ($ from ): array
247
+ {
248
+ if (PHP_VERSION_ID < 80000 ) {
249
+ return [];
250
+ }
251
+ return array_map (function ($ attr ) {
252
+ return new Attribute ($ attr ->getName (), $ attr ->getArguments ());
253
+ }, $ from ->getAttributes ());
254
+ }
255
+
256
+
257
+ private function getVisibility ($ from ): string
258
+ {
259
+ return $ from ->isPrivate ()
260
+ ? ClassType::VISIBILITY_PRIVATE
261
+ : ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC );
262
+ }
263
+
264
+
258
265
private function loadMethodBodies (\ReflectionClass $ from ): array
259
266
{
260
267
if ($ from ->isAnonymous ()) {
@@ -395,17 +402,4 @@ private function parse($from): array
395
402
396
403
return [$ code , $ stmts ];
397
404
}
398
-
399
-
400
- private function getAttributes ($ from ): array
401
- {
402
- if (PHP_VERSION_ID < 80000 ) {
403
- return [];
404
- }
405
- $ res = [];
406
- foreach ($ from ->getAttributes () as $ attr ) {
407
- $ res [] = new Attribute ($ attr ->getName (), $ attr ->getArguments ());
408
- }
409
- return $ res ;
410
- }
411
405
}
0 commit comments