@@ -129,7 +129,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
129
129
}
130
130
131
131
132
- private function printFunctionBody (Closure |GlobalFunction |Method $ function ): string
132
+ private function printFunctionBody (Closure |GlobalFunction |Method | PropertyHook $ function ): string
133
133
{
134
134
$ code = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
135
135
$ code = Strings::normalize ($ code );
@@ -313,7 +313,7 @@ protected function printUses(PhpNamespace $namespace, string $of = PhpNamespace:
313
313
}
314
314
315
315
316
- protected function printParameters (Closure |GlobalFunction |Method $ function , int $ column = 0 ): string
316
+ protected function printParameters (Closure |GlobalFunction |Method | PropertyHook $ function , int $ column = 0 ): string
317
317
{
318
318
$ special = false ;
319
319
foreach ($ function ->getParameters () as $ param ) {
@@ -332,13 +332,13 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
332
332
}
333
333
334
334
335
- private function formatParameters (Closure |GlobalFunction |Method $ function , bool $ multiline ): string
335
+ private function formatParameters (Closure |GlobalFunction |Method | PropertyHook $ function , bool $ multiline ): string
336
336
{
337
337
$ params = $ function ->getParameters ();
338
338
$ res = '' ;
339
339
340
340
foreach ($ params as $ param ) {
341
- $ variadic = $ function ->isVariadic () && $ param === end ($ params );
341
+ $ variadic = ! $ function instanceof PropertyHook && $ function ->isVariadic () && $ param === end ($ params );
342
342
$ attrs = $ this ->printAttributes ($ param ->getAttributes (), inline: true );
343
343
$ res .=
344
344
$ this ->printDocComment ($ param )
@@ -351,6 +351,7 @@ private function formatParameters(Closure|GlobalFunction|Method $function, bool
351
351
. ($ variadic ? '... ' : '' )
352
352
. '$ ' . $ param ->getName ()
353
353
. ($ param ->hasDefaultValue () && !$ variadic ? ' = ' . $ this ->dump ($ param ->getDefaultValue ()) : '' )
354
+ . ($ param instanceof PromotedParameter ? $ this ->printHooks ($ param ) : '' )
354
355
. ($ multiline ? ", \n" : ', ' );
355
356
}
356
357
@@ -386,13 +387,16 @@ private function printProperty(Property $property, bool $readOnlyClass = false):
386
387
. ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
387
388
. '$ ' . $ property ->getName ());
388
389
390
+ $ defaultValue = $ property ->getValue () === null && !$ property ->isInitialized ()
391
+ ? ''
392
+ : ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 ); // 3 = ' = '
393
+
389
394
return $ this ->printDocComment ($ property )
390
395
. $ this ->printAttributes ($ property ->getAttributes ())
391
396
. $ def
392
- . ($ property ->getValue () === null && !$ property ->isInitialized ()
393
- ? ''
394
- : ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 )) // 3 = ' = '
395
- . "; \n" ;
397
+ . $ defaultValue
398
+ . ($ this ->printHooks ($ property ) ?: '; ' )
399
+ . "\n" ;
396
400
}
397
401
398
402
@@ -452,6 +456,30 @@ protected function printAttributes(array $attrs, bool $inline = false): string
452
456
}
453
457
454
458
459
+ private function printHooks (Property |PromotedParameter $ property ): string
460
+ {
461
+ $ hooks = $ property ->getHooks ();
462
+ if (!$ hooks ) {
463
+ return '' ;
464
+ }
465
+
466
+ foreach ($ property ->getHooks () as $ type => $ hook ) {
467
+ $ hooks [$ type ] = $ this ->printDocComment ($ hook )
468
+ . $ this ->printAttributes ($ hook ->getAttributes ())
469
+ . ($ hook ->isFinal () ? 'final ' : '' )
470
+ . ($ hook ->getReturnReference () ? '& ' : '' )
471
+ . $ type
472
+ . ($ hook ->getParameters () ? $ this ->printParameters ($ hook ) : '' )
473
+ . ' '
474
+ . ($ hook ->isShort ()
475
+ ? '=> ' . $ hook ->getBody () . '; '
476
+ : "{ \n" . $ this ->indent ($ this ->printFunctionBody ($ hook )) . '} ' );
477
+ }
478
+
479
+ return " { \n" . $ this ->indent (implode ("\n" , $ hooks )) . "\n} " ;
480
+ }
481
+
482
+
455
483
public function setTypeResolving (bool $ state = true ): static
456
484
{
457
485
$ this ->resolveTypes = $ state ;
0 commit comments