@@ -311,12 +311,7 @@ private function addPropertyToClass(ClassLike $class, Node\Stmt\Property $node):
311311 foreach ($ node ->props as $ item ) {
312312 $ prop = $ class ->addProperty ($ item ->name ->toString ());
313313 $ 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 ));
320315 $ prop ->setType ($ node ->type ? $ this ->toPhp ($ node ->type ) : null );
321316 if ($ item ->default ) {
322317 $ prop ->setValue (new Literal ($ this ->getReformattedContents ([$ item ->default ], 1 )));
@@ -334,12 +329,7 @@ private function addMethodToClass(ClassLike $class, Node\Stmt\ClassMethod $node)
334329 $ method ->setAbstract ($ node ->isAbstract ());
335330 $ method ->setFinal ($ node ->isFinal ());
336331 $ 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 ));
343333 $ this ->setupFunction ($ method , $ node );
344334 }
345335
@@ -349,12 +339,7 @@ private function addConstantToClass(ClassLike $class, Node\Stmt\ClassConst $node
349339 foreach ($ node ->consts as $ item ) {
350340 $ value = $ this ->getReformattedContents ([$ item ->value ], 1 );
351341 $ 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 ));
358343 $ const ->setFinal (method_exists ($ node , 'isFinal ' ) && $ node ->isFinal ());
359344 $ this ->addCommentAndAttributes ($ const , $ node );
360345 }
@@ -423,6 +408,17 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
423408 }
424409
425410
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+
426422 private function toPhp (mixed $ value ): string
427423 {
428424 return $ this ->printer ->prettyPrint ([$ value ]);
0 commit comments