Skip to content

Commit 102c2c7

Browse files
authored
refactor: make method parameter names match interfaces (#7643)
1 parent 86f93ac commit 102c2c7

5 files changed

Lines changed: 42 additions & 42 deletions

File tree

Serializer/ConstraintViolationListNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public function __construct(private readonly PropertyMetadataFactoryInterface $p
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
40+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
4141
{
4242
$violations = [];
43-
foreach ($object as $violation) {
43+
foreach ($data as $violation) {
4444
$violations[] = [
4545
'detail' => $violation->getMessage(),
4646
'source' => [
@@ -61,9 +61,9 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
6161
}
6262

6363
/**
64-
* @param string|null $format
64+
* {@inheritdoc}
6565
*/
66-
public function getSupportedTypes($format): array
66+
public function getSupportedTypes(?string $format): array
6767
{
6868
return self::FORMAT === $format ? [ConstraintViolationListInterface::class => true] : [];
6969
}

Serializer/EntrypointNormalizer.php

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

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

4949
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
}

Serializer/ErrorNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ public function __construct(private ?NormalizerInterface $itemNormalizer = null)
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function normalize(mixed $object, ?string $format = null, array $context = []): array
35+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
3636
{
37-
$jsonApiObject = $this->itemNormalizer->normalize($object, $format, $context);
37+
$jsonApiObject = $this->itemNormalizer->normalize($data, $format, $context);
3838
$error = $jsonApiObject['data']['attributes'] ?? [];
3939
$error['id'] = $jsonApiObject['data']['id'];
4040
if (isset($error['type'])) {
4141
$error['links'] = ['type' => $error['type']];
4242
}
4343

44-
if (!isset($error['code']) && method_exists($object, 'getId')) {
45-
$error['code'] = $object->getId();
44+
if (!isset($error['code']) && method_exists($data, 'getId')) {
45+
$error['code'] = $data->getId();
4646
}
4747

4848
// TODO: change this 5.x
@@ -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
if (self::FORMAT === $format) {
8989
return [

Serializer/ItemNormalizer.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,26 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
7373
}
7474

7575
/**
76-
* @param string|null $format
76+
* {@inheritdoc}
7777
*/
78-
public function getSupportedTypes($format): array
78+
public function getSupportedTypes(?string $format): array
7979
{
8080
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
8181
}
8282

8383
/**
8484
* {@inheritdoc}
8585
*/
86-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
86+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
8787
{
88-
$resourceClass = $this->getObjectClass($object);
88+
$resourceClass = $this->getObjectClass($data);
8989
if ($this->getOutputClass($context)) {
90-
return parent::normalize($object, $format, $context);
90+
return parent::normalize($data, $format, $context);
9191
}
9292

9393
$previousResourceClass = $context['resource_class'] ?? null;
9494
if ($this->resourceClassResolver->isResourceClass($resourceClass) && (null === $previousResourceClass || $this->resourceClassResolver->isResourceClass($previousResourceClass))) {
95-
$resourceClass = $this->resourceClassResolver->getResourceClass($object, $previousResourceClass);
95+
$resourceClass = $this->resourceClassResolver->getResourceClass($data, $previousResourceClass);
9696
}
9797

9898
if (($operation = $context['operation'] ?? null) && method_exists($operation, 'getItemUriTemplate')) {
@@ -101,37 +101,37 @@ public function normalize(mixed $object, ?string $format = null, array $context
101101

102102
$context = $this->initContext($resourceClass, $context);
103103

104-
$iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context);
105-
$context['object'] = $object;
104+
$iri = $context['iri'] ??= $this->iriConverter->getIriFromResource($data, UrlGeneratorInterface::ABS_PATH, $context['operation'] ?? null, $context);
105+
$context['object'] = $data;
106106
$context['format'] = $format;
107107
$context['api_normalize'] = true;
108108

109109
if (!isset($context['cache_key'])) {
110110
$context['cache_key'] = $this->getCacheKey($format, $context);
111111
}
112112

113-
$data = parent::normalize($object, $format, $context);
114-
if (!\is_array($data)) {
115-
return $data;
113+
$normalizedData = parent::normalize($data, $format, $context);
114+
if (!\is_array($normalizedData)) {
115+
return $normalizedData;
116116
}
117117

118118
// Get and populate relations
119-
['relationships' => $allRelationshipsData, 'links' => $links] = $this->getComponents($object, $format, $context);
119+
['relationships' => $allRelationshipsData, 'links' => $links] = $this->getComponents($data, $format, $context);
120120
$populatedRelationContext = $context;
121-
$relationshipsData = $this->getPopulatedRelations($object, $format, $populatedRelationContext, $allRelationshipsData);
121+
$relationshipsData = $this->getPopulatedRelations($data, $format, $populatedRelationContext, $allRelationshipsData);
122122

123123
// Do not include primary resources
124124
$context['api_included_resources'] = [$context['iri']];
125125

126-
$includedResourcesData = $this->getRelatedResources($object, $format, $context, $allRelationshipsData);
126+
$includedResourcesData = $this->getRelatedResources($data, $format, $context, $allRelationshipsData);
127127

128128
$resourceData = [
129129
'id' => $context['iri'],
130130
'type' => $this->getResourceShortName($resourceClass),
131131
];
132132

133-
if ($data) {
134-
$resourceData['attributes'] = $data;
133+
if ($normalizedData) {
134+
$resourceData['attributes'] = $normalizedData;
135135
}
136136

137137
if ($relationshipsData) {
@@ -166,7 +166,7 @@ public function supportsDenormalization(mixed $data, string $type, ?string $form
166166
*
167167
* @throws NotNormalizableValueException
168168
*/
169-
public function denormalize(mixed $data, string $class, ?string $format = null, array $context = []): mixed
169+
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
170170
{
171171
// Avoid issues with proxies if we populated the object
172172
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,
188188

189189
return parent::denormalize(
190190
$dataToDenormalize,
191-
$class,
191+
$type,
192192
$format,
193193
$context
194194
);

Serializer/ObjectNormalizer.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
4242
}
4343

4444
/**
45-
* @param string|null $format
45+
* {@inheritdoc}
4646
*/
47-
public function getSupportedTypes($format): array
47+
public function getSupportedTypes(?string $format): array
4848
{
4949
return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
5050
}
5151

5252
/**
5353
* {@inheritdoc}
5454
*/
55-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
55+
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
5656
{
5757
if (isset($context['api_resource'])) {
5858
$originalResource = $context['api_resource'];
5959
unset($context['api_resource']);
6060
}
6161

62-
$data = $this->decorated->normalize($object, $format, $context);
63-
if (!\is_array($data) || isset($context['api_attribute'])) {
64-
return $data;
62+
$normalizedData = $this->decorated->normalize($data, $format, $context);
63+
if (!\is_array($normalizedData) || isset($context['api_attribute'])) {
64+
return $normalizedData;
6565
}
6666

6767
if (isset($originalResource)) {
@@ -72,13 +72,13 @@ public function normalize(mixed $object, ?string $format = null, array $context
7272
];
7373
} else {
7474
$resourceData = [
75-
'id' => $this->iriConverter->getIriFromResource($object),
76-
'type' => (new \ReflectionClass($this->getObjectClass($object)))->getShortName(),
75+
'id' => $this->iriConverter->getIriFromResource($data),
76+
'type' => (new \ReflectionClass($this->getObjectClass($data)))->getShortName(),
7777
];
7878
}
7979

80-
if ($data) {
81-
$resourceData['attributes'] = $data;
80+
if ($normalizedData) {
81+
$resourceData['attributes'] = $normalizedData;
8282
}
8383

8484
return ['data' => $resourceData];

0 commit comments

Comments
 (0)