@@ -311,12 +311,7 @@ private function addPropertyToClass(ClassType $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(ClassType $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(ClassType $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 }
@@ -421,6 +406,19 @@ private function setupFunction($function, Node\FunctionLike $node): void
421406 }
422407
423408
409+ private function toVisibility (int $ flags ): ?string
410+ {
411+ if ($ flags & Node \Stmt \Class_::MODIFIER_PUBLIC ) {
412+ return ClassType::VisibilityPublic;
413+ } elseif ($ flags & Node \Stmt \Class_::MODIFIER_PROTECTED ) {
414+ return ClassType::VisibilityProtected;
415+ } elseif ($ flags & Node \Stmt \Class_::MODIFIER_PRIVATE ) {
416+ return ClassType::VisibilityPrivate;
417+ }
418+ return null ;
419+ }
420+
421+
424422 private function toPhp ($ value ): string
425423 {
426424 return $ this ->printer ->prettyPrint ([$ value ]);
0 commit comments