@@ -330,11 +330,7 @@ protected function instantiateComplexObject(array &$data, $class, array &$contex
330
330
331
331
$ params = array_merge ($ params , $ data [$ paramName ]);
332
332
}
333
-
334
- continue ;
335
- }
336
-
337
- if ($ allowed && !$ ignored && (isset ($ data [$ key ]) || array_key_exists ($ key , $ data ))) {
333
+ } elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) || array_key_exists ($ key , $ data ))) {
338
334
$ parameterData = $ data [$ key ];
339
335
if (null !== $ constructorParameter ->getClass ()) {
340
336
$ parameterData = $ this ->serializer ->deserialize ($ parameterData , $ constructorParameter ->getClass ()->getName (), $ format , $ context );
@@ -343,30 +339,24 @@ protected function instantiateComplexObject(array &$data, $class, array &$contex
343
339
// Don't run set for a parameter passed to the constructor
344
340
$ params [] = $ parameterData ;
345
341
unset($ data [$ key ]);
346
-
347
- continue ;
348
- }
349
-
350
- if ($ constructorParameter ->isDefaultValueAvailable ()) {
342
+ } elseif ($ constructorParameter ->isDefaultValueAvailable ()) {
351
343
$ params [] = $ constructorParameter ->getDefaultValue ();
352
-
353
- continue ;
344
+ } else {
345
+ throw new RuntimeException (
346
+ sprintf (
347
+ 'Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present. ' ,
348
+ $ class ,
349
+ $ constructorParameter ->name
350
+ )
351
+ );
354
352
}
355
-
356
- throw new RuntimeException (
357
- sprintf (
358
- 'Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present. ' ,
359
- $ class ,
360
- $ constructorParameter ->name
361
- )
362
- );
363
353
}
364
354
365
355
if ($ constructor ->isConstructor ()) {
366
356
return $ reflectionClass ->newInstanceArgs ($ params );
357
+ } else {
358
+ return $ constructor ->invokeArgs (null , $ params );
367
359
}
368
-
369
- return $ constructor ->invokeArgs (null , $ params );
370
360
}
371
361
372
362
return new $ class ();
0 commit comments