Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Elasticsearch/Serializer/DocumentNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Elasticsearch/Serializer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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) : [];
}
Expand Down
14 changes: 7 additions & 7 deletions src/Elasticsearch/Tests/Serializer/ItemNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/GraphQl/Serializer/Exception/ErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 13 additions & 17 deletions src/GraphQl/Serializer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) : [];
}
Expand All @@ -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)) {
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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';
Expand Down
24 changes: 12 additions & 12 deletions src/GraphQl/Serializer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) : [];
}
Expand All @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/Hal/Serializer/EntrypointNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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] : [];
}
Expand Down
Loading
Loading