66
77use Patchlevel \Hydrator \Normalizer \Normalizer ;
88use ReflectionClass ;
9+ use ReflectionParameter ;
910
1011/**
1112 * @phpstan-type serialized array{
@@ -25,6 +26,9 @@ final class ClassMetadata
2526 /** @var array<string, PropertyMetadata> */
2627 public readonly array $ properties ;
2728
29+ /** @var array<string, ReflectionParameter>|null */
30+ private array |null $ promotedConstructorDefaults = null ;
31+
2832 /**
2933 * @param ReflectionClass<T> $reflection
3034 * @param list<PropertyMetadata> $properties
@@ -65,6 +69,32 @@ public function newInstance(): object
6569 return $ this ->reflection ->newInstanceWithoutConstructor ();
6670 }
6771
72+ /** @return array<string, ReflectionParameter> */
73+ public function promotedConstructorDefaults (): array
74+ {
75+ if ($ this ->promotedConstructorDefaults !== null ) {
76+ return $ this ->promotedConstructorDefaults ;
77+ }
78+
79+ $ constructor = $ this ->reflection ->getConstructor ();
80+
81+ if (!$ constructor ) {
82+ return $ this ->promotedConstructorDefaults = [];
83+ }
84+
85+ $ result = [];
86+
87+ foreach ($ constructor ->getParameters () as $ parameter ) {
88+ if (!$ parameter ->isPromoted () || !$ parameter ->isDefaultValueAvailable ()) {
89+ continue ;
90+ }
91+
92+ $ result [$ parameter ->getName ()] = $ parameter ;
93+ }
94+
95+ return $ this ->promotedConstructorDefaults = $ result ;
96+ }
97+
6898 /** @return serialized */
6999 public function __serialize (): array
70100 {
0 commit comments