Skip to content

Commit 6e486bc

Browse files
committed
[Serializer] Add correct signature to normalize for type mixed
1 parent aa493f2 commit 6e486bc

23 files changed

+101
-101
lines changed

src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ final class FlattenExceptionNormalizer implements DenormalizerInterface, Normali
2626
{
2727
use NormalizerAwareTrait;
2828

29-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
29+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
3030
{
3131
$normalized = [
32-
'message' => $object->getMessage(),
33-
'code' => $object->getCode(),
34-
'headers' => $object->getHeaders(),
35-
'class' => $object->getClass(),
36-
'file' => $object->getFile(),
37-
'line' => $object->getLine(),
38-
'previous' => null === $object->getPrevious() ? null : $this->normalize($object->getPrevious(), $format, $context),
39-
'status' => $object->getStatusCode(),
40-
'status_text' => $object->getStatusText(),
41-
'trace' => $object->getTrace(),
42-
'trace_as_string' => $object->getTraceAsString(),
32+
'message' => $data->getMessage(),
33+
'code' => $data->getCode(),
34+
'headers' => $data->getHeaders(),
35+
'class' => $data->getClass(),
36+
'file' => $data->getFile(),
37+
'line' => $data->getLine(),
38+
'previous' => null === $data->getPrevious() ? null : $this->normalize($data->getPrevious(), $format, $context),
39+
'status' => $data->getStatusCode(),
40+
'status_text' => $data->getStatusText(),
41+
'trace' => $data->getTrace(),
42+
'trace_as_string' => $data->getTraceAsString(),
4343
];
4444

4545
return $normalized;

src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function getSupportedTypes(?string $format): array
3939
return $this->normalizer->getSupportedTypes($format);
4040
}
4141

42-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
42+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
4343
{
4444
if (!$this->normalizer instanceof NormalizerInterface) {
4545
throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class));
4646
}
4747

4848
$startTime = microtime(true);
49-
$normalized = $this->normalizer->normalize($object, $format, $context);
49+
$normalized = $this->normalizer->normalize($data, $format, $context);
5050
$time = microtime(true) - $startTime;
5151

5252
if ($traceId = ($context[TraceableSerializer::DEBUG_TRACE_ID] ?? null)) {

src/Symfony/Component/Serializer/Debug/TraceableSerializer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ public function deserialize(mixed $data, string $type, string $format, array $co
6565
return $result;
6666
}
6767

68-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
68+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
6969
{
7070
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
7171

7272
$startTime = microtime(true);
73-
$result = $this->serializer->normalize($object, $format, $context);
73+
$result = $this->serializer->normalize($data, $format, $context);
7474
$time = microtime(true) - $startTime;
7575

7676
$caller = $this->getCaller(__FUNCTION__, NormalizerInterface::class);
7777

78-
$this->dataCollector->collectNormalize($traceId, $object, $format, $context, $time, $caller);
78+
$this->dataCollector->collectNormalize($traceId, $data, $format, $context, $time, $caller);
7979

8080
return $result;
8181
}

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
150150
return \is_object($data) && !$data instanceof \Traversable;
151151
}
152152

