@@ -311,12 +311,7 @@ private function addPropertyToClass(ClassLike $class, Node\Stmt\Property $node):
311
311
foreach ($ node ->props as $ item ) {
312
312
$ prop = $ class ->addProperty ($ item ->name ->toString ());
313
313
$ prop ->setStatic ($ node ->isStatic ());
314
- if ($ node ->isPrivate ()) {
315
- $ prop ->setPrivate ();
316
- } elseif ($ node ->isProtected ()) {
317
- $ prop ->setProtected ();
318
- }
319
-
314
+ $ prop ->setVisibility ($ this ->toVisibility ($ node ->flags ));
320
315
$ prop ->setType ($ node ->type ? $ this ->toPhp ($ node ->type ) : null );
321
316
if ($ item ->default ) {
322
317
$ prop ->setValue (new Literal ($ this ->getReformattedContents ([$ item ->default ], 1 )));
@@ -334,12 +329,7 @@ private function addMethodToClass(ClassLike $class, Node\Stmt\ClassMethod $node)
334
329
$ method ->setAbstract ($ node ->isAbstract ());
335
330
$ method ->setFinal ($ node ->isFinal ());
336
331
$ method ->setStatic ($ node ->isStatic ());
337
- if ($ node ->isPrivate ()) {
338
- $ method ->setPrivate ();
339
- } elseif ($ node ->isProtected ()) {
340
- $ method ->setProtected ();
341
- }
342
-
332
+ $ method ->setVisibility ($ this ->toVisibility ($ node ->flags ));
343
333
$ this ->setupFunction ($ method , $ node );
344
334
}
345
335
@@ -349,12 +339,7 @@ private function addConstantToClass(ClassLike $class, Node\Stmt\ClassConst $node
349
339
foreach ($ node ->consts as $ item ) {
350
340
$ value = $ this ->getReformattedContents ([$ item ->value ], 1 );
351
341
$ const = $ class ->addConstant ($ item ->name ->toString (), new Literal ($ value ));
352
- if ($ node ->isPrivate ()) {
353
- $ const ->setPrivate ();
354
- } elseif ($ node ->isProtected ()) {
355
- $ const ->setProtected ();
356
- }
357
-
342
+ $ const ->setVisibility ($ this ->toVisibility ($ node ->flags ));
358
343
$ const ->setFinal (method_exists ($ node , 'isFinal ' ) && $ node ->isFinal ());
359
344
$ this ->addCommentAndAttributes ($ const , $ node );
360
345
}
@@ -423,6 +408,17 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
423
408
}
424
409
425
410
411
+ private function toVisibility (int $ flags ): ?string
412
+ {
413
+ return match (true ) {
414
+ (bool ) ($ flags & Node \Stmt \Class_::MODIFIER_PUBLIC ) => ClassType::VisibilityPublic,
415
+ (bool ) ($ flags & Node \Stmt \Class_::MODIFIER_PROTECTED ) => ClassType::VisibilityProtected,
416
+ (bool ) ($ flags & Node \Stmt \Class_::MODIFIER_PRIVATE ) => ClassType::VisibilityPrivate,
417
+ default => null ,
418
+ };
419
+ }
420
+
421
+
426
422
private function toPhp (mixed $ value ): string
427
423
{
428
424
return $ this ->printer ->prettyPrint ([$ value ]);
0 commit comments