diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php b/src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php index e68927559fac1..19b2a7f457273 100644 --- a/src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php +++ b/src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php @@ -26,20 +26,20 @@ final class FlattenExceptionNormalizer implements DenormalizerInterface, Normali { use NormalizerAwareTrait; - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { return [ - 'message' => $object->getMessage(), - 'code' => $object->getCode(), - 'headers' => $object->getHeaders(), - 'class' => $object->getClass(), - 'file' => $object->getFile(), - 'line' => $object->getLine(), - 'previous' => null === $object->getPrevious() ? null : $this->normalize($object->getPrevious(), $format, $context), - 'status' => $object->getStatusCode(), - 'status_text' => $object->getStatusText(), - 'trace' => $object->getTrace(), - 'trace_as_string' => $object->getTraceAsString(), + 'message' => $data->getMessage(), + 'code' => $data->getCode(), + 'headers' => $data->getHeaders(), + 'class' => $data->getClass(), + 'file' => $data->getFile(), + 'line' => $data->getLine(), + 'previous' => null === $data->getPrevious() ? null : $this->normalize($data->getPrevious(), $format, $context), + 'status' => $data->getStatusCode(), + 'status_text' => $data->getStatusText(), + 'trace' => $data->getTrace(), + 'trace_as_string' => $data->getTraceAsString(), ]; } diff --git a/src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php b/src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php index 1b143e295f5a7..d737f5b361bc8 100644 --- a/src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php +++ b/src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php @@ -40,14 +40,14 @@ public function getSupportedTypes(?string $format): array return $this->normalizer->getSupportedTypes($format); } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { if (!$this->normalizer instanceof NormalizerInterface) { throw new \BadMethodCallException(\sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class)); } $startTime = microtime(true); - $normalized = $this->normalizer->normalize($object, $format, $context); + $normalized = $this->normalizer->normalize($data, $format, $context); $time = microtime(true) - $startTime; if ($traceId = ($context[TraceableSerializer::DEBUG_TRACE_ID] ?? null)) { diff --git a/src/Symfony/Component/Serializer/Debug/TraceableSerializer.php b/src/Symfony/Component/Serializer/Debug/TraceableSerializer.php index a05bf4bf8655c..bd4f505f8acf9 100644 --- a/src/Symfony/Component/Serializer/Debug/TraceableSerializer.php +++ b/src/Symfony/Component/Serializer/Debug/TraceableSerializer.php @@ -66,17 +66,17 @@ public function deserialize(mixed $data, string $type, string $format, array $co return $result; } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { $context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4)); $startTime = microtime(true); - $result = $this->serializer->normalize($object, $format, $context); + $result = $this->serializer->normalize($data, $format, $context); $time = microtime(true) - $startTime; $caller = $this->getCaller(__FUNCTION__, NormalizerInterface::class); - $this->dataCollector->collectNormalize($traceId, $object, $format, $context, $time, $caller, $this->serializerName); + $this->dataCollector->collectNormalize($traceId, $data, $format, $context, $time, $caller, $this->serializerName); return $result; } diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index fb45a924bee70..32d1c906f9377 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -154,7 +154,7 @@ public function supportsNormalization(mixed $data, ?string $format = null, array return \is_object($data) && !$data instanceof \Traversable; } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { $context['_read_attributes'] = true; @@ -164,14 +164,14 @@ public function normalize(mixed $object, ?string $format = null, array $context $this->validateCallbackContext($context); - if ($this->isCircularReference($object, $context)) { - return $this->handleCircularReference($object, $format, $context); + if ($this->isCircularReference($data, $context)) { + return $this->handleCircularReference($data, $format, $context); } - $data = []; + $normalizedData = []; $stack = []; - $attributes = $this->getAttributes($object, $format, $context); - $class = ($this->objectClassResolver)($object); + $attributes = $this->getAttributes($data, $format, $context); + $class = ($this->objectClassResolver)($data); $classMetadata = $this->classMetadataFactory?->getMetadataFor($class); $attributesMetadata = $this->classMetadataFactory?->getMetadataFor($class)->getAttributesMetadata(); if (isset($context[self::MAX_DEPTH_HANDLER])) { @@ -189,12 +189,12 @@ public function normalize(mixed $object, ?string $format = null, array $context continue; } - $attributeContext = $this->getAttributeNormalizationContext($object, $attribute, $context); + $attributeContext = $this->getAttributeNormalizationContext($data, $attribute, $context); try { - $attributeValue = $attribute === $this->classDiscriminatorResolver?->getMappingForMappedObject($object)?->getTypeProperty() - ? $this->classDiscriminatorResolver?->getTypeForMappedObject($object) - : $this->getAttributeValue($object, $attribute, $format, $attributeContext); + $attributeValue = $attribute === $this->classDiscriminatorResolver?->getMappingForMappedObject($data)?->getTypeProperty() + ? $this->classDiscriminatorResolver?->getTypeForMappedObject($data) + : $this->getAttributeValue($data, $attribute, $format, $attributeContext); } catch (UninitializedPropertyException|\Error $e) { if (($context[self::SKIP_UNINITIALIZED_VALUES] ?? $this->defaultContext[self::SKIP_UNINITIALIZED_VALUES] ?? true) && $this->isUninitializedValueError($e)) { continue; @@ -203,17 +203,17 @@ public function normalize(mixed $object, ?string $format = null, array $context } if ($maxDepthReached) { - $attributeValue = $maxDepthHandler($attributeValue, $object, $attribute, $format, $attributeContext); + $attributeValue = $maxDepthHandler($attributeValue, $data, $attribute, $format, $attributeContext); } - $stack[$attribute] = $this->applyCallbacks($attributeValue, $object, $attribute, $format, $attributeContext); + $stack[$attribute] = $this->applyCallbacks($attributeValue, $data, $attribute, $format, $attributeContext); } foreach ($stack as $attribute => $attributeValue) { - $attributeContext = $this->getAttributeNormalizationContext($object, $attribute, $context); + $attributeContext = $this->getAttributeNormalizationContext($data, $attribute, $context); if (null === $attributeValue || \is_scalar($attributeValue)) { - $data = $this->updateData($data, $attribute, $attributeValue, $class, $format, $attributeContext, $attributesMetadata, $classMetadata); + $normalizedData = $this->updateData($normalizedData, $attribute, $attributeValue, $class, $format, $attributeContext, $attributesMetadata, $classMetadata); continue; } @@ -223,15 +223,15 @@ public function normalize(mixed $object, ?string $format = null, array $context $childContext = $this->createChildContext($attributeContext, $attribute, $format); - $data = $this->updateData($data, $attribute, $this->serializer->normalize($attributeValue, $format, $childContext), $class, $format, $attributeContext, $attributesMetadata, $classMetadata); + $normalizedData = $this->updateData($normalizedData, $attribute, $this->serializer->normalize($attributeValue, $format, $childContext), $class, $format, $attributeContext, $attributesMetadata, $classMetadata); } $preserveEmptyObjects = $context[self::PRESERVE_EMPTY_OBJECTS] ?? $this->defaultContext[self::PRESERVE_EMPTY_OBJECTS] ?? false; - if ($preserveEmptyObjects && !$data) { + if ($preserveEmptyObjects && !$normalizedData) { return new \ArrayObject(); } - return $data; + return $normalizedData; } protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, ?string $format = null): object diff --git a/src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php index 3d8e7e7c549da..7d3659c8c1155 100644 --- a/src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php @@ -33,13 +33,13 @@ public function getSupportedTypes(?string $format): array ]; } - public function normalize(mixed $object, ?string $format = null, array $context = []): int|string + public function normalize(mixed $data, ?string $format = null, array $context = []): int|string { - if (!$object instanceof \BackedEnum) { + if (!$data instanceof \BackedEnum) { throw new InvalidArgumentException('The data must belong to a backed enumeration.'); } - return $object->value; + return $data->value; } public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool diff --git a/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php index eda3b758e8792..92e036384dc66 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php @@ -43,7 +43,7 @@ public function getSupportedTypes(?string $format): array ]; } - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { if (\array_key_exists(self::PAYLOAD_FIELDS, $context)) { $payloadFieldsToSerialize = $context[self::PAYLOAD_FIELDS]; @@ -59,7 +59,7 @@ public function normalize(mixed $object, ?string $format = null, array $context $violations = []; $messages = []; - foreach ($object as $violation) { + foreach ($data as $violation) { $propertyPath = $this->nameConverter ? $this->nameConverter->normalize($violation->getPropertyPath(), null, $format, $context) : $violation->getPropertyPath(); $violationEntry = [ diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index d97108312f55c..444c413544f61 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -30,9 +30,9 @@ public function getSupportedTypes(?string $format): array ]; } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { - return $object->normalize($this->serializer, $format, $context); + return $data->normalize($this->serializer, $format, $context); } public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed diff --git a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php index 5ee076be64edd..57ad724c488f1 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -47,27 +47,27 @@ public function getSupportedTypes(?string $format): array return self::SUPPORTED_TYPES; } - public function normalize(mixed $object, ?string $format = null, array $context = []): string + public function normalize(mixed $data, ?string $format = null, array $context = []): string { - if (!$object instanceof \SplFileInfo) { + if (!$data instanceof \SplFileInfo) { throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".'); } - $mimeType = $this->getMimeType($object); - $splFileObject = $this->extractSplFileObject($object); + $mimeType = $this->getMimeType($data); + $splFileObject = $this->extractSplFileObject($data); - $data = ''; + $splFileData = ''; $splFileObject->rewind(); while (!$splFileObject->eof()) { - $data .= $splFileObject->fgets(); + $splFileData .= $splFileObject->fgets(); } if ('text' === explode('/', $mimeType, 2)[0]) { - return \sprintf('data:%s,%s', $mimeType, rawurlencode($data)); + return \sprintf('data:%s,%s', $mimeType, rawurlencode($splFileData)); } - return \sprintf('data:%s;base64,%s', $mimeType, base64_encode($data)); + return \sprintf('data:%s;base64,%s', $mimeType, base64_encode($splFileData)); } public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 05d1a8529e5f6..1ad81ec614c6c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -43,13 +43,13 @@ public function getSupportedTypes(?string $format): array /** * @throws InvalidArgumentException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): string + public function normalize(mixed $data, ?string $format = null, array $context = []): string { - if (!$object instanceof \DateInterval) { + if (!$data instanceof \DateInterval) { throw new InvalidArgumentException('The object must be an instance of "\DateInterval".'); } - return $object->format($context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY]); + return $data->format($context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY]); } public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php index dfc498c19f194..a136ec227a3ae 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -56,9 +56,9 @@ public function getSupportedTypes(?string $format): array /** * @throws InvalidArgumentException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): int|float|string + public function normalize(mixed $data, ?string $format = null, array $context = []): int|float|string { - if (!$object instanceof \DateTimeInterface) { + if (!$data instanceof \DateTimeInterface) { throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".'); } @@ -66,14 +66,14 @@ public function normalize(mixed $object, ?string $format = null, array $context $timezone = $this->getTimezone($context); if (null !== $timezone) { - $object = clone $object; - $object = $object->setTimezone($timezone); + $data = clone $data; + $data = $data->setTimezone($timezone); } return match ($context[self::CAST_KEY] ?? $this->defaultContext[self::CAST_KEY] ?? false) { - 'int' => (int) $object->format($dateTimeFormat), - 'float' => (float) $object->format($dateTimeFormat), - default => $object->format($dateTimeFormat), + 'int' => (int) $data->format($dateTimeFormat), + 'float' => (float) $data->format($dateTimeFormat), + default => $data->format($dateTimeFormat), }; } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php index f4528a03dae40..cdb6eb2f0cb84 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php @@ -31,13 +31,13 @@ public function getSupportedTypes(?string $format): array /** * @throws InvalidArgumentException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): string + public function normalize(mixed $data, ?string $format = null, array $context = []): string { - if (!$object instanceof \DateTimeZone) { + if (!$data instanceof \DateTimeZone) { throw new InvalidArgumentException('The object must be an instance of "\DateTimeZone".'); } - return $object->getName(); + return $data->getName(); } public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool diff --git a/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php index 9ef13a669eba4..c91d7d528bcae 100644 --- a/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php @@ -22,20 +22,20 @@ final class FormErrorNormalizer implements NormalizerInterface public const TYPE = 'type'; public const CODE = 'status_code'; - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $data = [ + $error = [ 'title' => $context[self::TITLE] ?? 'Validation Failed', 'type' => $context[self::TYPE] ?? 'https://symfony.com/errors/form', 'code' => $context[self::CODE] ?? null, - 'errors' => $this->convertFormErrorsToArray($object), + 'errors' => $this->convertFormErrorsToArray($data), ]; - if (0 !== \count($object->all())) { - $data['children'] = $this->convertFormChildrenToArray($object); + if (0 !== \count($data->all())) { + $error['children'] = $this->convertFormChildrenToArray($data); } - return $data; + return $error; } public function getSupportedTypes(?string $format): array diff --git a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php index 31c224175e697..3bc4f280eb495 100644 --- a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php @@ -21,13 +21,13 @@ */ final class JsonSerializableNormalizer extends AbstractNormalizer { - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { - if ($this->isCircularReference($object, $context)) { - return $this->handleCircularReference($object, $format, $context); + if ($this->isCircularReference($data, $context)) { + return $this->handleCircularReference($data, $format, $context); } - if (!$object instanceof \JsonSerializable) { + if (!$data instanceof \JsonSerializable) { throw new InvalidArgumentException(\sprintf('The object must implement "%s".', \JsonSerializable::class)); } @@ -35,7 +35,7 @@ public function normalize(mixed $object, ?string $format = null, array $context throw new LogicException('Cannot normalize object because injected serializer is not a normalizer.'); } - return $this->serializer->normalize($object->jsonSerialize(), $format, $context); + return $this->serializer->normalize($data->jsonSerialize(), $format, $context); } public function getSupportedTypes(?string $format): array diff --git a/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php index 633edf36902f5..5b121338946fe 100644 --- a/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php @@ -62,25 +62,25 @@ public function setSerializer(SerializerInterface $serializer): void $this->normalizer->setSerializer($serializer); } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { - if ($object instanceof Headers) { + if ($data instanceof Headers) { $ret = []; - foreach ($this->headersProperty->getValue($object) as $name => $header) { + foreach ($this->headersProperty->getValue($data) as $name => $header) { $ret[$name] = $this->serializer->normalize($header, $format, $context); } return $ret; } - $ret = $this->normalizer->normalize($object, $format, $context); + $ret = $this->normalizer->normalize($data, $format, $context); - if ($object instanceof AbstractPart) { - $ret['class'] = $object::class; + if ($data instanceof AbstractPart) { + $ret['class'] = $data::class; unset($ret['seekable'], $ret['cid'], $ret['handle']); } - if ($object instanceof RawMessage && \array_key_exists('message', $ret) && null === $ret['message']) { + if ($data instanceof RawMessage && \array_key_exists('message', $ret) && null === $ret['message']) { unset($ret['message']); } diff --git a/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php index 08aca6796cf88..8f255e6cee6d8 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php @@ -57,7 +57,7 @@ public function normalize(mixed $object, ?string $format = null, array $context throw new InvalidArgumentException(\sprintf('The object must implement "%s".', FlattenException::class)); } - $data = []; + $error = []; $context += $this->defaultContext; $debug = $this->debug && ($context['debug'] ?? true); $exception = $context['exception'] ?? null; @@ -67,7 +67,7 @@ public function normalize(mixed $object, ?string $format = null, array $context if ($exception instanceof PartialDenormalizationException) { $trans = $this->translator ? $this->translator->trans(...) : fn ($m, $p) => strtr($m, $p); $template = 'This value should be of type {{ type }}.'; - $data = [ + $error = [ self::TYPE => 'https://symfony.com/errors/validation', self::TITLE => 'Validation Failed', 'violations' => array_map( @@ -84,27 +84,27 @@ public function normalize(mixed $object, ?string $format = null, array $context $exception->getErrors() ), ]; - $data['detail'] = implode("\n", array_map(fn ($e) => $e['propertyPath'].': '.$e['title'], $data['violations'])); + $error['detail'] = implode("\n", array_map(fn ($e) => $e['propertyPath'].': '.$e['title'], $error['violations'])); } elseif (($exception instanceof ValidationFailedException || $exception instanceof MessageValidationFailedException) && $this->serializer instanceof NormalizerInterface && $this->serializer->supportsNormalization($exception->getViolations(), $format, $context) ) { - $data = $this->serializer->normalize($exception->getViolations(), $format, $context); + $error = $this->serializer->normalize($exception->getViolations(), $format, $context); } } - $data = [ - self::TYPE => $data[self::TYPE] ?? $context[self::TYPE] ?? 'https://tools.ietf.org/html/rfc2616#section-10', - self::TITLE => $data[self::TITLE] ?? $context[self::TITLE] ?? 'An error occurred', + $error = [ + self::TYPE => $error[self::TYPE] ?? $context[self::TYPE] ?? 'https://tools.ietf.org/html/rfc2616#section-10', + self::TITLE => $error[self::TITLE] ?? $context[self::TITLE] ?? 'An error occurred', self::STATUS => $context[self::STATUS] ?? $object->getStatusCode(), - 'detail' => $data['detail'] ?? ($debug ? $object->getMessage() : $object->getStatusText()), - ] + $data; + 'detail' => $error['detail'] ?? ($debug ? $object->getMessage() : $object->getStatusText()), + ] + $error; if ($debug) { - $data['class'] = $object->getClass(); - $data['trace'] = $object->getTrace(); + $error['class'] = $object->getClass(); + $error['trace'] = $object->getTrace(); } - return $data; + return $error; } public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool diff --git a/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php index 463616e7248e4..d365598b548d2 100644 --- a/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/TranslatableNormalizer.php @@ -34,13 +34,13 @@ public function __construct( /** * @throws InvalidArgumentException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): string + public function normalize(mixed $data, ?string $format = null, array $context = []): string { - if (!$object instanceof TranslatableInterface) { - throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The object must implement the "%s".', TranslatableInterface::class), $object, [TranslatableInterface::class]); + if (!$data instanceof TranslatableInterface) { + throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The object must implement the "%s".', TranslatableInterface::class), $data, [TranslatableInterface::class]); } - return $object->trans($this->translator, $context[self::NORMALIZATION_LOCALE_KEY] ?? $this->defaultContext[self::NORMALIZATION_LOCALE_KEY]); + return $data->trans($this->translator, $context[self::NORMALIZATION_LOCALE_KEY] ?? $this->defaultContext[self::NORMALIZATION_LOCALE_KEY]); } public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool diff --git a/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php index 0bee1f704511e..eb624eed197bd 100644 --- a/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php @@ -48,16 +48,13 @@ public function getSupportedTypes(?string $format): array ]; } - /** - * @param AbstractUid $object - */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { return match ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) { - self::NORMALIZATION_FORMAT_CANONICAL => (string) $object, - self::NORMALIZATION_FORMAT_BASE58 => $object->toBase58(), - self::NORMALIZATION_FORMAT_BASE32 => $object->toBase32(), - self::NORMALIZATION_FORMAT_RFC4122 => $object->toRfc4122(), + self::NORMALIZATION_FORMAT_CANONICAL => (string) $data, + self::NORMALIZATION_FORMAT_BASE58 => $data->toBase58(), + self::NORMALIZATION_FORMAT_BASE32 => $data->toBase32(), + self::NORMALIZATION_FORMAT_RFC4122 => $data->toRfc4122(), default => throw new LogicException(\sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY])), }; } diff --git a/src/Symfony/Component/Serializer/Tests/Debug/TraceableSerializerTest.php b/src/Symfony/Component/Serializer/Tests/Debug/TraceableSerializerTest.php index d697b270ff958..9092433214abf 100644 --- a/src/Symfony/Component/Serializer/Tests/Debug/TraceableSerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Debug/TraceableSerializerTest.php @@ -142,7 +142,7 @@ public function deserialize(mixed $data, string $type, string $format, array $co return 'deserialized'; } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { return 'normalized'; } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php index f5bf565a1b373..3945a10804cec 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php @@ -30,7 +30,7 @@ public function getAllowedAttributes(string|object $classOrObject, array $contex return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString); } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopeNormalizer.php b/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopeNormalizer.php index 4acfdf8304743..7d085ad9afc28 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopeNormalizer.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopeNormalizer.php @@ -20,9 +20,9 @@ class EnvelopeNormalizer implements NormalizerInterface { private $serializer; - public function normalize($envelope, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $xmlContent = $this->serializer->serialize($envelope->message, 'xml'); + $xmlContent = $this->serializer->serialize($data->message, 'xml'); $encodedContent = base64_encode($xmlContent); diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopedMessageNormalizer.php b/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopedMessageNormalizer.php index 812dbf015730a..e907b00a57d99 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopedMessageNormalizer.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopedMessageNormalizer.php @@ -18,10 +18,10 @@ */ class EnvelopedMessageNormalizer implements NormalizerInterface { - public function normalize($message, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { return [ - 'text' => $message->text, + 'text' => $data->text, ]; } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php index d45586b4444ee..231448d4c0b50 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php @@ -85,11 +85,14 @@ class ObjectNormalizerTest extends TestCase use TypeEnforcementTestTrait; private ObjectNormalizer $normalizer; + private NormalizerInterface $normalizerInterface; private SerializerInterface&NormalizerInterface&MockObject $serializer; protected function setUp(): void { $this->createNormalizer(); + + $this->normalizerInterface = $this->normalizer; } private function createNormalizer(array $defaultContext = [], ?ClassMetadataFactoryInterface $classMetadataFactory = null): void diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php b/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php index 941fef42b067a..6c6e930666eeb 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php @@ -20,7 +20,7 @@ */ class TestNormalizer implements NormalizerInterface { - public function normalize($object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { return null; }