Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc24d62

Browse filesBrowse files
committed
remove data parameter from createConstructorArgument method
1 parent 80c5e87 commit bc24d62
Copy full SHA for bc24d62

File tree

1 file changed

+10
-12
lines changed
Filter options

1 file changed

+10
-12
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
361361
$params = array_merge($params, $data[$paramName]);
362362
}
363363
} elseif ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
364-
$params[] = $this->createConstructorArgument($data, $key, $constructorParameter, $context, $format);
364+
$params[] = $this->createConstructorArgument($data[$key], $key, $constructorParameter, $context, $format);
365+
366+
// Don't run set for a parameter passed to the constructor
367+
unset($data[$key]);
365368
} elseif (isset($context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key])) {
366369
$params[] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
367370
} elseif ($constructorParameter->isDefaultValueAvailable()) {
@@ -388,7 +391,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
388391
}
389392

390393
/**
391-
* @param array $data
394+
* @param mixed $parameterData
392395
* @param string $key
393396
* @param \ReflectionParameter $constructorParameter
394397
* @param array $context
@@ -400,13 +403,9 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
400403
* @throws RuntimeException
401404
* @throws MissingConstructorArgumentsException
402405
*/
403-
protected function createConstructorArgument(array &$data, string $key, \ReflectionParameter $constructorParameter, array &$context, string $format = null)
406+
protected function createConstructorArgument($parameterData, string $key, \ReflectionParameter $constructorParameter, array &$context, string $format = null)
404407
{
405-
$parameterData = $data[$key];
406408
if (null === $parameterData && $constructorParameter->allowsNull()) {
407-
// Don't run set for a parameter passed to the constructor
408-
unset($data[$key]);
409-
410409
return null;
411410
}
412411
try {
@@ -415,19 +414,18 @@ protected function createConstructorArgument(array &$data, string $key, \Reflect
415414
throw new LogicException(sprintf('Cannot create an instance of %s from serialized data because the serializer inject in "%s" is not a denormalizer', $constructorParameter->getClass(), static::class));
416415
}
417416
$parameterClass = $constructorParameter->getClass()->getName();
418-
$parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $constructorParameter->name));
417+
418+
return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $constructorParameter->name));
419419
}
420420
} catch (\ReflectionException $e) {
421421
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $key), 0, $e);
422422
} catch (MissingConstructorArgumentsException $e) {
423423
if (!$constructorParameter->getType()->allowsNull()) {
424424
throw $e;
425425
}
426-
$parameterData = null;
427-
}
428426

429-
// Don't run set for a parameter passed to the constructor
430-
unset($data[$key]);
427+
return null;
428+
}
431429

432430
return $parameterData;
433431
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.