@@ -48,7 +48,7 @@ public function printFunction(GlobalFunction $function, ?PhpNamespace $namespace
48
48
$ body = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
49
49
$ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
50
50
51
- return Helpers:: formatDocComment ( $ function -> getComment () . "\n" )
51
+ return $ this -> printDocComment ( $ function )
52
52
. self ::printAttributes ($ function ->getAttributes ())
53
53
. $ line
54
54
. $ this ->printParameters ($ function , strlen ($ line ) + strlen ($ returnType ) + 2 ) // 2 = parentheses
@@ -119,7 +119,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
119
119
$ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
120
120
$ braceOnNextLine = $ this ->bracesOnNextLine && !str_contains ($ params , "\n" );
121
121
122
- return Helpers:: formatDocComment ( $ method -> getComment () . "\n" )
122
+ return $ this -> printDocComment ( $ method )
123
123
. self ::printAttributes ($ method ->getAttributes ())
124
124
. $ line
125
125
. $ params
@@ -144,7 +144,7 @@ public function printClass(
144
144
if ($ class instanceof ClassType || $ class instanceof TraitType || $ class instanceof EnumType) {
145
145
foreach ($ class ->getTraits () as $ trait ) {
146
146
$ resolutions = $ trait ->getResolutions ();
147
- $ traits [] = Helpers:: formatDocComment (( string ) $ trait -> getComment () )
147
+ $ traits [] = $ this -> printDocComment ( $ trait )
148
148
. 'use ' . $ resolver ($ trait ->getName ())
149
149
. ($ resolutions
150
150
? " { \n" . $ this ->indentation . implode ("; \n" . $ this ->indentation , $ resolutions ) . "; \n} \n"
@@ -158,7 +158,7 @@ public function printClass(
158
158
$ enumType = $ class ->getType ();
159
159
foreach ($ class ->getCases () as $ case ) {
160
160
$ enumType ??= is_scalar ($ case ->getValue ()) ? get_debug_type ($ case ->getValue ()) : null ;
161
- $ cases [] = Helpers:: formatDocComment (( string ) $ case -> getComment () )
161
+ $ cases [] = $ this -> printDocComment ( $ case )
162
162
. self ::printAttributes ($ case ->getAttributes ())
163
163
. 'case ' . $ case ->getName ()
164
164
. ($ case ->getValue () === null ? '' : ' = ' . $ this ->dump ($ case ->getValue ()))
@@ -173,7 +173,7 @@ public function printClass(
173
173
. ($ const ->getVisibility () ? $ const ->getVisibility () . ' ' : '' )
174
174
. 'const ' . $ const ->getName () . ' = ' ;
175
175
176
- $ consts [] = Helpers:: formatDocComment (( string ) $ const -> getComment () )
176
+ $ consts [] = $ this -> printDocComment ( $ const )
177
177
. self ::printAttributes ($ const ->getAttributes ())
178
178
. $ def
179
179
. $ this ->dump ($ const ->getValue (), strlen ($ def )) . "; \n" ;
@@ -204,7 +204,7 @@ public function printClass(
204
204
. ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
205
205
. '$ ' . $ property ->getName ());
206
206
207
- $ properties [] = Helpers:: formatDocComment (( string ) $ property -> getComment () )
207
+ $ properties [] = $ this -> printDocComment ( $ property )
208
208
. self ::printAttributes ($ property ->getAttributes ())
209
209
. $ def
210
210
. ($ property ->getValue () === null && !$ property ->isInitialized ()
@@ -242,7 +242,7 @@ public function printClass(
242
242
: null ;
243
243
$ line [] = $ class ->getName () ? null : '{ ' ;
244
244
245
- return Helpers:: formatDocComment ( $ class -> getComment () . "\n" )
245
+ return $ this -> printDocComment ( $ class )
246
246
. self ::printAttributes ($ class ->getAttributes ())
247
247
. implode (' ' , array_filter ($ line ))
248
248
. ($ class ->getName () ? "\n{ \n" : "\n" )
@@ -295,7 +295,7 @@ public function printFile(PhpFile $file): string
295
295
}
296
296
297
297
return "<?php \n"
298
- . ($ file ->getComment () ? "\n" . Helpers:: formatDocComment ( $ file -> getComment () . "\n" ) : '' )
298
+ . ($ file ->getComment () ? "\n" . $ this -> printDocComment ( $ file ) : '' )
299
299
. "\n"
300
300
. ($ file ->hasStrictTypes () ? "declare(strict_types=1); \n\n" : '' )
301
301
. implode ("\n\n" , $ namespaces );
@@ -332,7 +332,7 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
332
332
$ type = $ param ->getType ();
333
333
$ promoted = $ param instanceof PromotedParameter ? $ param : null ;
334
334
$ params [] =
335
- ($ promoted ? Helpers:: formatDocComment (( string ) $ promoted -> getComment () ) : '' )
335
+ ($ promoted ? $ this -> printDocComment ( $ promoted ) : '' )
336
336
. ($ attrs = self ::printAttributes ($ param ->getAttributes (), inline: true ))
337
337
. ($ promoted ?
338
338
($ promoted ->getVisibility () ?: 'public ' )
@@ -375,6 +375,16 @@ protected function printType(?string $type, bool $nullable): string
375
375
}
376
376
377
377
378
+ protected function printDocComment (/*Traits\CommentAware*/ $ commentable ): string
379
+ {
380
+ $ multiLine = $ commentable instanceof GlobalFunction
381
+ || $ commentable instanceof Method
382
+ || $ commentable instanceof ClassLike
383
+ || $ commentable instanceof PhpFile;
384
+ return Helpers::formatDocComment ((string ) $ commentable ->getComment (), $ multiLine );
385
+ }
386
+
387
+
378
388
private function printReturnType (Closure |GlobalFunction |Method $ function ): string
379
389
{
380
390
return ($ tmp = $ this ->printType ($ function ->getReturnType (), $ function ->isReturnNullable ()))
0 commit comments