8000 [Serializer] Fixed docblocks and parameter names. · symfony/symfony@50701fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 50701fe

Browse files
committed
[Serializer] Fixed docblocks and parameter names.
1 parent 628271d commit 50701fe

13 files changed

+34
-35
lines changed

src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait ClassResolverTrait
2525
/**
2626
* Gets a class name for a given class or instance.
2727
*
28-
* @param mixed $value
28+
* @param object|string $value
2929
*
3030
* @return string
3131
*

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,33 +168,33 @@ public function supportsDenormalization($data, $type, $format = null)
168168
/**
169169
* {@inheritdoc}
170170
*/
171-
public function denormalize($data, $class, $format = null, array $context = [])
171+
public function denormalize($data, $type, $format = null, array $context = [])
172172
{
173173
if (!isset($context['cache_key'])) {
174174
$context['cache_key'] = $this->getCacheKey($format, $context);
175175
}
176176

177-
$allowedAttributes = $this->getAllowedAttributes($class, $context, true);
177+
$allowedAttributes = $this->getAllowedAttributes($type, $context, true);
178178
$normalizedData = $this->prepareForDenormalization($data);
179179
$extraAttributes = [];
180180

181-
$reflectionClass = new \ReflectionClass($class);
182-
$object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes, $format);
181+
$reflectionClass = new \ReflectionClass($type);
182+
$object = $this->instantiateObject($normalizedData, $type, $context, $reflectionClass, $allowedAttributes, $format);
183183

184184
foreach ($normalizedData as $attribute => $value) {
185185
if ($this->nameConverter) {
186186
$attribute = $this->nameConverter->denormalize($attribute);
187187
}
188188

189-
if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($class, $attribute, $format, $context)) {
189+
if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($type, $attribute, $format, $context)) {
190190
if (isset($context[self::ALLOW_EXTRA_ATTRIBUTES]) && !$context[self::ALLOW_EXTRA_ATTRIBUTES]) {
191191
$extraAttributes[] = $attribute;
192192
}
193193

194194
continue;
195195
}
196196

197-
$value = $this->validateAndDenormalize($class, $attribute, $value, $format, $context);
197+
$value = $this->validateAndDenormalize($type, $attribute, $value, $format, $context);
198198
try {
199199
$this->setAttributeValue($object, $attribute, $value, $format, $context);
200200
} catch (InvalidArgumentException $e) {

src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterfa
3636
*
3737
* @throws NotNormalizableValueException
3838
*/
39-
public function denormalize($data, $class, $format = null, array $context = [])
39+
public function denormalize($data, $type, $format = null, array $context = [])
4040
{
4141
if (null === $this->serializer) {
4242
throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
4343
}
4444
if (!\is_array($data)) {
4545
throw new InvalidArgumentException('Data expected to be an array, '.\gettype($data).' given.');
4646
}
47-
if ('[]' !== substr($class, -2)) {
48-
throw new InvalidArgumentException('Unsupported class: '.$class);
47+
if ('[]' !== substr($type, -2)) {
48+
throw new InvalidArgumentException('Unsupported class: '.$type);
4949
}
5050

5151
$serializer = $this->serializer;
52-
$class = substr($class, 0, -2);
52+
$type = substr($type, 0, -2);
5353

5454
$builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null;
5555
foreach ($data as $key => $value) {
5656
if (null !== $builtinType && !\call_user_func('is_'.$builtinType, $key)) {
5757
throw new NotNormalizableValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, \gettype($key)));
5858
}
5959

60-
$data[$key] = $serializer->denormalize($value, $class, $format, $context);
60+
$data[$key] = $serializer->denormalize($value, $type, $format, $context);
6161
}
6262

6363
return $data;

src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function normalize($object, $format = null, array $context = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function denormalize($data, $class, $format = null, array $context = [])
38+
public function denormalize($data, $type, $format = null, array $context = [])
3939
{
40-
$object = $this->extractObjectToPopulate($class, $context) ?: new $class();
40+
$object = $this->extractObjectToPopulate($type, $context) ?: new $type();
4141
$object->denormalize($this->serializer, $data, $format, $context);
4242

4343
return $object;

src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public function supportsNormalization($data, $format = null)
8989
* @throws InvalidArgumentException
9090
* @throws NotNormalizableValueException
9191
*/
92-
public function denormalize($data, $class, $format = null, array $context = [])
92+
public function denormalize($data, $type, $format = null, array $context = [])
9393
{
9494
if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) {
9595
throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
9696
}
9797

9898
try {
99-
switch ($class) {
99+
switch ($type) {
100100
case 'Symfony\Component\HttpFoundation\File\File':
101101
return new File($data, false);
102102

@@ -108,7 +108,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
108108
throw new NotNormalizableValueException($exception->getMessage(), $exception->getCode(), $exception);
109109
}
110110

111-
throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $class));
111+
throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $type));
112112
}
113113

114114
/**

src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function supportsNormalization($data, $format = null)
6464
* @throws InvalidArgumentException
6565
* @throws UnexpectedValueException
6666
*/
67-
public function denormalize($data, $class, $format = null, array $context = [])
67+
public function denormalize($data, $type, $format = null, array $context = [])
6868
{
6969
if (!\is_string($data)) {
7070
throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data)));

