@@ -314,7 +314,7 @@ private function addPropertyToClass(ClassLike $class, Node\Stmt\Property $node):
314
314
$ prop ->setVisibility ($ this ->toVisibility ($ node ->flags ));
315
315
$ prop ->setType ($ node ->type ? $ this ->toPhp ($ node ->type ) : null );
316
316
if ($ item ->default ) {
317
- $ prop ->setValue (new Literal ( $ this ->getReformattedContents ([ $ item ->default ] , 1 ) ));
317
+ $ prop ->setValue ($ this ->formatValue ( $ item ->default , 1 ));
318
318
}
319
319
320
320
$ prop ->setReadOnly (method_exists ($ node , 'isReadonly ' ) && $ node ->isReadonly ());
@@ -337,8 +337,7 @@ private function addMethodToClass(ClassLike $class, Node\Stmt\ClassMethod $node)
337
337
private function addConstantToClass (ClassLike $ class , Node \Stmt \ClassConst $ node ): void
338
338
{
339
339
foreach ($ node ->consts as $ item ) {
340
- $ value = $ this ->getReformattedContents ([$ item ->value ], 1 );
341
- $ const = $ class ->addConstant ($ item ->name ->toString (), new Literal ($ value ));
340
+ $ const = $ class ->addConstant ($ item ->name ->toString (), $ this ->formatValue ($ item ->value , 1 ));
342
341
$ const ->setVisibility ($ this ->toVisibility ($ node ->flags ));
343
342
$ const ->setFinal (method_exists ($ node , 'isFinal ' ) && $ node ->isFinal ());
344
343
$ this ->addCommentAndAttributes ($ const , $ node );
@@ -351,7 +350,7 @@ private function addEnumCaseToClass(EnumType $class, Node\Stmt\EnumCase $node):
351
350
$ value = match (true ) {
352
351
$ node ->expr === null => null ,
353
352
$ node ->expr instanceof Node \Scalar \LNumber, $ node ->expr instanceof Node \Scalar \String_ => $ node ->expr ->value ,
354
- default => new Literal ( $ this ->getReformattedContents ([ $ node ->expr ] , 1 ) ),
353
+ default => $ this ->formatValue ( $ node ->expr , 1 ),
355
354
};
356
355
$ case = $ class ->addCase ($ node ->name ->toString (), $ value );
357
356
$ this ->addCommentAndAttributes ($ case , $ node );
@@ -371,7 +370,7 @@ private function addCommentAndAttributes($element, Node $node): void
371
370
foreach ($ group ->attrs as $ attribute ) {
372
371
$ args = [];
373
372
foreach ($ attribute ->args as $ arg ) {
374
- $ value = new Literal ( $ this ->getReformattedContents ([ $ arg ->value ] , 0 ) );
373
+ $ value = $ this ->formatValue ( $ arg ->value , 0 );
375
374
if ($ arg ->name ) {
376
375
$ args [$ arg ->name ->toString ()] = $ value ;
377
376
} else {
@@ -399,7 +398,7 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
399
398
$ param ->setReference ($ item ->byRef );
400
399
$ function ->setVariadic ($ item ->variadic );
401
400
if ($ item ->default ) {
402
- $ param ->setDefaultValue (new Literal ( $ this ->getReformattedContents ([ $ item ->default ] , 2 ) ));
401
+ $ param ->setDefaultValue ($ this ->formatValue ( $ item ->default , 2 ));
403
402
}
404
403
405
404
$ this ->addCommentAndAttributes ($ param , $ item );
@@ -412,6 +411,13 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
412
411
}
413
412
414
413
414
+ private function formatValue (Node \Expr $ value , int $ level ): Literal
415
+ {
416
+ $ value = $ this ->getReformattedContents ([$ value ], $ level );
417
+ return new Literal ($ value );
418
+ }
419
+
420
+
415
421
private function toVisibility (int $ flags ): ?string
416
422
{
417
423
return match (true ) {
0 commit comments