@@ -61,29 +61,20 @@ public function setDefaults(array|object $data, bool $erase = false): static
6161 * Fill-in with values.
6262 * @internal
6363 */
64- public function setValues (array |object $ data , bool $ erase = false ): static
64+ public function setValues (array |object $ values , bool $ erase = false ): static
6565 {
66- if ($ data instanceof \Traversable) {
67- $ values = iterator_to_array ($ data );
68-
69- } elseif (is_object ($ data ) || is_array ($ data ) || $ data === null ) {
70- $ values = (array ) $ data ;
71- }
66+ $ values = $ values instanceof \Traversable
67+ ? iterator_to_array ($ values )
68+ : (array ) $ values ;
7269
7370 foreach ($ this ->getComponents () as $ name => $ control ) {
7471 if ($ control instanceof Control) {
75- if (array_key_exists ($ name , $ values )) {
76- $ control ->setValue ($ values [$ name ]);
77-
78- } elseif ($ erase ) {
79- $ control ->setValue (null );
72+ if (array_key_exists ($ name , $ values ) || $ erase ) {
73+ $ control ->setValue ($ values [$ name ] ?? null );
8074 }
8175 } elseif ($ control instanceof self) {
82- if (isset ($ values [$ name ])) {
83- $ control ->setValues ($ values [$ name ], $ erase );
84-
85- } elseif ($ erase ) {
86- $ control ->setValues ([], $ erase );
76+ if (isset ($ values [$ name ]) || $ erase ) {
77+ $ control ->setValues ($ values [$ name ] ?? [], $ erase );
8778 }
8879 }
8980 }
@@ -186,7 +177,6 @@ public function getUnsafeValues($returnType, ?array $controls = null)
186177 }
187178
188179
189- /** @return static */
190180 public function setMappedType (string $ type ): static
191181 {
192182 $ this ->mappedType = $ type ;
@@ -287,10 +277,7 @@ public function addComponent(
287277 ): static
288278 {
289279 parent ::addComponent ($ component , $ name , $ insertBefore );
290- if ($ this ->currentGroup !== null ) {
291- $ this ->currentGroup ->add ($ component );
292- }
293-
280+ $ this ->currentGroup ?->add($ component );
294281 return $ this ;
295282 }
296283
@@ -577,10 +564,7 @@ public function addContainer(string|int $name): self
577564 {
578565 $ control = new self ;
579566 $ control ->currentGroup = $ this ->currentGroup ;
580- if ($ this ->currentGroup !== null ) {
581- $ this ->currentGroup ->add ($ control );
582- }
583-
567+ $ this ->currentGroup ?->add($ control );
584568 return $ this [$ name ] = $ control ;
585569 }
586570
0 commit comments