153-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
153+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
154154
{
155155
$context['_read_attributes'] = true;
156156

@@ -160,14 +160,14 @@ public function normalize(mixed $object, ?string $format = null, array $context
160160

161161
$this->validateCallbackContext($context);
162162

163-
if ($this->isCircularReference($object, $context)) {
164-
return $this->handleCircularReference($object, $format, $context);
163+
if ($this->isCircularReference($data, $context)) {
164+
return $this->handleCircularReference($data, $format, $context);
165165
}
166166

167-
$data = [];
167+
$normalized = [];
168168
$stack = [];
169-
$attributes = $this->getAttributes($object, $format, $context);
170-
$class = ($this->objectClassResolver)($object);
169+
$attributes = $this->getAttributes($data, $format, $context);
170+
$class = ($this->objectClassResolver)($data);
171171
$classMetadata = $this->classMetadataFactory?->getMetadataFor($class);
172172
$attributesMetadata = $this->classMetadataFactory?->getMetadataFor($class)->getAttributesMetadata();
173173
if (isset($context[self::MAX_DEPTH_HANDLER])) {
@@ -185,12 +185,12 @@ public function normalize(mixed $object, ?string $format = null, array $context
185185
continue;
186186
}
187187

188-
$attributeContext = $this->getAttributeNormalizationContext($object, $attribute, $context);
188+
$attributeContext = $this->getAttributeNormalizationContext($data, $attribute, $context);
189189

190190
try {
191-
$attributeValue = $attribute === $this->classDiscriminatorResolver?->getMappingForMappedObject($object)?->getTypeProperty()
192-
? $this->classDiscriminatorResolver?->getTypeForMappedObject($object)
193-
: $this->getAttributeValue($object, $attribute, $format, $attributeContext);
191+
$attributeValue = $attribute === $this->classDiscriminatorResolver?->getMappingForMappedObject($data)?->getTypeProperty()
192+
? $this->classDiscriminatorResolver?->getTypeForMappedObject($data)
193+
: $this->getAttributeValue($data, $attribute, $format, $attributeContext);
194194
} catch (UninitializedPropertyException|\Error $e) {
195195
if (($context[self::SKIP_UNINITIALIZED_VALUES] ?? $this->defaultContext[self::SKIP_UNINITIALIZED_VALUES] ?? true) && $this->isUninitializedValueError($e)) {
196196
continue;
@@ -199,17 +199,17 @@ public function normalize(mixed $object, ?string $format = null, array $context
199199
}
200200

201201
if ($maxDepthReached) {
202-
$attributeValue = $maxDepthHandler($attributeValue, $object, $attribute, $format, $attributeContext);
202+
$attributeValue = $maxDepthHandler($attributeValue, $data, $attribute, $format, $attributeContext);
203203
}
204204

205-
$stack[$attribute] = $this->applyCallbacks($attributeValue, $object, $attribute, $format, $attributeContext);
205+
$stack[$attribute] = $this->applyCallbacks($attributeValue, $data, $attribute, $format, $attributeContext);
206206
}
207207

208208
foreach ($stack as $attribute => $attributeValue) {
209-
$attributeContext = $this->getAttributeNormalizationContext($object, $attribute, $context);
209+
$attributeContext = $this->getAttributeNormalizationContext($data, $attribute, $context);
210210

211211
if (null === $attributeValue || \is_scalar($attributeValue)) {
212-
$data = $this->updateData($data, $attribute, $attributeValue, $class, $format, $attributeContext, $attributesMetadata, $classMetadata);
212+
$normalized = $this->updateNormalizedData($normalized, $attribute, $attributeValue, $class, $format, $attributeContext, $attributesMetadata, $classMetadata);
213213
continue;
214214
}
215215

@@ -219,15 +219,15 @@ public function normalize(mixed $object, ?string $format = null, array $context
219219

220220
$childContext = $this->createChildContext($attributeContext, $attribute, $format);
221221

222-
$data = $this->updateData($data, $attribute, $this->serializer->normalize($attributeValue, $format, $childContext), $class, $format, $attributeContext, $attributesMetadata, $classMetadata);
222+
$normalized = $this->updateNormalizedData($normalized, $attribute, $this->serializer->normalize($attributeValue, $format, $childContext), $class, $format, $attributeContext, $attributesMetadata, $classMetadata);
223223
}
224224

225225
$preserveEmptyObjects = $context[self::PRESERVE_EMPTY_OBJECTS] ?? $this->defaultContext[self::PRESERVE_EMPTY_OBJECTS] ?? false;
226-
if ($preserveEmptyObjects && !$data) {
226+
if ($preserveEmptyObjects && !$normalized) {
227227
return new \ArrayObject();
228228
}
229229

230-
return $data;
230+
return $normalized;
231231
}
232232

233233
protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, ?string $format = null): object
@@ -888,7 +888,7 @@ private function getPropertyType(string $className, string $property): Type|arra
888888
/**
889889
* Sets an attribute and apply the name converter if necessary.
890890
*/
891-
private function updateData(array $data, string $attribute, mixed $attributeValue, string $class, ?string $format, array $context, ?array $attributesMetadata, ?ClassMetadataInterface $classMetadata): array
891+
private function updateNormalizedData(array $data, string $attribute, mixed $attributeValue, string $class, ?string $format, array $context, ?array $attributesMetadata, ?ClassMetadataInterface $classMetadata): array
892892
{
893893
if (null === $attributeValue && ($context[self::SKIP_NULL_VALUES] ?? $this->defaultContext[self::SKIP_NULL_VALUES] ?? false)) {
894894
return $data;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public function getSupportedTypes(?string $format): array
3333
];
3434
}
3535

36-
public function normalize(mixed $object, ?string $format = null, array $context = []): int|string
36+
public function normalize(mixed $data, ?string $format = null, array $context = []): int|string
3737
{
38-
if (!$object instanceof \BackedEnum) {
38+
if (!$data instanceof \BackedEnum) {
3939
throw new InvalidArgumentException('The data must belong to a backed enumeration.');
4040
}
4141

42-
return $object->value;
42+
return $data->value;
4343
}
4444

4545
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getSupportedTypes(?string $format): array
4343
];
4444
}
4545

46-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
46+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
4747
{
4848
if (\array_key_exists(self::PAYLOAD_FIELDS, $context)) {
4949
$payloadFieldsToSerialize = $context[self::PAYLOAD_FIELDS];
@@ -59,7 +59,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
5959

6060
$violations = [];
6161
$messages = [];
62-
foreach ($object as $violation) {
62+
foreach ($data as $violation) {
6363
$propertyPath = $this->nameConverter ? $this->nameConverter->normalize($violation->getPropertyPath(), null, $format, $context) : $violation->getPropertyPath();
6464

6565
$violationEntry = [

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function getSupportedTypes(?string $format): array
3030
];
3131
}
3232

33-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
33+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
3434
{
35-
return $object->normalize($this->serializer, $format, $context);
35+
return $data->normalize($this->serializer, $format, $context);
3636
}
3737

3838
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public function getSupportedTypes(?string $format): array
5151
];
5252
}
5353

54-
public function normalize(mixed $object, ?string $format = null, array $context = []): string
54+
public function normalize(mixed $data, ?string $format = null, array $context = []): string
5555
{
56-
if (!$object instanceof \SplFileInfo) {
56+
if (!$data instanceof \SplFileInfo) {
5757
throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".');
5858
}
5959

60-
$mimeType = $this->getMimeType($object);
61-
$splFileObject = $this->extractSplFileObject($object);
60+
$mimeType = $this->getMimeType($data);
61+
$splFileObject = $this->extractSplFileObject($data);
6262

6363
$data = '';
6464

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public function getSupportedTypes(?string $format): array
4343
/**
4444
* @throws InvalidArgumentException
4545
*/
46-
public function normalize(mixed $object, ?string $format = null, array $context = []): string
46+
public function normalize(mixed $data, ?string $format = null, array $context = []): string
4747
{
48-
if (!$object instanceof \DateInterval) {
48+
if (!$data instanceof \DateInterval) {
4949
throw new InvalidArgumentException('The object must be an instance of "\DateInterval".');
5050
}
5151

52-
return $object->format($context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY]);
52+
return $data->format($context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY]);
5353
}
5454

5555
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ public function getSupportedTypes(?string $format): array
6060
/**
6161
* @throws InvalidArgumentException
6262
*/
63-
public function normalize(mixed $object, ?string $format = null, array $context = []): int|float|string
63+
public function normalize(mixed $data, ?string $format = null, array $context = []): int|float|string
6464
{
65-
if (!$object instanceof \DateTimeInterface) {
65+
if (!$data instanceof \DateTimeInterface) {
6666
throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
6767
}
6868

6969
$dateTimeFormat = $context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY];
7070
$timezone = $this->getTimezone($context);
7171

7272
if (null !== $timezone) {
73-
$object = clone $object;
74-
$object = $object->setTimezone($timezone);
73+
$data = clone $data;
74+
$data = $data->setTimezone($timezone);
7575
}
7676

7777
return match ($context[self::CAST_KEY] ?? $this->defaultContext[self::CAST_KEY] ?? false) {
78-
'int' => (int) $object->format($dateTimeFormat),
79-
'float' => (float) $object->format($dateTimeFormat),
80-
default => $object->format($dateTimeFormat),
78+
'int' => (int) $data->format($dateTimeFormat),
79+
'float' => (float) $data->format($dateTimeFormat),
80+
default => $data->format($dateTimeFormat),
8181
};
8282
}
8383

0 commit comments

Comments
 (0)