@@ -121,6 +121,7 @@ public function getValues(string|object|bool|null $returnType = null, ?array $co
121121 $ returnType = self ::Array;
122122 }
123123
124+ /** @var list<Control>|null $controls */
124125 return $ this ->getUntrustedValues ($ returnType , $ controls );
125126 }
126127
@@ -140,7 +141,9 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array
140141
141142 } else {
142143 $ returnType ??= $ this ->mappedType ?? ArrayHash::class;
143- $ rc = new \ReflectionClass ($ returnType === self ::Array ? \stdClass::class : $ returnType );
144+ /** @var class-string $rcClass */
145+ $ rcClass = $ returnType === self ::Array ? \stdClass::class : $ returnType ;
146+ $ rc = new \ReflectionClass ($ rcClass );
144147 $ constructor = $ rc ->hasMethod ('__construct ' ) ? $ rc ->getMethod ('__construct ' ) : null ;
145148 if ($ constructor ?->getNumberOfRequiredParameters()) {
146149 $ resultObj = new \stdClass ;
@@ -166,23 +169,28 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array
166169 $ resultObj ->$ name = Helpers::tryEnumConversion ($ control ->getValue (), $ property );
167170
168171 } elseif ($ control instanceof self) {
172+ /** @var class-string|'array'|null $type */
169173 $ type = $ returnType === self ::Array && !$ control ->mappedType
170174 ? self ::Array
171175 : ($ property ? Helpers::getSingleType ($ property ) : null );
172176 $ resultObj ->$ name = $ control ->getUntrustedValues ($ type , $ allowed ? null : $ controls );
173177 }
174178 }
175179
176- return match (true ) {
177- isset ($ constructor ) => new $ returnType (...(array ) $ resultObj ),
178- $ returnType === self ::Array => (array ) $ resultObj ,
179- default => $ resultObj ,
180- };
180+ if ($ returnType === self ::Array) {
181+ return (array ) $ resultObj ;
182+ } elseif (isset ($ constructor )) {
183+ /** @var class-string $returnType */
184+ return new $ returnType (...(array ) $ resultObj );
185+ }
186+
187+ return $ resultObj ;
181188 }
182189
183190
184191 /**
185192 * @deprecated use getUntrustedValues()
193+ * @param class-string|'array'|object|null $returnType
186194 * @param ?list<Control> $controls
187195 * @return object|array<string, mixed>
188196 */
@@ -242,6 +250,7 @@ public function validate(?array $controls = null): void
242250
243251 foreach ($ this ->onValidate as $ handler ) {
244252 $ params = Nette \Utils \Callback::toReflection ($ handler )->getParameters ();
253+ /** @var list<?class-string> $types */
245254 $ types = array_map (Helpers::getSingleType (...), $ params );
246255 $ args = isset ($ types [0 ]) && !$ this instanceof $ types [0 ]
247256 ? [$ this ->getUntrustedValues ($ types [0 ])]
0 commit comments