@@ -311,12 +311,7 @@ private function addPropertyToClass(ClassType $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(ClassType $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(ClassType $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
}
@@ -421,6 +406,19 @@ private function setupFunction($function, Node\FunctionLike $node): void
421
406
}
422
407
423
408
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
+
424
422
private function toPhp ($ value ): string
425
423
{
426
424
return $ this ->printer ->prettyPrint ([$ value ]);
0 commit comments