@@ -129,7 +129,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
129129 }
130130
131131
132- private function printFunctionBody (Closure |GlobalFunction |Method $ function ): string
132+ private function printFunctionBody (Closure |GlobalFunction |Method | PropertyHook $ function ): string
133133 {
134134 $ code = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
135135 $ code = Strings::normalize ($ code );
@@ -313,7 +313,7 @@ protected function printUses(PhpNamespace $namespace, string $of = PhpNamespace:
313313 }
314314
315315
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
317317 {
318318 $ special = false ;
319319 foreach ($ function ->getParameters () as $ param ) {
@@ -332,13 +332,13 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
332332 }
333333
334334
335- private function formatParameters (Closure |GlobalFunction |Method $ function , bool $ multiline ): string
335+ private function formatParameters (Closure |GlobalFunction |Method | PropertyHook $ function , bool $ multiline ): string
336336 {
337337 $ params = $ function ->getParameters ();
338338 $ res = '' ;
339339
340340 foreach ($ params as $ param ) {
341- $ variadic = $ function ->isVariadic () && $ param === end ($ params );
341+ $ variadic = ! $ function instanceof PropertyHook && $ function ->isVariadic () && $ param === end ($ params );
342342 $ attrs = $ this ->printAttributes ($ param ->getAttributes (), inline: true );
343343 $ res .=
344344 $ this ->printDocComment ($ param )
@@ -351,6 +351,7 @@ private function formatParameters(Closure|GlobalFunction|Method $function, bool
351351 . ($ variadic ? '... ' : '' )
352352 . '$ ' . $ param ->getName ()
353353 . ($ param ->hasDefaultValue () && !$ variadic ? ' = ' . $ this ->dump ($ param ->getDefaultValue ()) : '' )
354+ . ($ param instanceof PromotedParameter ? $ this ->printHooks ($ param ) : '' )
354355 . ($ multiline ? ", \n" : ', ' );
355356 }
356357
@@ -386,13 +387,16 @@ private function printProperty(Property $property, bool $readOnlyClass = false):
386387 . ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
387388 . '$ ' . $ property ->getName ());
388389
390+ $ defaultValue = $ property ->getValue () === null && !$ property ->isInitialized ()
391+ ? ''
392+ : ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 ); // 3 = ' = '
393+
389394 return $ this ->printDocComment ($ property )
390395 . $ this ->printAttributes ($ property ->getAttributes ())
391396 . $ 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" ;
396400 }
397401
398402
@@ -452,6 +456,30 @@ protected function printAttributes(array $attrs, bool $inline = false): string
452456 }
453457
454458
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+
455483 public function setTypeResolving (bool $ state = true ): static
456484 {
457485 $ this ->resolveTypes = $ state ;
0 commit comments