diff --git a/src/Elasticsearch/Serializer/DocumentNormalizer.php b/src/Elasticsearch/Serializer/DocumentNormalizer.php index 1d523d66633..d9a816cf87b 100644 --- a/src/Elasticsearch/Serializer/DocumentNormalizer.php +++ b/src/Elasticsearch/Serializer/DocumentNormalizer.php @@ -64,13 +64,13 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form /** * {@inheritdoc} */ - public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if (\is_string($data['_id'] ?? null) && \is_array($data['_source'] ?? null)) { - $data = $this->populateIdentifier($data, $class)['_source']; + $data = $this->populateIdentifier($data, $type)['_source']; } - return $this->decoratedNormalizer->denormalize($data, $class, $format, $context); + return $this->decoratedNormalizer->denormalize($data, $type, $format, $context); } /** @@ -87,7 +87,7 @@ public function supportsNormalization(mixed $data, ?string $format = null, array * * @throws LogicException */ - 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 { throw new LogicException(\sprintf('%s is a write-only format.', self::FORMAT)); } diff --git a/src/Elasticsearch/Serializer/ItemNormalizer.php b/src/Elasticsearch/Serializer/ItemNormalizer.php index 01c5020a40e..e3cece34f23 100644 --- a/src/Elasticsearch/Serializer/ItemNormalizer.php +++ b/src/Elasticsearch/Serializer/ItemNormalizer.php @@ -64,9 +64,9 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { - return $this->decorated->normalize($object, $format, $context); + return $this->decorated->normalize($data, $format, $context); } /** @@ -78,9 +78,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : []; } diff --git a/src/Elasticsearch/Tests/Serializer/ItemNormalizerTest.php b/src/Elasticsearch/Tests/Serializer/ItemNormalizerTest.php index 7819eb3951c..9382aed52fb 100644 --- a/src/Elasticsearch/Tests/Serializer/ItemNormalizerTest.php +++ b/src/Elasticsearch/Tests/Serializer/ItemNormalizerTest.php @@ -66,18 +66,18 @@ public function testSupportsDenormalization(): void public function testNormalize(): void { - $this->normalizerProphecy->normalize($object = (object) ['foo'], 'json', ['groups' => 'foo'])->willReturn(['foo'])->shouldBeCalledOnce(); + $this->normalizerProphecy->normalize($data = (object) ['foo'], 'json', ['groups' => 'foo'])->willReturn(['foo'])->shouldBeCalledOnce(); - self::assertEquals(['foo'], $this->itemNormalizer->normalize($object, 'json', ['groups' => 'foo'])); + self::assertEquals(['foo'], $this->itemNormalizer->normalize($data, 'json', ['groups' => 'foo'])); } public function testSupportsNormalization(): void { - $this->normalizerProphecy->supportsNormalization($object = (object) ['foo'], 'json')->willReturn(true)->shouldBeCalledOnce(); - $this->normalizerProphecy->supportsNormalization($object, DocumentNormalizer::FORMAT)->shouldNotBeCalled(); + $this->normalizerProphecy->supportsNormalization($data = (object) ['foo'], 'json')->willReturn(true)->shouldBeCalledOnce(); + $this->normalizerProphecy->supportsNormalization($data, DocumentNormalizer::FORMAT)->shouldNotBeCalled(); - self::assertTrue($this->itemNormalizer->supportsNormalization($object, 'json')); - self::assertFalse($this->itemNormalizer->supportsNormalization($object, DocumentNormalizer::FORMAT)); + self::assertTrue($this->itemNormalizer->supportsNormalization($data, 'json')); + self::assertFalse($this->itemNormalizer->supportsNormalization($data, DocumentNormalizer::FORMAT)); } public function testSetSerializer(): void @@ -115,7 +115,7 @@ public function testGetSupportedTypes(): void { // TODO: use prophecy when getSupportedTypes() will be added to the interface $this->itemNormalizer = new ItemNormalizer(new class implements NormalizerInterface { - public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + public function normalize(mixed $data, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null { return null; } diff --git a/src/GraphQl/Serializer/Exception/ErrorNormalizer.php b/src/GraphQl/Serializer/Exception/ErrorNormalizer.php index 47e8721df45..cb01320874e 100644 --- a/src/GraphQl/Serializer/Exception/ErrorNormalizer.php +++ b/src/GraphQl/Serializer/Exception/ErrorNormalizer.php @@ -27,9 +27,9 @@ final class ErrorNormalizer implements NormalizerInterface /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - return FormattedError::createFromException($object); + return FormattedError::createFromException($data); } /** @@ -41,9 +41,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return [ Error::class => true, diff --git a/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php b/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php index 86b3242b159..3843ddd6524 100644 --- a/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php +++ b/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php @@ -28,11 +28,11 @@ final class HttpExceptionNormalizer implements NormalizerInterface /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { /** @var HttpExceptionInterface */ - $httpException = $object->getPrevious(); - $error = FormattedError::createFromException($object); + $httpException = $data->getPrevious(); + $error = FormattedError::createFromException($data); $error['message'] = $httpException->getMessage(); $error['extensions']['status'] = $statusCode = $httpException->getStatusCode(); // graphql-php < 15 @@ -52,9 +52,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return [ Error::class => false, diff --git a/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php b/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php index bc12ff5ebdf..1b1a5ab9412 100644 --- a/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php +++ b/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php @@ -27,11 +27,11 @@ final class RuntimeExceptionNormalizer implements NormalizerInterface /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { /** @var \RuntimeException */ - $runtimeException = $object->getPrevious(); - $error = FormattedError::createFromException($object); + $runtimeException = $data->getPrevious(); + $error = FormattedError::createFromException($data); $error['message'] = $runtimeException->getMessage(); return $error; @@ -46,9 +46,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return [ Error::class => false, diff --git a/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php b/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php index b792fb15b89..fcc325bf43b 100644 --- a/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php +++ b/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php @@ -35,14 +35,14 @@ public function __construct(private readonly array $exceptionToStatus = []) /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $validationException = $object->getPrevious(); + $validationException = $data->getPrevious(); if (!$validationException instanceof ConstraintViolationListAwareExceptionInterface) { throw new RuntimeException(\sprintf('Object is not a "%s".', ConstraintViolationListAwareExceptionInterface::class)); } - $error = FormattedError::createFromException($object); + $error = FormattedError::createFromException($data); $error['message'] = $validationException->getMessage(); $exceptionClass = $validationException::class; @@ -81,9 +81,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return [ Error::class => false, diff --git a/src/GraphQl/Serializer/ItemNormalizer.php b/src/GraphQl/Serializer/ItemNormalizer.php index 1948733e1d2..1d94476c787 100644 --- a/src/GraphQl/Serializer/ItemNormalizer.php +++ b/src/GraphQl/Serializer/ItemNormalizer.php @@ -63,9 +63,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; } @@ -77,17 +77,17 @@ public function getSupportedTypes($format): array * * @throws UnexpectedValueException */ - 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 { - $resourceClass = $this->getObjectClass($object); + $resourceClass = $this->getObjectClass($data); if ($this->getOutputClass($context)) { $context['graphql_identifiers'] = [ self::ITEM_RESOURCE_CLASS_KEY => $context['operation']->getClass(), - self::ITEM_IDENTIFIERS_KEY => $this->identifiersExtractor->getIdentifiersFromItem($object, $context['operation'] ?? null), + self::ITEM_IDENTIFIERS_KEY => $this->identifiersExtractor->getIdentifiersFromItem($data, $context['operation'] ?? null), ]; - return parent::normalize($object, $format, $context); + return parent::normalize($data, $format, $context); } if ($this->isCacheKeySafe($context)) { @@ -97,19 +97,19 @@ public function normalize(mixed $object, ?string $format = null, array $context } unset($context['operation_name'], $context['operation']); // Remove operation and operation_name only when cache key has been created - $data = parent::normalize($object, $format, $context); - if (!\is_array($data)) { + $normalizedData = parent::normalize($data, $format, $context); + if (!\is_array($normalizedData)) { throw new UnexpectedValueException('Expected data to be an array.'); } if (isset($context['graphql_identifiers'])) { - $data += $context['graphql_identifiers']; + $normalizedData += $context['graphql_identifiers']; } elseif (!($context['no_resolver_data'] ?? false)) { - $data[self::ITEM_RESOURCE_CLASS_KEY] = $resourceClass; - $data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($object, $context['operation'] ?? null); + $normalizedData[self::ITEM_RESOURCE_CLASS_KEY] = $resourceClass; + $normalizedData[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($data, $context['operation'] ?? null); } - return $data; + return $normalizedData; } /** @@ -152,12 +152,8 @@ protected function getAllowedAttributes(string|object $classOrObject, array $con /** * {@inheritdoc} - * - * @param object $object - * @param string $attribute - * @param string|null $format */ - protected function setAttributeValue($object, $attribute, mixed $value, $format = null, array $context = []): void + protected function setAttributeValue(object $object, string $attribute, mixed $value, ?string $format = null, array $context = []): void { if ('_id' === $attribute) { $attribute = 'id'; diff --git a/src/GraphQl/Serializer/ObjectNormalizer.php b/src/GraphQl/Serializer/ObjectNormalizer.php index 4d19750a560..08525475f55 100644 --- a/src/GraphQl/Serializer/ObjectNormalizer.php +++ b/src/GraphQl/Serializer/ObjectNormalizer.php @@ -44,9 +44,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; } @@ -56,32 +56,32 @@ public function getSupportedTypes($format): array * * @throws UnexpectedValueException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { if (isset($context['api_resource'])) { $originalResource = $context['api_resource']; unset($context['api_resource']); } - $data = $this->decorated->normalize($object, $format, $context); - if (!\is_array($data)) { + $normalizedData = $this->decorated->normalize($data, $format, $context); + if (!\is_array($normalizedData)) { throw new UnexpectedValueException('Expected data to be an array.'); } if (!isset($originalResource)) { - return $data; + return $normalizedData; } - if (isset($data['id'])) { - $data['_id'] = $data['id']; - $data['id'] = $this->iriConverter->getIriFromResource($originalResource); + if (isset($normalizedData['id'])) { + $normalizedData['_id'] = $normalizedData['id']; + $normalizedData['id'] = $this->iriConverter->getIriFromResource($originalResource); } if (!($context['no_resolver_data'] ?? false)) { - $data[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($originalResource); - $data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($originalResource); + $normalizedData[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($originalResource); + $normalizedData[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($originalResource); } - return $data; + return $normalizedData; } } diff --git a/src/Hal/Serializer/EntrypointNormalizer.php b/src/Hal/Serializer/EntrypointNormalizer.php index d8c8399c9fd..5a516d1e83e 100644 --- a/src/Hal/Serializer/EntrypointNormalizer.php +++ b/src/Hal/Serializer/EntrypointNormalizer.php @@ -38,11 +38,11 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { $entrypoint = ['_links' => ['self' => ['href' => $this->urlGenerator->generate('api_entrypoint')]]]; - foreach ($object->getResourceNameCollection() as $resourceClass) { + foreach ($data->getResourceNameCollection() as $resourceClass) { $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass); foreach ($resourceMetadata as $resource) { @@ -74,9 +74,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? [Entrypoint::class => true] : []; } diff --git a/src/Hal/Serializer/ItemNormalizer.php b/src/Hal/Serializer/ItemNormalizer.php index d0a54141329..effc2267d94 100644 --- a/src/Hal/Serializer/ItemNormalizer.php +++ b/src/Hal/Serializer/ItemNormalizer.php @@ -82,9 +82,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; } @@ -92,22 +92,22 @@ public function getSupportedTypes($format): array /** * {@inheritdoc} */ - 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 { - $resourceClass = $this->getObjectClass($object); + $resourceClass = $this->getObjectClass($data); if ($this->getOutputClass($context)) { - return parent::normalize($object, $format, $context); + return parent::normalize($data, $format, $context); } $previousResourceClass = $context['resource_class'] ?? null; if ($this->resourceClassResolver->isResourceClass($resourceClass) && (null === $previousResourceClass || $this->resourceClassResolver->isResourceClass($previousResourceClass))) { - $resourceClass = $this->resourceClassResolver->getResourceClass($object, $previousResourceClass); + $resourceClass = $this->resourceClassResolver->getResourceClass($data, $previousResourceClass); } $context = $this->initContext($resourceClass, $context); - $iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context); - $context['object'] = $object; + $iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($data, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context); + $context['object'] = $data; $context['format'] = $format; $context['api_normalize'] = true; @@ -115,10 +115,10 @@ public function normalize(mixed $object, ?string $format = null, array $context $context['cache_key'] = $this->getCacheKey($format, $context); } - $data = parent::normalize($object, $format, $context); + $normalizedData = parent::normalize($data, $format, $context); - if (!\is_array($data)) { - return $data; + if (!\is_array($normalizedData)) { + return $normalizedData; } $metadata = [ @@ -128,11 +128,11 @@ public function normalize(mixed $object, ?string $format = null, array $context ], ], ]; - $components = $this->getComponents($object, $format, $context); - $metadata = $this->populateRelation($metadata, $object, $format, $context, $components, 'links'); - $metadata = $this->populateRelation($metadata, $object, $format, $context, $components, 'embedded'); + $components = $this->getComponents($data, $format, $context); + $metadata = $this->populateRelation($metadata, $data, $format, $context, $components, 'links'); + $metadata = $this->populateRelation($metadata, $data, $format, $context, $components, 'embedded'); - return $metadata + $data; + return $metadata + $normalizedData; } /** diff --git a/src/Hal/Serializer/ObjectNormalizer.php b/src/Hal/Serializer/ObjectNormalizer.php index ef1d480a811..5e52ca9075c 100644 --- a/src/Hal/Serializer/ObjectNormalizer.php +++ b/src/Hal/Serializer/ObjectNormalizer.php @@ -39,9 +39,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; } @@ -49,20 +49,20 @@ public function getSupportedTypes($format): array /** * {@inheritdoc} */ - 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 (isset($context['api_resource'])) { $originalResource = $context['api_resource']; unset($context['api_resource']); } - $data = $this->decorated->normalize($object, $format, $context); - if (!\is_array($data)) { - return $data; + $normalizedData = $this->decorated->normalize($data, $format, $context); + if (!\is_array($normalizedData)) { + return $normalizedData; } if (!isset($originalResource)) { - return $data; + return $normalizedData; } $metadata = [ @@ -73,7 +73,7 @@ public function normalize(mixed $object, ?string $format = null, array $context ], ]; - return $metadata + $data; + return $metadata + $normalizedData; } /** diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index c527a32f544..9625e992260 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -61,9 +61,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return $this->collectionNormalizer->getSupportedTypes($format); } @@ -71,32 +71,32 @@ public function getSupportedTypes($format): array /** * {@inheritdoc} */ - 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 (($context[AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS] ?? false) && $object instanceof \ArrayObject && !\count($object)) { - return $object; + if (($context[AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS] ?? false) && $data instanceof \ArrayObject && !\count($data)) { + return $data; } - $data = $this->collectionNormalizer->normalize($object, $format, $context); + $normalizedData = $this->collectionNormalizer->normalize($data, $format, $context); if (!isset($context['resource_class']) || isset($context['api_sub_level'])) { - return $data; + return $normalizedData; } - if (!\is_array($data)) { + if (!\is_array($normalizedData)) { throw new UnexpectedValueException('Expected data to be an array'); } - $resourceClass = $this->resourceClassResolver->getResourceClass($object, $context['resource_class']); + $resourceClass = $this->resourceClassResolver->getResourceClass($data, $context['resource_class']); $operation = $context['operation'] ?? $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation($context['operation_name'] ?? null); $parameters = $operation->getParameters(); $resourceFilters = $operation->getFilters(); if (!$resourceFilters && !$parameters) { - return $data; + return $normalizedData; } $requestParts = parse_url($context['request_uri'] ?? ''); if (!\is_array($requestParts)) { - return $data; + return $normalizedData; } $currentFilters = []; foreach ($resourceFilters as $filterId) { @@ -110,7 +110,7 @@ public function normalize(mixed $object, ?string $format = null, array $context if ($currentFilters || ($parameters && \count($parameters))) { $hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext); ['mapping' => $mapping, 'keys' => $keys] = $this->getSearchMappingAndKeys($operation, $resourceClass, $currentFilters, $parameters, [$this, 'getFilter']); - $data[$hydraPrefix.'search'] = [ + $normalizedData[$hydraPrefix.'search'] = [ '@type' => $hydraPrefix.'IriTemplate', $hydraPrefix.'template' => \sprintf('%s{?%s}', $requestParts['path'], implode(',', $keys)), $hydraPrefix.'variableRepresentation' => 'BasicRepresentation', @@ -118,7 +118,7 @@ public function normalize(mixed $object, ?string $format = null, array $context ]; } - return $data; + return $normalizedData; } /** diff --git a/src/Hydra/Serializer/ConstraintViolationListNormalizer.php b/src/Hydra/Serializer/ConstraintViolationListNormalizer.php index 0b24fcb0fa0..38df693497e 100644 --- a/src/Hydra/Serializer/ConstraintViolationListNormalizer.php +++ b/src/Hydra/Serializer/ConstraintViolationListNormalizer.php @@ -35,9 +35,9 @@ public function __construct(?array $serializePayloadFields = null, ?NameConverte /** * {@inheritdoc} */ - 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 { - [, $violations] = $this->getMessagesAndViolations($object); + [, $violations] = $this->getMessagesAndViolations($data); return $violations; } diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index b565fc4e0c6..08f5800cb98 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -67,13 +67,13 @@ public function __construct( /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { $classes = []; $entrypointProperties = []; $hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext); - foreach ($object->getResourceNameCollection() as $resourceClass) { + foreach ($data->getResourceNameCollection() as $resourceClass) { $resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass); $resourceMetadata = $resourceMetadataCollection[0]; @@ -88,7 +88,7 @@ public function normalize(mixed $object, ?string $format = null, array $context $classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $hydraPrefix, $resourceMetadataCollection); } - return $this->computeDoc($object, $this->getClasses($entrypointProperties, $classes, $hydraPrefix), $hydraPrefix); + return $this->computeDoc($data, $this->getClasses($entrypointProperties, $classes, $hydraPrefix), $hydraPrefix); } /** @@ -686,9 +686,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? [Documentation::class => true] : []; } diff --git a/src/Hydra/Serializer/EntrypointNormalizer.php b/src/Hydra/Serializer/EntrypointNormalizer.php index 77dda8539eb..8ff3327b6ff 100644 --- a/src/Hydra/Serializer/EntrypointNormalizer.php +++ b/src/Hydra/Serializer/EntrypointNormalizer.php @@ -38,7 +38,7 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { $entrypoint = [ '@context' => $this->urlGenerator->generate('api_jsonld_context', ['shortName' => 'Entrypoint']), @@ -46,7 +46,7 @@ public function normalize(mixed $object, ?string $format = null, array $context '@type' => 'Entrypoint', ]; - foreach ($object->getResourceNameCollection() as $resourceClass) { + foreach ($data->getResourceNameCollection() as $resourceClass) { $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass); foreach ($resourceMetadata as $resource) { @@ -83,9 +83,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? [Entrypoint::class => true] : []; } diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index c37586f7e95..52c32173777 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -50,21 +50,21 @@ public function __construct(private readonly NormalizerInterface $collectionNorm /** * {@inheritdoc} */ - 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 { - $data = $this->collectionNormalizer->normalize($object, $format, $context); + $normalizedData = $this->collectionNormalizer->normalize($data, $format, $context); if (isset($context['api_sub_level'])) { - return $data; + return $normalizedData; } - if (!\is_array($data)) { + if (!\is_array($normalizedData)) { throw new UnexpectedValueException('Expected data to be an array'); } - $paginated = $object instanceof PartialPaginatorInterface; - if ($paginated && $object instanceof PaginatorInterface) { - $paginated = 1. !== $object->getLastPage(); + $paginated = $data instanceof PartialPaginatorInterface; + if ($paginated && $data instanceof PaginatorInterface) { + $paginated = 1. !== $data->getLastPage(); } $parsed = IriHelper::parseIri($context['uri'] ?? $context['request_uri'] ?? '/', $this->pageParameterName); @@ -72,7 +72,7 @@ public function normalize(mixed $object, ?string $format = null, array $context unset($appliedFilters[$this->enabledParameterName]); if (!$appliedFilters && !$paginated) { - return $data; + return $normalizedData; } $isPaginatedWithCursor = false; @@ -88,12 +88,12 @@ public function normalize(mixed $object, ?string $format = null, array $context $hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext); if ($isPaginatedWithCursor) { - $data[$hydraPrefix.'view'] = ['@id' => null, '@type' => $hydraPrefix.'PartialCollectionView']; + $normalizedData[$hydraPrefix.'view'] = ['@id' => null, '@type' => $hydraPrefix.'PartialCollectionView']; - return $this->populateDataWithCursorBasedPagination($data, $parsed, $object, $cursorPaginationAttribute, $operation?->getUrlGenerationStrategy() ?? $this->urlGenerationStrategy, $hydraPrefix); + return $this->populateDataWithCursorBasedPagination($normalizedData, $parsed, $data, $cursorPaginationAttribute, $operation?->getUrlGenerationStrategy() ?? $this->urlGenerationStrategy, $hydraPrefix); } - $partialCollectionView = $this->getPartialCollectionView($object, $context['uri'] ?? $context['request_uri'] ?? '/', $this->pageParameterName, $this->enabledParameterName, $operation?->getUrlGenerationStrategy() ?? $this->urlGenerationStrategy); + $partialCollectionView = $this->getPartialCollectionView($data, $context['uri'] ?? $context['request_uri'] ?? '/', $this->pageParameterName, $this->enabledParameterName, $operation?->getUrlGenerationStrategy() ?? $this->urlGenerationStrategy); $view = [ '@id' => $partialCollectionView->id, @@ -113,9 +113,9 @@ public function normalize(mixed $object, ?string $format = null, array $context $view[$hydraPrefix.'next'] = $partialCollectionView->next; } - $data[$hydraPrefix.'view'] = $view; + $normalizedData[$hydraPrefix.'view'] = $view; - return $data; + return $normalizedData; } /** @@ -127,9 +127,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return $this->collectionNormalizer->getSupportedTypes($format); } diff --git a/src/Hydra/Tests/Serializer/CollectionFiltersNormalizerTest.php b/src/Hydra/Tests/Serializer/CollectionFiltersNormalizerTest.php index 6943b8db13c..bb2ff50c3af 100644 --- a/src/Hydra/Tests/Serializer/CollectionFiltersNormalizerTest.php +++ b/src/Hydra/Tests/Serializer/CollectionFiltersNormalizerTest.php @@ -332,7 +332,7 @@ public function testGetSupportedTypes(): void // TODO: use prophecy when getSupportedTypes() will be added to the interface $normalizer = new CollectionFiltersNormalizer( new class implements NormalizerInterface { - public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + public function normalize(mixed $data, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null { return null; } diff --git a/src/Hydra/Tests/Serializer/PartialCollectionViewNormalizerTest.php b/src/Hydra/Tests/Serializer/PartialCollectionViewNormalizerTest.php index 2b13ef703df..49b7a194a16 100644 --- a/src/Hydra/Tests/Serializer/PartialCollectionViewNormalizerTest.php +++ b/src/Hydra/Tests/Serializer/PartialCollectionViewNormalizerTest.php @@ -193,7 +193,7 @@ public function testGetSupportedTypes(): void // TODO: use prophecy when getSupportedTypes() will be added to the interface $normalizer = new PartialCollectionViewNormalizer(new class implements NormalizerInterface { - public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + public function normalize(mixed $data, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null { return null; } diff --git a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php index fc87afcae7c..3d25656f161 100644 --- a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php +++ b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php @@ -37,10 +37,10 @@ public function __construct(private readonly PropertyMetadataFactoryInterface $p /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { $violations = []; - foreach ($object as $violation) { + foreach ($data as $violation) { $violations[] = [ 'detail' => $violation->getMessage(), 'source' => [ @@ -61,9 +61,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? [ConstraintViolationListInterface::class => true] : []; } diff --git a/src/JsonApi/Serializer/EntrypointNormalizer.php b/src/JsonApi/Serializer/EntrypointNormalizer.php index 394bcb3cc39..a7a6f677cde 100644 --- a/src/JsonApi/Serializer/EntrypointNormalizer.php +++ b/src/JsonApi/Serializer/EntrypointNormalizer.php @@ -39,11 +39,11 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { $entrypoint = ['links' => ['self' => $this->urlGenerator->generate('api_entrypoint', [], UrlGeneratorInterface::ABS_URL)]]; - foreach ($object->getResourceNameCollection() as $resourceClass) { + foreach ($data->getResourceNameCollection() as $resourceClass) { $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass); foreach ($resourceMetadata as $resource) { @@ -74,9 +74,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? [Entrypoint::class => true] : []; } diff --git a/src/JsonApi/Serializer/ErrorNormalizer.php b/src/JsonApi/Serializer/ErrorNormalizer.php index 4875b28181e..3b6d2fba917 100644 --- a/src/JsonApi/Serializer/ErrorNormalizer.php +++ b/src/JsonApi/Serializer/ErrorNormalizer.php @@ -32,17 +32,17 @@ public function __construct(private ?NormalizerInterface $itemNormalizer = null) /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $jsonApiObject = $this->itemNormalizer->normalize($object, $format, $context); + $jsonApiObject = $this->itemNormalizer->normalize($data, $format, $context); $error = $jsonApiObject['data']['attributes'] ?? []; $error['id'] = $jsonApiObject['data']['id']; if (isset($error['type'])) { $error['links'] = ['type' => $error['type']]; } - if (!isset($error['code']) && method_exists($object, 'getId')) { - $error['code'] = $object->getId(); + if (!isset($error['code']) && method_exists($data, 'getId')) { + $error['code'] = $data->getId(); } // TODO: change this 5.x @@ -81,9 +81,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { if (self::FORMAT === $format) { return [ diff --git a/src/JsonApi/Serializer/ItemNormalizer.php b/src/JsonApi/Serializer/ItemNormalizer.php index 47a5879a4b4..12be479cd60 100644 --- a/src/JsonApi/Serializer/ItemNormalizer.php +++ b/src/JsonApi/Serializer/ItemNormalizer.php @@ -73,9 +73,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; } @@ -83,16 +83,16 @@ public function getSupportedTypes($format): array /** * {@inheritdoc} */ - 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 { - $resourceClass = $this->getObjectClass($object); + $resourceClass = $this->getObjectClass($data); if ($this->getOutputClass($context)) { - return parent::normalize($object, $format, $context); + return parent::normalize($data, $format, $context); } $previousResourceClass = $context['resource_class'] ?? null; if ($this->resourceClassResolver->isResourceClass($resourceClass) && (null === $previousResourceClass || $this->resourceClassResolver->isResourceClass($previousResourceClass))) { - $resourceClass = $this->resourceClassResolver->getResourceClass($object, $previousResourceClass); + $resourceClass = $this->resourceClassResolver->getResourceClass($data, $previousResourceClass); } if (($operation = $context['operation'] ?? null) && method_exists($operation, 'getItemUriTemplate')) { @@ -101,8 +101,8 @@ public function normalize(mixed $object, ?string $format = null, array $context $context = $this->initContext($resourceClass, $context); - $iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context); - $context['object'] = $object; + $iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($data, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context); + $context['object'] = $data; $context['format'] = $format; $context['api_normalize'] = true; @@ -110,28 +110,28 @@ public function normalize(mixed $object, ?string $format = null, array $context $context['cache_key'] = $this->getCacheKey($format, $context); } - $data = parent::normalize($object, $format, $context); - if (!\is_array($data)) { - return $data; + $normalizedData = parent::normalize($data, $format, $context); + if (!\is_array($normalizedData)) { + return $normalizedData; } // Get and populate relations - ['relationships' => $allRelationshipsData, 'links' => $links] = $this->getComponents($object, $format, $context); + ['relationships' => $allRelationshipsData, 'links' => $links] = $this->getComponents($data, $format, $context); $populatedRelationContext = $context; - $relationshipsData = $this->getPopulatedRelations($object, $format, $populatedRelationContext, $allRelationshipsData); + $relationshipsData = $this->getPopulatedRelations($data, $format, $populatedRelationContext, $allRelationshipsData); // Do not include primary resources $context['api_included_resources'] = [$context['iri']]; - $includedResourcesData = $this->getRelatedResources($object, $format, $context, $allRelationshipsData); + $includedResourcesData = $this->getRelatedResources($data, $format, $context, $allRelationshipsData); $resourceData = [ 'id' => $context['iri'], 'type' => $this->getResourceShortName($resourceClass), ]; - if ($data) { - $resourceData['attributes'] = $data; + if ($normalizedData) { + $resourceData['attributes'] = $normalizedData; } if ($relationshipsData) { @@ -166,7 +166,7 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form * * @throws NotNormalizableValueException */ - public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { // Avoid issues with proxies if we populated the object if (!isset($context[self::OBJECT_TO_POPULATE]) && isset($data['data']['id'])) { @@ -188,7 +188,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null, return parent::denormalize( $dataToDenormalize, - $class, + $type, $format, $context ); diff --git a/src/JsonApi/Serializer/ObjectNormalizer.php b/src/JsonApi/Serializer/ObjectNormalizer.php index 1fd986b2dbb..5ea74b1f4c3 100644 --- a/src/JsonApi/Serializer/ObjectNormalizer.php +++ b/src/JsonApi/Serializer/ObjectNormalizer.php @@ -42,9 +42,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; } @@ -52,16 +52,16 @@ public function getSupportedTypes($format): array /** * {@inheritdoc} */ - 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 (isset($context['api_resource'])) { $originalResource = $context['api_resource']; unset($context['api_resource']); } - $data = $this->decorated->normalize($object, $format, $context); - if (!\is_array($data) || isset($context['api_attribute'])) { - return $data; + $normalizedData = $this->decorated->normalize($data, $format, $context); + if (!\is_array($normalizedData) || isset($context['api_attribute'])) { + return $normalizedData; } if (isset($originalResource)) { @@ -72,13 +72,13 @@ public function normalize(mixed $object, ?string $format = null, array $context ]; } else { $resourceData = [ - 'id' => $this->iriConverter->getIriFromResource($object), - 'type' => (new \ReflectionClass($this->getObjectClass($object)))->getShortName(), + 'id' => $this->iriConverter->getIriFromResource($data), + 'type' => (new \ReflectionClass($this->getObjectClass($data)))->getShortName(), ]; } - if ($data) { - $resourceData['attributes'] = $data; + if ($normalizedData) { + $resourceData['attributes'] = $normalizedData; } return ['data' => $resourceData]; diff --git a/src/JsonLd/Serializer/ErrorNormalizer.php b/src/JsonLd/Serializer/ErrorNormalizer.php index 1227421a5c3..aa786d80b26 100644 --- a/src/JsonLd/Serializer/ErrorNormalizer.php +++ b/src/JsonLd/Serializer/ErrorNormalizer.php @@ -25,10 +25,13 @@ public function __construct(private readonly NormalizerInterface $inner, private { } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + /** + * {@inheritdoc} + */ + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { $context += $this->defaultContext; - $normalized = $this->inner->normalize($object, $format, $context); + $normalized = $this->inner->normalize($data, $format, $context); $hydraPrefix = $this->getHydraPrefix($context); if (!$hydraPrefix) { return $normalized; @@ -53,12 +56,18 @@ public function normalize(mixed $object, ?string $format = null, array $context return $normalized; } + /** + * {@inheritdoc} + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $this->inner->supportsNormalization($data, $format, $context) && (is_a($data, Error::class) || is_a($data, ValidationException::class)); } + /** + * {@inheritdoc} + */ public function getSupportedTypes(?string $format): array { if (method_exists($this->inner, 'getSupportedTypes')) { diff --git a/src/JsonLd/Serializer/ItemNormalizer.php b/src/JsonLd/Serializer/ItemNormalizer.php index e4e42b9a30d..ed9f0624c6c 100644 --- a/src/JsonLd/Serializer/ItemNormalizer.php +++ b/src/JsonLd/Serializer/ItemNormalizer.php @@ -84,9 +84,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; } @@ -96,20 +96,20 @@ public function getSupportedTypes($format): array * * @throws LogicException */ - 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 { - $resourceClass = $this->getObjectClass($object); + $resourceClass = $this->getObjectClass($data); $outputClass = $this->getOutputClass($context); if ($outputClass && !($context['item_uri_template'] ?? null)) { - return parent::normalize($object, $format, $context); + return parent::normalize($data, $format, $context); } // TODO: we should not remove the resource_class in the normalizeRawCollection as we would find out anyway that it's not the same as the requested one $previousResourceClass = $context['resource_class'] ?? null; $metadata = []; if ($isResourceClass = $this->resourceClassResolver->isResourceClass($resourceClass) && (null === $previousResourceClass || $this->resourceClassResolver->isResourceClass($previousResourceClass))) { - $resourceClass = $this->resourceClassResolver->getResourceClass($object, $previousResourceClass); + $resourceClass = $this->resourceClassResolver->getResourceClass($data, $previousResourceClass); $context = $this->initContext($resourceClass, $context); $metadata = $this->addJsonLdContext($this->contextBuilder, $resourceClass, $context); } elseif ($this->contextBuilder instanceof AnonymousContextBuilderInterface) { @@ -124,7 +124,7 @@ public function normalize(mixed $object, ?string $format = null, array $context } // We should improve what's behind the context creation, its probably more complicated then it should - $metadata = $this->createJsonLdContext($this->contextBuilder, $object, $context); + $metadata = $this->createJsonLdContext($this->contextBuilder, $data, $context); } // Special case: non-resource got serialized and contains a resource therefore we need to reset part of the context @@ -132,16 +132,16 @@ public function normalize(mixed $object, ?string $format = null, array $context unset($context['operation'], $context['operation_name'], $context['output']); } - if (true === ($context['output']['gen_id'] ?? true) && true === ($context['force_iri_generation'] ?? true) && $iri = $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context)) { + if (true === ($context['output']['gen_id'] ?? true) && true === ($context['force_iri_generation'] ?? true) && $iri = $this->iriConverter->getIriFromResource($data, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context)) { $context['iri'] = $iri; $metadata['@id'] = $iri; } $context['api_normalize'] = true; - $data = parent::normalize($object, $format, $context); - if (!\is_array($data)) { - return $data; + $normalizedData = parent::normalize($data, $format, $context); + if (!\is_array($normalizedData)) { + return $normalizedData; } $operation = $context['operation'] ?? null; @@ -157,7 +157,7 @@ public function normalize(mixed $object, ?string $format = null, array $context $metadata['@type'] = 1 === \count($types) ? $types[0] : $types; } - return $metadata + $data; + return $metadata + $normalizedData; } /** @@ -173,7 +173,7 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form * * @throws NotNormalizableValueException */ - public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { // Avoid issues with proxies if we populated the object if (isset($data['@id']) && !isset($context[self::OBJECT_TO_POPULATE])) { @@ -192,7 +192,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null, } } - return parent::denormalize($data, $class, $format, $context); + return parent::denormalize($data, $type, $format, $context); } protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false): array|bool diff --git a/src/JsonLd/Serializer/ObjectNormalizer.php b/src/JsonLd/Serializer/ObjectNormalizer.php index 23659458c91..24755c41e3b 100644 --- a/src/JsonLd/Serializer/ObjectNormalizer.php +++ b/src/JsonLd/Serializer/ObjectNormalizer.php @@ -41,9 +41,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; } @@ -51,7 +51,7 @@ public function getSupportedTypes($format): array /** * {@inheritdoc} */ - 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 (isset($context['api_resource'])) { $originalResource = $context['api_resource']; @@ -70,9 +70,9 @@ public function normalize(mixed $object, ?string $format = null, array $context */ $context['api_empty_resource_as_iri'] = true; - $data = $this->decorated->normalize($object, $format, $context); - if (!\is_array($data) || !$data) { - return $data; + $normalizedData = $this->decorated->normalize($data, $format, $context); + if (!\is_array($normalizedData) || !$normalizedData) { + return $normalizedData; } if (isset($originalResource)) { @@ -84,8 +84,8 @@ public function normalize(mixed $object, ?string $format = null, array $context $context['api_resource'] = $originalResource; } - $metadata = $this->createJsonLdContext($this->anonymousContextBuilder, $object, $context); + $metadata = $this->createJsonLdContext($this->anonymousContextBuilder, $data, $context); - return $metadata + $data; + return $metadata + $normalizedData; } } diff --git a/src/OpenApi/Serializer/ApiGatewayNormalizer.php b/src/OpenApi/Serializer/ApiGatewayNormalizer.php index f8fadeb5cc5..fed1cf8f215 100644 --- a/src/OpenApi/Serializer/ApiGatewayNormalizer.php +++ b/src/OpenApi/Serializer/ApiGatewayNormalizer.php @@ -42,73 +42,73 @@ public function __construct(private readonly NormalizerInterface $documentationN * * @throws UnexpectedValueException */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $data = $this->documentationNormalizer->normalize($object, $format, $context); - if (!\is_array($data)) { + $normalizedData = $this->documentationNormalizer->normalize($data, $format, $context); + if (!\is_array($normalizedData)) { throw new UnexpectedValueException('Expected data to be an array'); } if (!($context[self::API_GATEWAY] ?? $this->defaultContext[self::API_GATEWAY])) { - return $data; + return $normalizedData; } - if (empty($data['basePath'])) { - $data['basePath'] = '/'; + if (empty($normalizedData['basePath'])) { + $normalizedData['basePath'] = '/'; } - foreach ($data['paths'] as $path => $operations) { + foreach ($normalizedData['paths'] as $path => $operations) { foreach ($operations as $operation => $options) { if (isset($options['parameters'])) { foreach ($options['parameters'] as $key => $parameter) { if (!preg_match('/^[a-zA-Z0-9._$-]+$/', (string) $parameter['name'])) { - unset($data['paths'][$path][$operation]['parameters'][$key]); + unset($normalizedData['paths'][$path][$operation]['parameters'][$key]); } if (isset($parameter['schema']['$ref']) && $this->isLocalRef($parameter['schema']['$ref'])) { - $data['paths'][$path][$operation]['parameters'][$key]['schema']['$ref'] = $this->normalizeRef($parameter['schema']['$ref']); + $normalizedData['paths'][$path][$operation]['parameters'][$key]['schema']['$ref'] = $this->normalizeRef($parameter['schema']['$ref']); } } - $data['paths'][$path][$operation]['parameters'] = array_values($data['paths'][$path][$operation]['parameters']); + $normalizedData['paths'][$path][$operation]['parameters'] = array_values($normalizedData['paths'][$path][$operation]['parameters']); } if (isset($options['responses'])) { foreach ($options['responses'] as $statusCode => $response) { if (isset($response['schema']['items']['$ref']) && $this->isLocalRef($response['schema']['items']['$ref'])) { - $data['paths'][$path][$operation]['responses'][$statusCode]['schema']['items']['$ref'] = $this->normalizeRef($response['schema']['items']['$ref']); + $normalizedData['paths'][$path][$operation]['responses'][$statusCode]['schema']['items']['$ref'] = $this->normalizeRef($response['schema']['items']['$ref']); } if (isset($response['schema']['$ref']) && $this->isLocalRef($response['schema']['$ref'])) { - $data['paths'][$path][$operation]['responses'][$statusCode]['schema']['$ref'] = $this->normalizeRef($response['schema']['$ref']); + $normalizedData['paths'][$path][$operation]['responses'][$statusCode]['schema']['$ref'] = $this->normalizeRef($response['schema']['$ref']); } } } } } - foreach ($data['components']['schemas'] as $definition => $options) { + foreach ($normalizedData['components']['schemas'] as $definition => $options) { if (!isset($options['properties'])) { continue; } foreach ($options['properties'] as $property => $propertyOptions) { if (isset($propertyOptions['readOnly'])) { - unset($data['components']['schemas'][$definition]['properties'][$property]['readOnly']); + unset($normalizedData['components']['schemas'][$definition]['properties'][$property]['readOnly']); } if (isset($propertyOptions['$ref']) && $this->isLocalRef($propertyOptions['$ref'])) { - $data['components']['schemas'][$definition]['properties'][$property]['$ref'] = $this->normalizeRef($propertyOptions['$ref']); + $normalizedData['components']['schemas'][$definition]['properties'][$property]['$ref'] = $this->normalizeRef($propertyOptions['$ref']); } if (isset($propertyOptions['items']['$ref']) && $this->isLocalRef($propertyOptions['items']['$ref'])) { - $data['components']['schemas'][$definition]['properties'][$property]['items']['$ref'] = $this->normalizeRef($propertyOptions['items']['$ref']); + $normalizedData['components']['schemas'][$definition]['properties'][$property]['items']['$ref'] = $this->normalizeRef($propertyOptions['items']['$ref']); } } } - // $data['definitions'] is an instance of \ArrayObject - foreach (array_keys($data['components']['schemas']) as $definition) { + // $normalizedData['definitions'] is an instance of \ArrayObject + foreach (array_keys($normalizedData['components']['schemas']) as $definition) { if (!preg_match('/^[0-9A-Za-z]+$/', (string) $definition)) { - $data['components']['schemas'][preg_replace('/[^0-9A-Za-z]/', '', (string) $definition)] = $data['components']['schemas'][$definition]; - unset($data['components']['schemas'][$definition]); + $normalizedData['components']['schemas'][preg_replace('/[^0-9A-Za-z]/', '', (string) $definition)] = $normalizedData['components']['schemas'][$definition]; + unset($normalizedData['components']['schemas'][$definition]); } } - return $data; + return $normalizedData; } /** @@ -120,9 +120,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return $this->documentationNormalizer->getSupportedTypes($format); } diff --git a/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php b/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php index d306821933c..7f47f737fa5 100644 --- a/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php +++ b/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php @@ -27,9 +27,12 @@ public function __construct(private readonly NormalizerInterface $decorated, arr $this->defaultContext = array_merge($this->defaultContext, $defaultContext); } - public function normalize(mixed $object, ?string $format = null, array $context = []): array + /** + * {@inheritdoc} + */ + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $openapi = $this->decorated->normalize($object, $format, $context); + $openapi = $this->decorated->normalize($data, $format, $context); if ('3.0.0' !== ($context['spec_version'] ?? null)) { return $openapi; @@ -65,9 +68,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return $this->decorated->getSupportedTypes($format); } diff --git a/src/OpenApi/Serializer/OpenApiNormalizer.php b/src/OpenApi/Serializer/OpenApiNormalizer.php index 21c26380202..4da46fb518c 100644 --- a/src/OpenApi/Serializer/OpenApiNormalizer.php +++ b/src/OpenApi/Serializer/OpenApiNormalizer.php @@ -36,7 +36,7 @@ public function __construct(private readonly NormalizerInterface $decorated) /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { $pathsCallback = $this->getPathsCallBack(); $context[AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS] = true; @@ -45,7 +45,7 @@ public function normalize(mixed $object, ?string $format = null, array $context 'paths' => $pathsCallback, ]; - return $this->recursiveClean($this->decorated->normalize($object, $format, $context)); + return $this->recursiveClean($this->decorated->normalize($data, $format, $context)); } private function recursiveClean(array $data): array @@ -77,9 +77,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return (self::FORMAT === $format || self::JSON_FORMAT === $format || self::YAML_FORMAT === $format) ? [OpenApi::class => true] : []; } diff --git a/src/Problem/Serializer/ConstraintViolationListNormalizer.php b/src/Problem/Serializer/ConstraintViolationListNormalizer.php index 2fbcee0a671..8a6e3837b7a 100644 --- a/src/Problem/Serializer/ConstraintViolationListNormalizer.php +++ b/src/Problem/Serializer/ConstraintViolationListNormalizer.php @@ -44,9 +44,9 @@ public function __construct(?array $serializePayloadFields = null, ?NameConverte /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - [$messages, $violations] = $this->getMessagesAndViolations($object); + [$messages, $violations] = $this->getMessagesAndViolations($data); return $violations; } diff --git a/src/RamseyUuid/Serializer/UuidDenormalizer.php b/src/RamseyUuid/Serializer/UuidDenormalizer.php index 2cb8b0b3050..4bf4fed3c84 100644 --- a/src/RamseyUuid/Serializer/UuidDenormalizer.php +++ b/src/RamseyUuid/Serializer/UuidDenormalizer.php @@ -33,11 +33,17 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a } } + /** + * {@inheritdoc} + */ public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { return \is_string($data) && is_a($type, UuidInterface::class, true); } + /** + * {@inheritdoc} + */ public function getSupportedTypes(?string $format): array { return [ diff --git a/src/Serializer/AbstractCollectionNormalizer.php b/src/Serializer/AbstractCollectionNormalizer.php index bde6ab863b9..d757a3b35b5 100644 --- a/src/Serializer/AbstractCollectionNormalizer.php +++ b/src/Serializer/AbstractCollectionNormalizer.php @@ -53,6 +53,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array return static::FORMAT === $format && is_iterable($data); } + /** + * {@inheritdoc} + */ public function getSupportedTypes(?string $format): array { /* @@ -73,27 +76,27 @@ public function getSupportedTypes(?string $format): array /** * {@inheritdoc} * - * @param iterable $object + * @param iterable $data */ - 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 (!isset($context['resource_class']) || isset($context['api_sub_level'])) { - return $this->normalizeRawCollection($object, $format, $context); + return $this->normalizeRawCollection($data, $format, $context); } - $resourceClass = $this->resourceClassResolver->getResourceClass($object, $context['resource_class']); + $resourceClass = $this->resourceClassResolver->getResourceClass($data, $context['resource_class']); $collectionContext = $this->initContext($resourceClass, $context); - $data = []; - $paginationData = $this->getPaginationData($object, $collectionContext); + $normalizedData = []; + $paginationData = $this->getPaginationData($data, $collectionContext); $childContext = $this->createOperationContext($collectionContext, $resourceClass); if (isset($collectionContext['force_resource_class'])) { $childContext['force_resource_class'] = $collectionContext['force_resource_class']; } - $itemsData = $this->getItemsData($object, $format, $childContext); + $itemsData = $this->getItemsData($data, $format, $childContext); - return array_merge_recursive($data, $paginationData, $itemsData); + return array_merge_recursive($normalizedData, $paginationData, $itemsData); } /** diff --git a/src/Serializer/AbstractConstraintViolationListNormalizer.php b/src/Serializer/AbstractConstraintViolationListNormalizer.php index 995b3ace62b..41376e65c47 100644 --- a/src/Serializer/AbstractConstraintViolationListNormalizer.php +++ b/src/Serializer/AbstractConstraintViolationListNormalizer.php @@ -49,9 +49,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return $format === static::FORMAT ? [ConstraintViolationListInterface::class => true] : []; } diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index 5d00434c77d..23185e7ee45 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -105,6 +105,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array return $this->resourceClassResolver->isResourceClass($class); } + /** + * {@inheritdoc} + */ public function getSupportedTypes(?string $format): array { return [ @@ -117,9 +120,9 @@ public function getSupportedTypes(?string $format): array * * @throws LogicException */ - 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 { - $resourceClass = $context['force_resource_class'] ?? $this->getObjectClass($object); + $resourceClass = $context['force_resource_class'] ?? $this->getObjectClass($data); if ($outputClass = $this->getOutputClass($context)) { if (!$this->serializer instanceof NormalizerInterface) { throw new LogicException('Cannot normalize the output because the injected serializer is not a normalizer'); @@ -130,7 +133,7 @@ public function normalize(mixed $object, ?string $format = null, array $context $context['api_sub_level'] = true; $context[self::ALLOW_EXTRA_ATTRIBUTES] = false; - return $this->serializer->normalize($object, $format, $context); + return $this->serializer->normalize($data, $format, $context); } // Never remove this, with `application/json` we don't use our AbstractCollectionNormalizer and we need @@ -144,7 +147,7 @@ public function normalize(mixed $object, ?string $format = null, array $context } $context['api_normalize'] = true; - $iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_URL, $context['operation'] ?? null, $context); + $iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($data, UrlGeneratorInterface::ABS_URL, $context['operation'] ?? null, $context); /* * When true, converts the normalized data array of a resource into an @@ -163,10 +166,10 @@ public function normalize(mixed $object, ?string $format = null, array $context $context['resources'][$iri] = $iri; } - $context['object'] = $object; + $context['object'] = $data; $context['format'] = $format; - $data = parent::normalize($object, $format, $context); + $data = parent::normalize($data, $format, $context); $context['data'] = $data; unset($context['property_metadata'], $context['api_attribute']); @@ -203,9 +206,9 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form /** * {@inheritdoc} */ - public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { - $resourceClass = $class; + $resourceClass = $type; if ($inputClass = $this->getInputClass($context)) { if (!$this->serializer instanceof DenormalizerInterface) { @@ -224,13 +227,13 @@ public function denormalize(mixed $data, string $class, ?string $format = null, if (null === $objectToPopulate = $this->extractObjectToPopulate($resourceClass, $context, static::OBJECT_TO_POPULATE)) { $normalizedData = \is_scalar($data) ? [$data] : $this->prepareForDenormalization($data); - $class = $this->getClassDiscriminatorResolvedClass($normalizedData, $class, $context); + $type = $this->getClassDiscriminatorResolvedClass($normalizedData, $type, $context); } $context['api_denormalize'] = true; - if ($this->resourceClassResolver->isResourceClass($class)) { - $resourceClass = $this->resourceClassResolver->getResourceClass($objectToPopulate, $class); + if ($this->resourceClassResolver->isResourceClass($type)) { + $resourceClass = $this->resourceClassResolver->getResourceClass($objectToPopulate, $type); $context['resource_class'] = $resourceClass; } @@ -257,9 +260,9 @@ public function denormalize(mixed $data, string $class, ?string $format = null, } $previousObject = $this->clone($objectToPopulate); - $object = parent::denormalize($data, $class, $format, $context); + $object = parent::denormalize($data, $type, $format, $context); - if (!$this->resourceClassResolver->isResourceClass($class)) { + if (!$this->resourceClassResolver->isResourceClass($type)) { return $object; } @@ -428,12 +431,9 @@ protected function createConstructorArgument(mixed $parameterData, string $key, * * Unused in this context. * - * @param object $object - * @param string|null $format - * * @return string[] */ - protected function extractAttributes($object, $format = null, array $context = []): array + protected function extractAttributes(object $object, ?string $format = null, array $context = []): array { return []; } diff --git a/src/Serializer/ConstraintViolationListNormalizer.php b/src/Serializer/ConstraintViolationListNormalizer.php index d6c2e7907af..6ee3aa5b1f2 100644 --- a/src/Serializer/ConstraintViolationListNormalizer.php +++ b/src/Serializer/ConstraintViolationListNormalizer.php @@ -34,9 +34,9 @@ public function __construct(?array $serializePayloadFields = null, ?NameConverte /** * {@inheritdoc} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - [$messages, $violations] = $this->getMessagesAndViolations($object); + [$messages, $violations] = $this->getMessagesAndViolations($data); return $violations; } diff --git a/src/Serializer/ItemNormalizer.php b/src/Serializer/ItemNormalizer.php index 01e069b8994..ee0d7ddad3c 100644 --- a/src/Serializer/ItemNormalizer.php +++ b/src/Serializer/ItemNormalizer.php @@ -53,7 +53,7 @@ public function __construct(PropertyNameCollectionFactoryInterface $propertyName * * @throws NotNormalizableValueException */ - public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { // Avoid issues with proxies if we populated the object if (isset($data['id']) && !isset($context[self::OBJECT_TO_POPULATE])) { @@ -73,7 +73,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null, } } - return parent::denormalize($data, $class, $format, $context); + return parent::denormalize($data, $type, $format, $context); } private function updateObjectToPopulate(array $data, array &$context): bool diff --git a/src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php b/src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php index dc95f8723da..1928509cb26 100644 --- a/src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php +++ b/src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php @@ -23,10 +23,13 @@ public function __construct(private readonly NormalizerInterface $decorated, pri { } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + /** + * {@inheritdoc} + */ + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { $messages = []; - foreach ($object->getConstraintViolationList() as $violation) { + foreach ($data->getConstraintViolationList() as $violation) { $class = \is_object($root = $violation->getRoot()) ? $root::class : null; if ($this->nameConverter) { @@ -39,20 +42,23 @@ public function normalize(mixed $object, ?string $format = null, array $context } $str = implode("\n", $messages); - $object->setDetail($str); + $data->setDetail($str); - return $this->decorated->normalize($object, $format, $context); + return $this->decorated->normalize($data, $format, $context); } + /** + * {@inheritdoc} + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof ValidationException && $this->decorated->supportsNormalization($data, $format, $context); } /** - * @param string|null $format + * {@inheritdoc} */ - public function getSupportedTypes($format): array + public function getSupportedTypes(?string $format): array { return [ValidationException::class => false]; } diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php index 4f3a8c8c659..9f11588a00f 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php @@ -41,9 +41,9 @@ public function __construct(private readonly IriConverterInterface $iriConverter /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { - $relatedDummyClass = DummyEntity::class === $class ? RelatedDummyEntity::class : RelatedDummyDocument::class; + $relatedDummyClass = DummyEntity::class === $type ? RelatedDummyEntity::class : RelatedDummyDocument::class; if (!empty($data['relatedDummy'])) { $data['relatedDummy'] = $this->iriConverter->getIriFromResource($relatedDummyClass, UrlGeneratorInterface::ABS_PATH, new Get(), ['uri_variables' => [ 'id' => $data['relatedDummy'], @@ -58,13 +58,13 @@ public function denormalize($data, $class, $format = null, array $context = []): } } - return $this->denormalizer->denormalize($data, $class, $format, $context + [self::class => true]); + return $this->denormalizer->denormalize($data, $type, $format, $context + [self::class => true]); } /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { return 'json' === $format && (is_a($type, DummyEntity::class, true) || is_a($type, DummyDocument::class, true)) @@ -72,7 +72,10 @@ public function supportsDenormalization($data, $type, $format = null, array $con && !isset($context[self::class]); } - public function getSupportedTypes($format): array + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { return 'json' === $format ? ['*' => false] : []; } diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php index 28f9ef27228..04a2815aff1 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php @@ -41,24 +41,24 @@ public function __construct(private readonly IriConverterInterface $iriConverter /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $iriConverterContext = ['uri_variables' => ['id' => $data['thirdLevel']]] + $context; $data['thirdLevel'] = $this->iriConverter->getIriFromResource( - RelatedDummyEntity::class === $class ? ThirdLevelEntity::class : ThirdLevelDocument::class, + RelatedDummyEntity::class === $type ? ThirdLevelEntity::class : ThirdLevelDocument::class, UrlGeneratorInterface::ABS_PATH, new Get(), $iriConverterContext ); - return $this->denormalizer->denormalize($data, $class, $format, $context + [self::class => true]); + return $this->denormalizer->denormalize($data, $type, $format, $context + [self::class => true]); } /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { return 'json' === $format && (is_a($type, RelatedDummyEntity::class, true) || is_a($type, RelatedDummyDocument::class, true)) @@ -66,7 +66,10 @@ public function supportsDenormalization($data, $type, $format = null, array $con && !isset($context[self::class]); } - public function getSupportedTypes($format): array + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { return 'json' === $format ? ['*' => false] : []; } diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php index 9322483e15b..a539ab48a6e 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php @@ -24,9 +24,9 @@ class SerializableResourceDenormalizer implements DenormalizerInterface /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { - $resource = new $class(); + $resource = new $type(); $resource->bar = $data['bar']; $resource->foo = $data['foo']; $resource->id = $data['id']; @@ -37,12 +37,15 @@ public function denormalize($data, $class, $format = null, array $context = []): /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { return 'json' === $format && SerializableResource::class === $type && \is_array($data); } - public function getSupportedTypes($format): array + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { return 'json' === $format ? ['*' => true] : []; } diff --git a/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php b/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php index cbefe3af649..030885d07e5 100644 --- a/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php @@ -22,19 +22,28 @@ public function __construct(private readonly NormalizerInterface $decorated) { } - public function normalize(mixed $object, ?string $format = null, array $context = []): array|\ArrayObject + /** + * {@inheritdoc} + */ + public function normalize(mixed $data, ?string $format = null, array $context = []): array|\ArrayObject { - $a = $this->decorated->normalize($object, $format, $context); + $a = $this->decorated->normalize($data, $format, $context); $a['hello'] = 'world'; return $a; } + /** + * {@inheritdoc} + */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return 'json' === $format; } + /** + * {@inheritdoc} + */ public function getSupportedTypes(?string $format): array { if ('json' === $format) { diff --git a/tests/Fixtures/TestBundle/Serializer/NameConverter/CustomConverter.php b/tests/Fixtures/TestBundle/Serializer/NameConverter/CustomConverter.php index 0dc6be57be1..2a5b536f27e 100644 --- a/tests/Fixtures/TestBundle/Serializer/NameConverter/CustomConverter.php +++ b/tests/Fixtures/TestBundle/Serializer/NameConverter/CustomConverter.php @@ -29,11 +29,17 @@ public function __construct() $this->nameConverter = new CamelCaseToSnakeCaseNameConverter(); } + /** + * {@inheritdoc} + */ public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string { return 'nameConverted' === $propertyName ? $this->nameConverter->normalize($propertyName) : $propertyName; } + /** + * {@inheritdoc} + */ public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string { return 'name_converted' === $propertyName ? $this->nameConverter->denormalize($propertyName) : $propertyName; diff --git a/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php b/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php index 9c0f610412e..bad69681fa8 100644 --- a/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php @@ -25,21 +25,27 @@ final class AddGroupNormalizer implements NormalizerAwareInterface, NormalizerIn private const ALREADY_CALLED = 'RELATED_GROUP_IMPACT_ON_COLLECTION_NORMALIZER_ALREADY_CALLED'; - public function normalize($object, $format = null, array $context = []): array|string|int|float|bool|\ArrayObject + /** + * {@inheritdoc} + */ + public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject { $context[self::ALREADY_CALLED] = true; if (!($operation = $context['operation'] ?? null)) { - return $this->normalizer->normalize($object, $format, $context); + return $this->normalizer->normalize($data, $format, $context); } if ($operation instanceof Get && '/custom_normalizer_relation_group_impact_on_collection' === $operation->getUriTemplate()) { $context['groups'] = ['related']; } - return $this->normalizer->normalize($object, $format, $context); + return $this->normalizer->normalize($data, $format, $context); } - public function supportsNormalization($data, $format = null, array $context = []): bool + /** + * {@inheritdoc} + */ + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { // Make sure we're not called twice if (isset($context[self::ALREADY_CALLED])) { @@ -49,7 +55,10 @@ public function supportsNormalization($data, $format = null, array $context = [] return $data instanceof RelationGroupImpactOnCollection; } - public function getSupportedTypes($format): array + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { return [ RelationGroupImpactOnCollection::class => false, diff --git a/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php b/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php index 3099c6cb89c..7953eeddcc9 100644 --- a/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php @@ -27,34 +27,35 @@ public function __construct(private readonly NormalizerInterface $documentationN } /** - * @param mixed|null $format - * * @throws ExceptionInterface */ - public function normalize($object, $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - $data = $this->documentationNormalizer->normalize($object, $format, $context); - if (!\is_array($data)) { + $normalizedData = $this->documentationNormalizer->normalize($data, $format, $context); + if (!\is_array($normalizedData)) { throw new UnexpectedValueException('Expected data to be an array'); } - if (isset($data['definitions'])) { - $data['definitions']['RamseyUuidDummy']['properties']['id']['description'] = 'The dummy id'; + if (isset($normalizedData['definitions'])) { + $normalizedData['definitions']['RamseyUuidDummy']['properties']['id']['description'] = 'The dummy id'; } else { - $data['components']['schemas']['RamseyUuidDummy']['properties']['id']['description'] = 'The dummy id'; + $normalizedData['components']['schemas']['RamseyUuidDummy']['properties']['id']['description'] = 'The dummy id'; } - return $data; + return $normalizedData; } /** - * @param mixed|null $format + * {@inheritdoc} */ - public function supportsNormalization($data, $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $this->documentationNormalizer->supportsNormalization($data, $format, $context); } + /** + * {@inheritdoc} + */ public function getSupportedTypes(?string $format): array { return [];