src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function supportsNormalization($data, $format = null)
7878
*
7979
* @throws NotNormalizableValueException
8080
*/
81-
public function denormalize($data, $class, $format = null, array $context = [])
81+
public function denormalize($data, $type, $format = null, array $context = [])
8282
{
8383
$dateTimeFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : null;
8484
$timezone = $this->getTimezone($context);
@@ -90,16 +90,16 @@ public function denormalize($data, $class, $format = null, array $context = [])
9090
if (null !== $dateTimeFormat) {
9191
if (null === $timezone && \PHP_VERSION_ID < 70000) {
9292
// https://bugs.php.net/68669
93-
$object = \DateTime::class === $class ? \DateTime::createFromFormat($dateTimeFormat, $data) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data);
93+
$object = \DateTime::class === $type ? \DateTime::createFromFormat($dateTimeFormat, $data) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data);
9494
} else {
95-
$object = \DateTime::class === $class ? \DateTime::createFromFormat($dateTimeFormat, $data, $timezone) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data, $timezone);
95+
$object = \DateTime::class === $type ? \DateTime::createFromFormat($dateTimeFormat, $data, $timezone) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data, $timezone);
9696
}
9797

9898
if (false !== $object) {
9999
return $object;
100100
}
101101

102-
$dateTimeErrors = \DateTime::class === $class ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors();
102+
$dateTimeErrors = \DateTime::class === $type ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors();
103103

104104
throw new NotNormalizableValueException(sprintf(
105105
'Parsing datetime string "%s" using format "%s" resulted in %d errors:'."\n".'%s',
@@ -111,7 +111,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
111111
}
112112

113113
try {
114-
return \DateTime::class === $class ? new \DateTime($data, $timezone) : new \DateTimeImmutable($data, $timezone);
114+
return \DateTime::class === $type ? new \DateTime($data, $timezone) : new \DateTimeImmutable($data, $timezone);
115115
} catch (\Exception $e) {
116116
throw new NotNormalizableValueException($e->getMessage(), $e->getCode(), $e);
117117
}

src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface DenormalizerInterface
3030
* Denormalizes data back into an object of the given class.
3131
*
3232
* @param mixed $data Data to restore
33-
* @param string $class The expected class to instantiate
33+
* @param string $type The expected class to instantiate
3434
* @param string $format Format the given data was extracted from
3535
* @param array $context Options available to the denormalizer
3636
*
@@ -44,7 +44,7 @@ interface DenormalizerInterface
4444
* @throws RuntimeException Occurs if the class cannot be instantiated
4545
* @throws ExceptionInterface Occurs for all the other cases of errors
4646
*/
47-
public function denormalize($data, $class, $format = null, array $context = []);
47+
public function denormalize($data, $type, $format = null, array $context = []);
4848

4949
/**
5050
* Checks whether the given class is supported for denormalization by this normalizer.

src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function supportsDenormalization($data, $type, $format = null)
6060
/**
6161
* {@inheritdoc}
6262
*/
63-
public function denormalize($data, $class, $format = null, array $context = [])
63+
public function denormalize($data, $type, $format = null, array $context = [])
6464
{
6565
throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
6666
}

src/Symfony/Component/Serializer/Normalizer/ObjectToPopulateTrait.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ trait ObjectToPopulateTrait
1717
* Extract the `object_to_populate` field from the context if it exists
1818
* and is an instance of the provided $class.
1919
*
20-
* @param string $class The class the object should be
21-
* @param $context The denormalization context
22-
* @param string $key They in which to look for the object to populate.
23-
* Keeps backwards compatibility with `AbstractNormalizer`.
20+
* @param string $class The class the object should be
21+
* @param string|null $key They in which to look for the object to populate.
22+
* Keeps backwards compatibility with `AbstractNormalizer`.
2423
*
2524
* @return object|null an object if things check out, null otherwise
2625
*/

src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function supportsNormalization($data, $format = null)
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function denormalize($data, $class, $format = null, array $context = [])
49+
public function denormalize($data, $type, $format = null, array $context = [])
5050
{
5151
}
5252

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@ class ArrayDenormalizerDummy implements DenormalizerInterface, SerializerAwareIn
304304
*
305305
* @throws NotNormalizableValueException
306306
*/
307-
public function denormalize($data, $class, $format = null, array $context = [])
307+
public function denormalize($data, $type, $format = null, array $context = [])
308308
{
309309
$serializer = $this->serializer;
310-
$class = substr($class, 0, -2);
310+
$type = substr($type, 0, -2);
311311

312312
foreach ($data as $key => $value) {
313-
$data[$key] = $serializer->denormalize($value, $class, $format, $context);
313+
$data[$key] = $serializer->denormalize($value, $type, $format, $context);
314314
}
315315

316316
return $data;

src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestDenormalizer implements DenormalizerInterface
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function denormalize($data, $class, $format = null, array $context = [])
26+
public function denormalize($data, $type, $format = null, array $context = [])
2727
{
2828
}
2929

0 commit comments

Comments
 (0)
0