@@ -209,22 +209,13 @@ public function __destruct()
209209 /** @param array{type: DataTypeCollection, default?: mixed} $property */
210210 private function buildPropertyForeachMapping (string $ propertyName , array $ property , ClassBluePrint $ blueprint ): string
211211 {
212- $ canHaveDefault = \array_key_exists ('default ' , $ property );
213-
214- $ foreach = \PHP_EOL . \str_repeat (' ' , $ canHaveDefault ? 3 : 2 ) . '$x-> ' . $ propertyName . ' = []; ' ;
215- $ foreach .= \PHP_EOL . \str_repeat (' ' , $ canHaveDefault ? 3 : 2 ) . 'foreach ($data[ \'' . $ propertyName . '\'] as $key => $value) { ' ;
216- $ foreach .= \PHP_EOL . \str_repeat (' ' , $ canHaveDefault ? 4 : 3 ) . '$x-> ' . $ propertyName . '[ ' . $ this ->castInMapperFunction ('$key ' , $ property ['type ' ]->types [0 ]->genericTypes [0 ], $ blueprint ) . '] = ' ;
212+ $ foreach = \PHP_EOL . \str_repeat (' ' , 2 ) . '$x-> ' . $ propertyName . ' = []; ' ;
213+ $ foreach .= \PHP_EOL . \str_repeat (' ' , 2 ) . 'foreach ($data[ \'' . $ propertyName . '\'] as $key => $value) { ' ;
214+ $ foreach .= \PHP_EOL . \str_repeat (' ' , 3 ) . '$x-> ' . $ propertyName . '[ ' . $ this ->castInMapperFunction ('$key ' , $ property ['type ' ]->types [0 ]->genericTypes [0 ], $ blueprint ) . '] = ' ;
217215 $ foreach .= $ this ->castInMapperFunction ('$value ' , $ property ['type ' ]->types [0 ]->genericTypes [1 ], $ blueprint ) . '; ' ;
218- $ foreach .= \PHP_EOL . \str_repeat (' ' , $ canHaveDefault ? 3 : 2 ) . '} ' ;
219-
220- if ($ canHaveDefault ) {
221- $ foreach = \PHP_EOL . \str_repeat (' ' , 2 ) . 'if ( \\array_key_exists( \'' . $ propertyName . '\', $data)) { ' . $ foreach ;
222- $ foreach .= \PHP_EOL . \str_repeat (' ' , 2 ) . '} else { ' ;
223- $ foreach .= \PHP_EOL . \str_repeat (' ' , 3 ) . '$x-> ' . $ propertyName . ' = ' . \var_export ($ property ['default ' ], true ) . '; ' ;
224- $ foreach .= \PHP_EOL . \str_repeat (' ' , 2 ) . '} ' ;
225- }
216+ $ foreach .= \PHP_EOL . \str_repeat (' ' , 2 ) . '} ' ;
226217
227- if ($ this -> mapper -> config -> allowUninitializedFields && ! \array_key_exists ('default ' , $ property )) {
218+ if (\array_key_exists ('default ' , $ property ) || $ this -> mapper -> config -> allowUninitializedFields ) {
228219 $ foreach = $ this ->wrapArrayKeyExists ($ foreach , $ propertyName );
229220 }
230221
0 commit comments