Skip to content

Commit 38e09ec

Browse files
authored
refactor: make method parameter names match interfaces (#7643)
1 parent bd3ed98 commit 38e09ec

File tree

45 files changed

+356
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+356
-299
lines changed

src/Elasticsearch/Serializer/DocumentNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form
6464
/**
6565
* {@inheritdoc}
6666
*/
67-
public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed
67+
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
6868
{
6969
if (\is_string($data['_id'] ?? null) && \is_array($data['_source'] ?? null)) {
70-
$data = $this->populateIdentifier($data, $class)['_source'];
70+
$data = $this->populateIdentifier($data, $type)['_source'];
7171
}
7272

73-
return $this->decoratedNormalizer->denormalize($data, $class, $format, $context);
73+
return $this->decoratedNormalizer->denormalize($data, $type, $format, $context);
7474
}
7575

7676
/**
@@ -87,7 +87,7 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
8787
*
8888
* @throws LogicException
8989
*/
90-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
90+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
9191
{
9292
throw new LogicException(\sprintf('%s is a write-only format.', self::FORMAT));
9393
}

src/Elasticsearch/Serializer/ItemNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form
6464
/**
6565
* {@inheritdoc}
6666
*/
67-
public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
67+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
6868
{
69-
return $this->decorated->normalize($object, $format, $context);
69+
return $this->decorated->normalize($data, $format, $context);
7070
}
7171

7272
/**
@@ -78,9 +78,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
7878
}
7979

8080
/**
81-
* @param string|null $format
81+
* {@inheritdoc}
8282
*/
83-
public function getSupportedTypes($format): array
83+
public function getSupportedTypes(?string $format): array
8484
{
8585
return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : [];
8686
}

src/Elasticsearch/Tests/Serializer/ItemNormalizerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ public function testSupportsDenormalization(): void
6666

6767
public function testNormalize(): void
6868
{
69-
$this->normalizerProphecy->normalize($object = (object) ['foo'], 'json', ['groups' => 'foo'])->willReturn(['foo'])->shouldBeCalledOnce();
69+
$this->normalizerProphecy->normalize($data = (object) ['foo'], 'json', ['groups' => 'foo'])->willReturn(['foo'])->shouldBeCalledOnce();
7070

71-
self::assertEquals(['foo'], $this->itemNormalizer->normalize($object, 'json', ['groups' => 'foo']));
71+
self::assertEquals(['foo'], $this->itemNormalizer->normalize($data, 'json', ['groups' => 'foo']));
7272
}
7373

7474
public function testSupportsNormalization(): void
7575
{
76-
$this->normalizerProphecy->supportsNormalization($object = (object) ['foo'], 'json')->willReturn(true)->shouldBeCalledOnce();
77-
$this->normalizerProphecy->supportsNormalization($object, DocumentNormalizer::FORMAT)->shouldNotBeCalled();
76+
$this->normalizerProphecy->supportsNormalization($data = (object) ['foo'], 'json')->willReturn(true)->shouldBeCalledOnce();
77+
$this->normalizerProphecy->supportsNormalization($data, DocumentNormalizer::FORMAT)->shouldNotBeCalled();
7878

79-
self::assertTrue($this->itemNormalizer->supportsNormalization($object, 'json'));
80-
self::assertFalse($this->itemNormalizer->supportsNormalization($object, DocumentNormalizer::FORMAT));
79+
self::assertTrue($this->itemNormalizer->supportsNormalization($data, 'json'));
80+
self::assertFalse($this->itemNormalizer->supportsNormalization($data, DocumentNormalizer::FORMAT));
8181
}
8282

8383
public function testSetSerializer(): void
@@ -115,7 +115,7 @@ public function testGetSupportedTypes(): void
115115
{
116116
// TODO: use prophecy when getSupportedTypes() will be added to the interface
117117
$this->itemNormalizer = new ItemNormalizer(new class implements NormalizerInterface {
118-
public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
118+
public function normalize(mixed $data, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
119119
{
120120
return null;
121121
}

src/GraphQl/Serializer/Exception/ErrorNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ final class ErrorNormalizer implements NormalizerInterface
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
30+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
3131
{
32-
return FormattedError::createFromException($object);
32+
return FormattedError::createFromException($data);
3333
}
3434

3535
/**
@@ -41,9 +41,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
4141
}
4242

4343
/**
44-
* @param string|null $format
44+
* {@inheritdoc}
4545
*/
46-
public function getSupportedTypes($format): array
46+
public function getSupportedTypes(?string $format): array
4747
{
4848
return [
4949
Error::class => true,

src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ final class HttpExceptionNormalizer implements NormalizerInterface
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
31+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
3232
{
3333
/** @var HttpExceptionInterface */
34-
$httpException = $object->getPrevious();
35-
$error = FormattedError::createFromException($object);
34+
$httpException = $data->getPrevious();
35+
$error = FormattedError::createFromException($data);
3636
$error['message'] = $httpException->getMessage();
3737
$error['extensions']['status'] = $statusCode = $httpException->getStatusCode();
3838
// graphql-php < 15
@@ -52,9 +52,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
5252
}
5353

5454
/**
55-
* @param string|null $format
55+
* {@inheritdoc}
5656
*/
57-
public function getSupportedTypes($format): array
57+
public function getSupportedTypes(?string $format): array
5858
{
5959
return [
6060
Error::class => false,

src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ final class RuntimeExceptionNormalizer implements NormalizerInterface
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
30+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
3131
{
3232
/** @var \RuntimeException */
33-
$runtimeException = $object->getPrevious();
34-
$error = FormattedError::createFromException($object);
33+
$runtimeException = $data->getPrevious();
34+
$error = FormattedError::createFromException($data);
3535
$error['message'] = $runtimeException->getMessage();
3636

3737
return $error;
@@ -46,9 +46,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
4646
}
4747

4848
/**
49-
* @param string|null $format
49+
* {@inheritdoc}
5050
*/
51-
public function getSupportedTypes($format): array
51+
public function getSupportedTypes(?string $format): array
5252
{
5353
return [
5454
Error::class => false,

src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public function __construct(private readonly array $exceptionToStatus = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
38+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
3939
{
40-
$validationException = $object->getPrevious();
40+
$validationException = $data->getPrevious();
4141
if (!$validationException instanceof ConstraintViolationListAwareExceptionInterface) {
4242
throw new RuntimeException(\sprintf('Object is not a "%s".', ConstraintViolationListAwareExceptionInterface::class));
4343
}
4444

45-
$error = FormattedError::createFromException($object);
45+
$error = FormattedError::createFromException($data);
4646
$error['message'] = $validationException->getMessage();
4747

4848
$exceptionClass = $validationException::class;
@@ -81,9 +81,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
8181
}
8282

8383
/**
84-
* @param string|null $format
84+
* {@inheritdoc}
8585
*/
86-
public function getSupportedTypes($format): array
86+
public function getSupportedTypes(?string $format): array
8787
{
8888
return [
8989
Error::class => false,

src/GraphQl/Serializer/ItemNormalizer.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
6363
}
6464

6565
/**
66-
* @param string|null $format
66+
* {@inheritdoc}
6767
*/
68-
public function getSupportedTypes($format): array
68+
public function getSupportedTypes(?string $format): array
6969
{
7070
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
7171
}
@@ -77,17 +77,17 @@ public function getSupportedTypes($format): array
7777
*
7878
* @throws UnexpectedValueException
7979
*/
80-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
80+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
8181
{
82-
$resourceClass = $this->getObjectClass($object);
82+
$resourceClass = $this->getObjectClass($data);
8383

8484
if ($this->getOutputClass($context)) {
8585
$context['graphql_identifiers'] = [
8686
self::ITEM_RESOURCE_CLASS_KEY => $context['operation']->getClass(),
87-
self::ITEM_IDENTIFIERS_KEY => $this->identifiersExtractor->getIdentifiersFromItem($object, $context['operation'] ?? null),
87+
self::ITEM_IDENTIFIERS_KEY => $this->identifiersExtractor->getIdentifiersFromItem($data, $context['operation'] ?? null),
8888
];
8989

90-
return parent::normalize($object, $format, $context);
90+
return parent::normalize($data, $format, $context);
9191
}
9292

9393
if ($this->isCacheKeySafe($context)) {
@@ -97,19 +97,19 @@ public function normalize(mixed $object, ?string $format = null, array $context
9797
}
9898

9999
unset($context['operation_name'], $context['operation']); // Remove operation and operation_name only when cache key has been created
100-
$data = parent::normalize($object, $format, $context);
101-
if (!\is_array($data)) {
100+
$normalizedData = parent::normalize($data, $format, $context);
101+
if (!\is_array($normalizedData)) {
102102
throw new UnexpectedValueException('Expected data to be an array.');
103103
}
104104

105105
if (isset($context['graphql_identifiers'])) {
106-
$data += $context['graphql_identifiers'];
106+
$normalizedData += $context['graphql_identifiers'];
107107
} elseif (!($context['no_resolver_data'] ?? false)) {
108-
$data[self::ITEM_RESOURCE_CLASS_KEY] = $resourceClass;
109-
$data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($object, $context['operation'] ?? null);
108+
$normalizedData[self::ITEM_RESOURCE_CLASS_KEY] = $resourceClass;
109+
$normalizedData[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($data, $context['operation'] ?? null);
110110
}
111111

112-
return $data;
112+
return $normalizedData;
113113
}
114114

115115
/**
@@ -152,12 +152,8 @@ protected function getAllowedAttributes(string|object $classOrObject, array $con
152152

153153
/**
154154
* {@inheritdoc}
155-
*
156-
* @param object $object
157-
* @param string $attribute
158-
* @param string|null $format
159155
*/
160-
protected function setAttributeValue($object, $attribute, mixed $value, $format = null, array $context = []): void
156+
protected function setAttributeValue(object $object, string $attribute, mixed $value, ?string $format = null, array $context = []): void
161157
{
162158
if ('_id' === $attribute) {
163159
$attribute = 'id';

src/GraphQl/Serializer/ObjectNormalizer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
4444
}
4545

4646
/**
47-
* @param string|null $format
47+
* {@inheritdoc}
4848
*/
49-
public function getSupportedTypes($format): array
49+
public function getSupportedTypes(?string $format): array
5050
{
5151
return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
5252
}
@@ -56,32 +56,32 @@ public function getSupportedTypes($format): array
5656
*
5757
* @throws UnexpectedValueException
5858
*/
59-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
59+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
6060
{
6161
if (isset($context['api_resource'])) {
6262
$originalResource = $context['api_resource'];
6363
unset($context['api_resource']);
6464
}
6565

66-
$data = $this->decorated->normalize($object, $format, $context);
67-
if (!\is_array($data)) {
66+
$normalizedData = $this->decorated->normalize($data, $format, $context);
67+
if (!\is_array($normalizedData)) {
6868
throw new UnexpectedValueException('Expected data to be an array.');
6969
}
7070

7171
if (!isset($originalResource)) {
72-
return $data;
72+
return $normalizedData;
7373
}
7474

75-
if (isset($data['id'])) {
76-
$data['_id'] = $data['id'];
77-
$data['id'] = $this->iriConverter->getIriFromResource($originalResource);
75+
if (isset($normalizedData['id'])) {
76+
$normalizedData['_id'] = $normalizedData['id'];
77+
$normalizedData['id'] = $this->iriConverter->getIriFromResource($originalResource);
7878
}
7979

8080
if (!($context['no_resolver_data'] ?? false)) {
81-
$data[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($originalResource);
82-
$data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($originalResource);
81+
$normalizedData[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($originalResource);
82+
$normalizedData[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($originalResource);
8383
}
8484

85-
return $data;
85+
return $normalizedData;
8686
}
8787
}

src/Hal/Serializer/EntrypointNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
41+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
4242
{
4343
$entrypoint = ['_links' => ['self' => ['href' => $this->urlGenerator->generate('api_entrypoint')]]];
4444

45-
foreach ($object->getResourceNameCollection() as $resourceClass) {
45+
foreach ($data->getResourceNameCollection() as $resourceClass) {
4646
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
4747

4848
foreach ($resourceMetadata as $resource) {
@@ -74,9 +74,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
7474
}
7575

7676
/**
77-
* @param string|null $format
77+
* {@inheritdoc}
7878
*/
79-
public function getSupportedTypes($format): array
79+
public function getSupportedTypes(?string $format): array
8080
{
8181
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
8282
}

0 commit comments

Comments
 (0)